Tracing Sample
Trace Sampling Practice Guide Based on DDTrace and OpenTelemetry
Focuses on resolving sampling issues in multi-trace concatenation scenarios.
Comparison of Sampling¶
DDTrace Sampling Behavior Analysis¶
-
Sampling Priority Field Logic In DDTrace, the
_sampling_priority_v1
field serves as the key identifier:1
: Default marker when no sampling is configured, indicates trace retention by system rules2
: Explicit user-configured retention marker (e.g., traces selected by 50% sampling rate)-1
: Traces to be dropped under user-defined rules (e.g., low-priority business traces)0
: Built-in deletion marker (e.g., when upstream service marks for deletion without active sampling rules)
-
Sampling Decision Propagation When upstream services exist (non-DDTrace agents), downstream sampling configurations become ineffective, with decision authority transferred upstream. This may cause trace tagging inconsistencies.
-
Sampling Configuration Example
OpenTelemetry Sampling Mechanism¶
-
W3C Protocol Propagation
OTel usestrace-flags
in thetraceparent
header to convey sampling status:00
: Non-sampled traces (not reported to DataKit)01
: Sampled traces (fully reported)
-
Sampling Configuration Example
# 50% sampling based on parent TraceID ratio
-Dotel.traces.sampler=parentbased_traceidratio -Dotel.traces.sampler.arg=0.5
OpenTelemetry Agent sends pre-sampled traces to DataKit. DDTrace implements server-side sampling at the service end.
Key Differences¶
Feature | DDTrace | OpenTelemetry |
---|---|---|
Data Reporting Strategy | Full collection with server-side filtering | Client-side filtered data collection |
Protocol Compatibility | W3C support with field collision risks | Native W3C standard compliance |
Multi-level Control | Downstream sampling constrained by upstream | Supports distributed decision coordination |
Concatenation Issues¶
W3C Protocol Compatibility Issues¶
-
Field Mapping Conflicts
Semantic overlap between DDTrace's_sampling_priority_v1
and OTel'strace-flags
with value logic differences:trace-flags
only has 0/1 states vs DDTrace's four-state system- DDTrace converts
trace-flags
0/1 to_sampling_priority_v1
0/1 instead of rule-based -1/2
-
Decision Authority Override Risks In mixed DDTrace-OTel environments:
- Upstream services forcibly override downstream sampling configurations
- Sampling markers from upstream dictate entire trace behavior
Data Consistency Challenges¶
- Sampling State Discontinuity
When OTel-processed traces (marked01
) propagate to DDTrace services:- DDTrace may reset new spans'
_sampling_priority_v1
to1
, causing DataKit sampling filters to mis delete data - DataKit OTel collectors might improperly drop traces that should be retained
- DDTrace may reset new spans'
Recommended solution: Enable sampling at the entry-point service and propagate through protocol headers.
Recommended Configuration Practices¶
Single Agent Type Configuration:
- For DDTrace-only environments: Enable sampling at either Agent or DataKit end, not both
- For OTel environments: Enable sampling at only one endpoint (Agent or DK) to prevent trace fragmentation
Multi-Agent Concatenation Configuration:
- Recommended practice:
- Enable head-end sampling at Agent
- Disable DataKit sampling
- Prevents span loss when DDTrace converts W3C headers:
_sampling_priority_v1
reset to1
might be deleted by DDTrace collector rules- Ensures complete trace preservation
For concatenated protocol configuration using tracecontext
, refer to:
Multi-Trace Concatenation Guide
Note: All configurations should be validated in testing environments before production deployment. Protocol conversions may cause unexpected behaviors in complex hybrid scenarios.