natchez icon indicating copy to clipboard operation
natchez copied to clipboard

Generic OpenTracing tracer

Open kubukoz opened this issue 4 years ago • 2 comments
trafficstars

This is mostly moving the code from the DataDog implementation, with a few small differences:

  • the code that defines the trace URI is refactored out so it can be specified by the implementations, e.g. I have a different path for Zipkin
  • in case of error, we don't do .log anymore but actually put some fields specifying that the span failed.

This is what a failed span looks like in DataDog with this code:

image

(parent spans also inherit the error if it's not caught with a fa.attempt or otherwise)

Previous attempt: https://github.com/tpolecat/natchez/pull/79

Some things I'm not so sure about:

  • ~case null in OTEntryPoint - I don't think this will ever be null. I'll dive deeper and see if we can get the underlying span to be null in this case.~ I'm worried this won't be universally defined for all OpenTracing implementations // update: turns out the context is actually null in this case. This is now handled in OTEntryPoint.

kubukoz avatar Oct 14 '21 22:10 kubukoz

object Demo extends IOApp.Simple {
  def run: IO[Unit] = DDTracer.entryPoint[IO](d => IO(d.serviceName("demo").build())).use { ep =>

    ep.root("demo").use { rt =>
      rt.kernel.flatMap { k =>
        ep.continue("test",k).use(sp => IO.println(sp)) *>
          ep.continue("test2", Kernel(Map.empty)).use(sp => IO.println(sp))
      }
    }
  }
}

This results in:

OTSpan(datadog.opentracing.DDTracer@68b30f7b,datadog.opentracing.OTSpan@223a7133,Some(natchez.datadog.DDTracer$$$Lambda$25/0x000000084008e840@7bd51be6))
[E] Exception in thread "main" natchez.opentracing.OTEntryPoint$ContinueException: Cannot continue from provided kernel
[E]     at natchez.opentracing.OTEntryPoint.$anonfun$continue$2(OTEntryPoint.scala:26)
[E]     at scala.Option.fold(Option.scala:263)
[E]     at natchez.opentracing.OTEntryPoint.$anonfun$continue$1(OTEntryPoint.scala:26)
[E]     at cats.effect.kernel.Resource.loop$1(Resource.scala:197)
[E]     at cats.effect.kernel.Resource.continue$1(Resource.scala:174)
[E]     at cats.effect.kernel.Resource.$anonfun$fold$3(Resource.scala:200)
[E]     at cats.effect.IOFiber.runLoop(IOFiber.scala:383)
[E]     at cats.effect.IOFiber.afterBlockingSuccessfulR(IOFiber.scala:1162)
[E]     at cats.effect.IOFiber.run(IOFiber.scala:129)
[E]     at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:359)

Using continueOrRoot in the case of test2 would result in a proper trace instead.

kubukoz avatar Oct 14 '21 22:10 kubukoz

@tpolecat have you seen this PR? ~I can resolve the conflicts and revive it but just wanted to make sure it's a desired change~ it was easier than I thought 😅

kubukoz avatar Jun 21 '22 14:06 kubukoz

@kubukoz Any interest in refreshing this one?

mpilquist avatar Oct 02 '22 00:10 mpilquist

Not so much... I'm not sure about the exact state of OTel vs OpenTracing, and I don't know if I'll be using either anytime soon. I'll close for now.

kubukoz avatar Oct 02 '22 22:10 kubukoz