Start with a bounded policy
This example keeps traces when any span hasERROR status, when any span has a
recorded exception event, or when the trace is slower than one second. It also
keeps a 10 percent baseline sample of the remaining traces.
otel-collector-config.yaml
num_traces, caches, and decision_wait for your trace rate and maximum
normal trace duration. A larger buffer or longer wait uses more memory.
Recording an exception adds a span event. It does not set the span status to
ERROR. Instrumentation must record the exception event, set ERROR status,
or both. Failures that produce neither signal can only enter through the
baseline sample. Add policies for other error signals that your services use.
Configure SDK sampling
Tail sampling cannot restore a trace that an SDK dropped. Send all candidate traces from the SDK to the tail-sampling Collector, usually with analways_on
head sampler. Keep a lower SDK head-sampling rate only when application
overhead is more important than complete tail decisions.
Do not apply independent random head-sampling decisions in each service. That
can produce partial traces before the Collector sees them.
Scale safely
For one Collector instance, send every service in the trace to that instance. For several instances, route by trace ID through an OpenTelemetry load-balancing exporter before the tail-sampling layer. A normal round-robin load balancer can split one trace and cause an incorrect decision. Keep processors that need receiver context, such as Kubernetes attribute enrichment, beforetail_sampling.
Monitor the Collector
Watch the Collector’s own metrics for:- traces removed before a decision
- late spans
- sampling-decision latency
- exporter failures
- accepted and exported spans
decision_wait, reduce incoming
volume, or increase num_traces and available memory. Change one control at a
time and compare the retained error and slow-trace counts.
Verify
- Run the pipeline without tail sampling and record a short baseline.
- Enable tail sampling for one service.
- Send a successful fast trace, a slow trace, a trace with
ERRORspan status, and a trace with a recorded exception event but unset span status. - Confirm that the slow trace and both error-signal traces always arrive.
- Compare Collector accepted/exported counts and Squasher trace volume.
- Widen the rollout only after late-span and early-drop metrics stay healthy.