Open gaeljw opened 8 months ago
As pointed out to me, this may be implemented in a similar way as it was for ZIO in https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/7980;
From @djspiewak (Cats Effect maintainer) on Discord:
(...) If you want to dig into this problem more deeply, I recommend cracking open
IOFiber
inside of Cats Effect core and going from there. This is the core of the fiber execution machinery, and it has direct awareness of when a fiber is running and on which thread. I believe there was a similar effort a couple years ago to get the DataDog agent working with CE.Another (probably less invasive) option would be to see if you can do anything with
IOLocal
. There's an open PR (which will be in 3.6.0) which makesIOLocal
usable from impure contexts, which seems close to what you would need to do something like this without hooking into Cats Effect's guts directly. https://github.com/typelevel/cats-effect/pull/3636
Is your feature request related to a problem? Please describe.
When trying out auto-instrumentation in a Scala application (Play Framework), I noticed that some of my Play WS Client calls are instrumented but not related to their parent traces. As some others were, I dug a bit and found out it's related to my usage of Cats library (Cats Effect and Cats Retry).
I think the context is not propagated when using Cats Effect library.
Here's a minimal code sample to highlight the behavior I'm talking about:
Note that it also impacts further operations. Let's say I chain a second call without retries: the context is lost event though I don't use Cats in this second call.
Describe the solution you'd like
I'd like the context to be propagated in Cats Effect
IO
usage (and thus in Cats Retry) so that, in my example above, callingcallWithCatsRetry
gives me a span attached to the parent trace rather than a new trace.Describe alternatives you've considered
I'll be looking at not using Cats Effect for this, likely by using a simpler retry library without
IO
type.Additional context
For people not familiar with Scala ecosystem, Cats Effect is kinda similar to ZIO (for which there's some auto instrumentation available): it's a "asynchronous runtime" working with fibers (green threads).