You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In applications that treat opentelemetry as a serialization layer and use tracing for all actual instrumentation, this is not a very big deal. It becomes a big deal when you want to use any crates which treat opentelemetry as a library. I discovered this bug when I was trialing the actix-web-opentelemtry library in combination with tracing.
The text was updated successfully, but these errors were encountered:
This is critical imho...
I did a shallow research on how this works.
It looks like this can be fixed by explicitly setting otel context when starting a span, and then reset context to the previous value on span exit.
I've checked and this working, however, there is a problem I wasn't able to overcome.
Code for tracing-opentelemetry::OpenTelemetryLayer:
fnon_enter(&self,id:&span::Id,ctx:Context<'_,S>){// ...let span = ctx.span(id).expect("Span not found, this is a bug");letmut extensions = span.extensions_mut();// ...let ctx_guard = extensions
.get_mut::<otel::SpanBuilder>().map(|builder| self.tracer.sampled_context(builder).attach());
extensions.insert(ctx_guard);}fnon_exit(&self,id:&span::Id,ctx:Context<'_,S>){// ...let span = ctx.span(id).expect("Span not found, this is a bug");letmut extensions = span.extensions_mut();// ...
extensions.remove::<Option<opentelemetry::ContextGuard>>();}
In order to be able to keep context active and reset later, we need to store ContextGuard as long as span active.
I tried to use extensions for this. However, extensions methods require Send + Sync and ContextGuard explicitly forbids Send because it relies on thread locals...
I can trick compiler by using a wrapped type with unsafe impl, but I don't know why exactly ExtensionsMut requires these, so can be unsafe indeed :)
Perhaps with a help of tracing-opentelemetry contributor we can fix this relatively easily
Bug Report
Version
Platform
Linux DESKTOP-8SQJE0D 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Crates
tracing-opentelemetry
Description
I tried this code:
I expected to see this happen:
Running the code should show the spans all inherit from each other, something like this:
The leaf
otel_fn
span should havetraced_fn
span set as its parent.Instead, this happened:
The
otel_fn
span has the rootmy_span
span set as its parent:In applications that treat
opentelemetry
as a serialization layer and usetracing
for all actual instrumentation, this is not a very big deal. It becomes a big deal when you want to use any crates which treatopentelemetry
as a library. I discovered this bug when I was trialing the actix-web-opentelemtry library in combination with tracing.The text was updated successfully, but these errors were encountered: