Set TraceOperation to sampled=true by default #2279
Merged
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.
Fixes #2101
Motivation
In v0.x of
ddtrace
, the currently active trace, represented by theContext
class, would always have asampled == true
by default, as it inherited its value fromSpan#sampled
:dd-trace-rb/lib/ddtrace/context.rb
Line 299 in 9fd0444
And
Span#sampled
defaults totrue
:dd-trace-rb/lib/ddtrace/span.rb
Line 94 in 9fd0444
In v1.x, the currently active trace is now represented by a
TraceOperation
.TraceOperation#sampled
defaults tofalse
:dd-trace-rb/lib/datadog/tracing/trace_operation.rb
Line 77 in 4f646ea
And there's no mechanism to inherit sampling from the active span in v1.x.
This doesn't normally affect traces, as the
PrioritySampler
, which is the default sampler, always setssampled = true
:dd-trace-rb/lib/datadog/tracing/sampling/priority_sampler.rb
Lines 92 to 98 in 4f646ea
But, sampling checks are completely skipped if the sampling decision was made in an upstream service. We only check the sampler if the current span is a root span (
parent_id == 0
):dd-trace-rb/lib/datadog/tracing/tracer.rb
Line 345 in 4f646ea
Because distributed traces won't have any spans with
parent_id == 0
, as the local root span inherits theparent_id
from the upstream distributed span, we never invoked thePrioritySampler
.What does this PR do?
This PR sets
TraceOperation#sampled
totrue
by default, as having traces being sampled by default was the desired intent in first place.