New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct way to handle trace context propagation when a context might not be present? #45
Comments
So generally you should use strategy 2, at the boundary of your system extract the context from whichever system the request came from which will allow you to propagate other data like baggage even if the span is not recording or sampled, and will keep them all in the same trace. It sounds like there may be a bug somewhere if you are not seeing the same trace id on the child span after setting the parent. Do you have a repo or other full example that shows number two with different trace ids? |
I'm observing identical behaviour in several of my projects, here's a short repro that demonstrates the behaviour: https://github.com/notheotherben/tracing-opentelemetry-traceid-repro Something to note here is that this only appears in scenarios where At a glance, it seems like this may have something to do with the way that the |
## Motivation Fix following issues * #54 * #45 ## Solution * Revert https://github.com/tokio-rs/tracing-opentelemetry/pull/26/files * When an invalid(empty) Context is extracted from the propagator and passed to OpenTelemetrySpanExt::set_parent(), if none is set for trace_id, root and child trace id will not match * I can confirm that this change works in [reproduction](https://github.com/notheotherben/tracing-opentelemetry-traceid-repro) that @notheotherben created * add regression test case which propagate empty context
Resolved in #55 |
edit: perhaps this should have been opened as a Discussion rather than an issue, apologies!
Greetings, I was hoping for some assistance with handling trace context propagation in cases where a trace context may or may not be present. I've tried digging through the docs and trying a few different options, but ran into issues with each case.
First of all, I should clarify what I expected the result to be:
Message
, we utilize that trace context and continue producing spans for the distributed traceMessage
, we end up generating a new trace with the parent span beinghandle_message
Attempt 1: Only setting the parent when a trace context is present in
Message
I haven't been able to understand why, but this case ran into a problem where calls between
handle_message
would all bleed into a single trace id. On another thought - I do have a higher level span that's created (atTRACE
level - withTRACE
not enabled), could that perhaps be why they end all up being linked together into the same TRACE when I don't propagate a context?Attempt 2: Always attempt to extract a context, even when one might not be present
This resolved the problem of
handle_message
calls without a trace context set all ending up in the same trace, but now I started running into a new issue where thehandle_message
span andgenerate_child_span
end up in separate trace ids, but linked to each other. For example, it would look something like this:Thus,
generate_child_span
correctly links toparent_span_id
, but ends up in its owntrace_id
so it doesn't display correctly.What's the correct way of utilizing
OpenTelemetrySpanExt::set_parent
for these cases?The text was updated successfully, but these errors were encountered: