Skip to content

Fix ParentBased sampler for implicit parent spans#1394

Merged
codeboten merged 6 commits intoopen-telemetry:masterfrom
mariojonke:fix-parent-based-sampler
Nov 25, 2020
Merged

Fix ParentBased sampler for implicit parent spans#1394
codeboten merged 6 commits intoopen-telemetry:masterfrom
mariojonke:fix-parent-based-sampler

Conversation

@mariojonke
Copy link
Copy Markdown
Contributor

@mariojonke mariojonke commented Nov 19, 2020

The ParentBased sampler currently is only considering parent spans if an explicit parent Context gets passed. Implicit spans in the current Context 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

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Additional ParentBased sampler unit tests considering implicit parent spans.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added

consider the sample decision of implicit parent spans (when creating
a span without explicitly providing a context) instead of forwarding
to the delegating sampler.
@mariojonke mariojonke requested review from a team, ocelotl and toumorokoshi and removed request for a team November 19, 2020 07:54
* 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.
if self._decision is Decision.DROP:
return SamplingResult(self._decision)
attributes = None
return SamplingResult(self._decision, attributes, trace_state)
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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.

@mariojonke
Copy link
Copy Markdown
Contributor Author

Besides the ParentBased sampler not considering implicit parent spans there was another issue.
Samplers weren't including the trace_state passed to should_sample in their sample result when the sampler decided to drop a span. The tracer then created a (unsampled) DefaultSpan without trace_state. Propagating this span further caused the trace to break.
TraceIdRatioBased sampler was discarding the trace state regardless of the sampling decision.

The failing BatchSpanProcessor test seems flaky.

Copy link
Copy Markdown
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codeboten codeboten merged commit 7b33dd6 into open-telemetry:master Nov 25, 2020
@mariojonke mariojonke deleted the fix-parent-based-sampler branch November 26, 2020 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParentBased sampler ignores sample decision of parent when creating span via implicit Context

4 participants