Skip to content

tracing-opentelemetry: why is SpanBuilder::start only called in on_close instead of new_span? #2133

Answered by jtescher
LukeMathWalker asked this question in Q&A
Discussion options

You must be logged in to vote

You are correct that otel's global Context is not used to track current spans as they are instead paired with tracing spans and tracked through the tracing registry. The main reason that an otel span is not started until the associated tracing span ends is to support setting a parent trace id / context after the associated tracing span has been created, which the otel API does not support.

Cases where you would want Context::current().span() are generally handled via either tracing's Span::current() for setting attributes, and OpenTelemetrySpanExt::context to read / inject the current context into a client request or otherwise bridge back to otel.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by LukeMathWalker
Comment options

You must be logged in to vote
1 reply
@jtescher
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
crate/opentelemetry Related to the `tracing-opentelemetry` crate.
2 participants
Converted from issue

This discussion was converted from issue #2131 on May 20, 2022 18:01.