Skip to content

[Single Span Sampling] Consider traces rejected solely by priority sampling as rejected#2131

Merged
marcotc merged 3 commits into
feature-single-span-samplingfrom
single-span-fix-priority-sample
Jul 28, 2022
Merged

[Single Span Sampling] Consider traces rejected solely by priority sampling as rejected#2131
marcotc merged 3 commits into
feature-single-span-samplingfrom
single-span-fix-priority-sample

Conversation

@marcotc

@marcotc marcotc commented Jul 6, 2022

Copy link
Copy Markdown
Member

The tracer flushes all traces that have not been dropped by the internal sampler (TraceOperation#sampled == false means dropped internally). This includes traces that might be dropped due to their Priority Sampling status downstream.

For Single Span Sampling, we need to guarantee that Single Span Sampled spans are kept and thus cannot trust that all spans flushed by the tracer are kept, unless it's both selected by the internal sampler (TraceOperation#sampled == true) the Priority Sampling status are set to keep (TraceOperation#sampling_priority > 0).

This logic is different from the logic used to flush traces through the transport: the tracer wants to send all traces that have not been rejected internally OR traces with Priority Sampling > 0. For Single Span Sampling, we only want to apply Single Span Sampling to spans that we know are going to be dropped, either internally or by the agent. This means that there's an intersection of states where these two processes diverge: when the tracer sends the trace to the agent, but it's dropped by priority sampling.

This PR ensures that this intersecting state is correctly handled for Single Span Sampling.

Single Span Sampling is moving the tracer more towards making independent sampling decisions, and thus having a bit more complicated logic, which currently resides in the agent.

@marcotc
marcotc requested a review from a team July 6, 2022 20:48
@marcotc
marcotc force-pushed the single-span-fix-priority-sample branch 2 times, most recently from a7073ed to 282196b Compare July 6, 2022 20:57
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #2131 (282196b) into feature-single-span-sampling (1abd498) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@                      Coverage Diff                      @@
##           feature-single-span-sampling    #2131   +/-   ##
=============================================================
  Coverage                         97.53%   97.53%           
=============================================================
  Files                              1047     1047           
  Lines                             54232    54256   +24     
=============================================================
+ Hits                              52896    52920   +24     
  Misses                             1336     1336           
Impacted Files Coverage Δ
lib/datadog/tracing/sampling/span/sampler.rb 100.00% <100.00%> (ø)
lib/datadog/tracing/trace_operation.rb 98.83% <100.00%> (+0.01%) ⬆️
spec/datadog/tracing/sampling/span/sampler_spec.rb 100.00% <100.00%> (ø)
spec/datadog/tracing/trace_operation_spec.rb 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@marcotc
marcotc force-pushed the single-span-fix-priority-sample branch from 282196b to f926088 Compare July 9, 2022 00:16
Comment thread lib/datadog/tracing/sampling/span/sampler.rb Outdated
Comment thread lib/datadog/tracing/trace_operation.rb

@ivoanjo ivoanjo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 LGTM

Comment thread lib/datadog/tracing/trace_operation.rb
Comment on lines -33 to +36
return if trace_op.sampled?
return if trace_op.sampled? && trace_op.priority_sampled?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change is incredibly important, and incredibly subtle. The description you wrote on the PR description is quite helpful in understanding why this is done this way -- can I convince you to copy paste it here as a comment, so it stays closer to the code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Docs flushed out!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I still kinda think the longer version in the PR description deserves a life as a comment right here above this line where it applies)

@marcotc
marcotc merged commit 10b72d0 into feature-single-span-sampling Jul 28, 2022
@marcotc
marcotc deleted the single-span-fix-priority-sample branch July 28, 2022 00:05
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.

3 participants