mp
10/02/2020, 10:20 PMContext
propagation play nicely with coroutines for use with OpenTelemetry (or anything that uses gRPC Context under the hood in the same way). Out of the box, Context is stored in a ThreadLocal
. (It's private, but there is an override mechanism, so a different implementation can be provided that exposes its ThreadLocal
.) Unfortunately, just using asContextElement()
doesn't work very well because that basically snapshots the OpenTelemetry state at the time the coroutine context was created. If you subsequently modify state like creating a new OT Span
, then launch another coroutine that ends up on a different thread without going to the trouble of adding a new context element, it will see the old span because the ThreadLocal
will be set based on the original snapshot of Context
. Does anyone know of a mechanism that can address this without forcing users to manually add context elements at all coroutine creation callsites? Something like ThreadContextElement
, but that allows capturing state from the thread at the time a new coroutine is created so that it doesn't re-use old state.