-
Notifications
You must be signed in to change notification settings - Fork 593
fix: ignore deferred spans when delegating sampling decision #3209
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
Open
lbeschastny
wants to merge
3
commits into
open-telemetry:main
Choose a base branch
from
lbeschastny:fix/psrent-based-sampler-with-deferred-trace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−6
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://w3c.github.io/trace-context/#trace-flags
I don't see such a flag definition in the official spec...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's not an official flag. It's a hack used across
opentelemetry-rustproject to mark spans which lack sampling information to distinguish between unsampled and not-yet-sampled ones.Here are some examples:
opentelemetry_zipkin::propagatorsetsTRACE_FLAG_DEFERREDin several places:opentelemetry-rust/opentelemetry-zipkin/src/propagator/mod.rs
Line 34 in b54fa84
opentelemetry_jaeger_propagator::propagatorchecks it here:opentelemetry-rust/opentelemetry-jaeger-propagator/src/propagator.rs
Line 149 in b54fa84
opentelemetry-rust-contrib propagators are using the same approach as well, i.e.:
opentelemetry_aws::trace::xray_propagator: https://github.com/open-telemetry/opentelemetry-rust-contrib/blob/ef1a3669459a9e3bdd1c2cec3d6593662ae7d584/opentelemetry-aws/src/trace/xray_propagator.rs#L61opentelemetry_datadog: https://github.com/open-telemetry/opentelemetry-rust-contrib/blob/ef1a3669459a9e3bdd1c2cec3d6593662ae7d584/opentelemetry-datadog/src/lib.rs#L172There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would've been better to provide a way to apply sampling inside a propagator when extracting tracing context.
But that's a separate thing that would require a major release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best to merge my fix now and then see how this
TRACE_FLAG_DEFERREDsolution could be refactored for the next major releaseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's unfortunate that the
B3code is usingTraceFlagsto send over this information betweenExtractorandInjector. If your application is set up to acceptB3headers and inject bothB3andw3c trace contextheaders, you will end up with illegal trace flags in thew3cheaders. Also, the sampling decision made here will not propagate correctly to the outgoingB3headers since they look at thedeferredflag first, and skip the sampling decision.To support this use case, I think it would be better to define a separate
structto hold this information (and notB3specific) in the API or SDK that is added as to theContextand then read by theSampler. TheB3code would need to be updated as well.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I testes this patch and it works correctly including context propagation.
Propagation works correctly because existing propagators clear all flags except for
TraceFlags::SAMPLEDright now, i.e.:https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-sdk/src/propagation/trace_context.rs#L136
I agree that going forward it would be best to store this information separately instead of using trace flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it's not only B3. I actually encountered this issue when using xray propagator from a third party
opentelemetry_awscrate. It looks like they copy-pasted the hack from zipkin propagator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incoming flags are also cleared of everything that is not
TraceFlags::SAMPLED:https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-sdk/src/propagation/trace_context.rs#L101-L103
So,
TRACE_FLAG_DEFERREDcan only exist internally and can never leak out. At least not with the current solution.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... you may be right. I should check that. So far I only verified that
w3cheaders are generated correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep,
x-b3-sampledis not set correctly