Sampling-Propagation:Set sampling decision mechanism tag
Follow up from #2266
This PR adds a trace-level tag to propagate the sampling mechanism used to make a sampling decision: _dd.p.dm.
The currently defined mechanisms are (many unused):
module Mechanism
# Used before the tracer receives any rates from agent and there are no rules configured.
DEFAULT = 0
# The sampling rate received in the agent's http response.
AGENT_RATE = 1
# Auto. Reserved for future use.
REMOTE_RATE_AUTO = 2
# Sampling rule or sampling rate based on tracer config.
TRACE_SAMPLING_RULE = 3
# User directly sets sampling priority via {Tracing.reject!} or {Tracing.keep!},
# or by a custom sampler implementation.
MANUAL = 4
# Formerly AppSec.
ASM = 5
# User-defined target. Reserved for future use.
REMOTE_RATE_USER = 6
# Reserved for future use.
REMOTE_RATE_BY_DATADOG = 7
# Single Span Sampled.
SPAN_SAMPLING_RATE = 8
end
The sampling mechanism can either come from an upstream service, if the sampling decision was performed upstream, or added by one of ddtraces sampling classes.
This PR also adds many feature test around different sampling mechanism (e.g. manual sampling, agent-based rates) in order to test for the newly added sampling mechanism tag. This unveiled a few bugs that have been fixed in separated PRs.
_dd.p.dm serialization format
One quirk of the implementation is due to the historical format of _dd.p.dm on other tracers: _dd.p.dm used to be comprised of two pieces of information, separated by a dash (-), e.g. info1-sampling_mechanism.
info1 is temporarily removed, by sampling_mechanism stays. This means that _dd.p.dm will look like this: -sampling_mechanism.
This ensures users using old versions of Datadog products that support the info1-sampling_mechanism format can still participate in the sampling propagation chain.
Codecov Report
Merging #2282 (627c116) into feat-Sampling-Propagation (8937ec9) will increase coverage by
0.00%. The diff coverage is99.39%.
@@ Coverage Diff @@
## feat-Sampling-Propagation #2282 +/- ##
===========================================================
Coverage 97.59% 97.59%
===========================================================
Files 1095 1095
Lines 57535 57788 +253
===========================================================
+ Hits 56149 56396 +247
- Misses 1386 1392 +6
| Impacted Files | Coverage Δ | |
|---|---|---|
| .../datadog/appsec/contrib/rack/request_middleware.rb | 25.86% <0.00%> (-0.46%) |
:arrow_down: |
| lib/datadog/tracing/sampling/span/ext.rb | 100.00% <ø> (ø) |
|
| spec/datadog/tracing/sampling/rule_sampler_spec.rb | 99.27% <88.88%> (+0.03%) |
:arrow_up: |
| lib/datadog/appsec/event.rb | 91.11% <100.00%> (+0.20%) |
:arrow_up: |
| lib/datadog/core/configuration/components.rb | 97.20% <100.00%> (ø) |
|
| lib/datadog/tracing/flush.rb | 96.55% <100.00%> (ø) |
|
| lib/datadog/tracing/metadata/ext.rb | 100.00% <100.00%> (ø) |
|
| lib/datadog/tracing/sampling/ext.rb | 100.00% <100.00%> (ø) |
|
| lib/datadog/tracing/sampling/priority_sampler.rb | 96.42% <100.00%> (+0.97%) |
:arrow_up: |
| ...ib/datadog/tracing/sampling/rate_by_key_sampler.rb | 89.58% <100.00%> (-0.22%) |
:arrow_down: |
| ... and 25 more |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more