How do the `ParentBased` and `TraceIdRatioBased` samplers work together?
AdvancedConceptTracing & OpenTelemetry
Answer
TraceIdRatioBased(0.1) makes a deterministic decision from the trace ID, so every service using the same ratio agrees on the same trace. ParentBased wraps it: if there is an incoming parent, follow the parent's decision; only root spans use the ratio.
export OTEL_TRACES_SAMPLER=parentbased_traceidratio
export OTEL_TRACES_SAMPLER_ARG=0.1
Without ParentBased, a downstream service with a different ratio would drop spans of traces the upstream kept, producing broken traces. Other options: always_on, always_off, parentbased_always_on (the default). Also note: an unsampled span is still created for context propagation; it is just not recorded or exported.
More on Tracing & OpenTelemetry
What is distributed tracing, and what are a trace, a span and a span context?BeginnerWhat fields does an OpenTelemetry span carry?BeginnerWhat are span kinds and why do they matter?IntermediateWhat does the W3C `traceparent` header look like?IntermediateWhat is baggage, and how is it different from span attributes?IntermediateWhat is OpenTelemetry and what are its main parts?Beginner