-
Notifications
You must be signed in to change notification settings - Fork 652
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
Fix ParentBased sampler for implicit parent spans #1394
Fix ParentBased sampler for implicit parent spans #1394
Conversation
consider the sample decision of implicit parent spans (when creating a span without explicitly providing a context) instead of forwarding to the delegating sampler.
* samplers did not return the trace_state in the sampling result when a span was dropped. This caused the trace_state extracted from a remote parent span to be erased and further context propagation to break. * fix also TraceIdRatioBased which erased the trace_state independent of the sampling outcome.
@@ -151,7 +151,7 @@ def should_sample( | |||
trace_state: "TraceState" = None, | |||
) -> "SamplingResult": | |||
if self._decision is Decision.DROP: | |||
return SamplingResult(self._decision) | |||
attributes = None | |||
return SamplingResult(self._decision, attributes, trace_state) |
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.
Do we need to pass in the trace_state
for dropped spans?
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.
Yes as otherwise the trace breaks when the span is propagated further. E.g. flask
instrumentation extracts span a span where the sampling flag in the trace parent is false
. The handler in the flask
app makes an outgoing HTTP request with the requests
library. The requests
instrumentation has the flask
span as parent so the created span will be dropped. The dropped span however is used for injecting/propagation, so it needs to include the trace_state
of the parent.
w3c_tracecontext
tests also rely on that the trace_state gets propagated.
Besides the The failing BatchSpanProcessor test seems flaky. |
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.
LGTM
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.
LGTM
The
ParentBased
sampler currently is only considering parent spans if an explicit parentContext
gets passed. Implicit spans in the currentContext
are ignored and sampling is forwarded to the delegating sampler.With this PR also parent spans via the implicit/current
Context
are considered.Fixes #1393
Type of change
How Has This Been Tested?
Additional
ParentBased
sampler unit tests considering implicit parent spans.Checklist: