Use it to control tracing cost while keeping useful traces.
Trace Sampling
Trace sampling decides which traces to keep: head sampling (decided at start, e.g. 10 %) or tail sampling (decided after completion, e.g. keep all errors and slow traces).
1. Sampler setting: OTEL_TRACES_SAMPLER=parentbased_traceidratio and OTEL_TRACES_SAMPLER_ARG.
2. Tail sampling policy in Collector.
3. Errors and slow traces kept?
4. Load-balancing exporter by trace ID.
5. Volume vs budget.
trace starts → sampling decision → kept or dropped → stored
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Check that sampled traces are complete across services. Watch collector memory when tail sampling.
Step 2 Common failures Narrow the fault
Different sample rates per service create broken traces. Tail sampling across several collector instances without trace-ID routing loses spans. Metrics derived from sampled traces must be scaled.
Head sampling must be consistent across services (parent-based). Tail sampling in the Collector needs all spans of a trace on the same Collector instance.
OTEL_TRACES_SAMPLER=parentbased_traceidratio— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool check config prometheus.yml— config valid
ReferenceWhat it is1 section · depth on demand
How it works
Parent-based samplers follow the decision of the caller so traces are complete. Tail sampling buffers spans in the collector until the trace ends, which needs memory and routing all spans of a trace to the same collector.
ReferenceImportant terms & boundaries3 sections · depth on demand
Sampling strategies
| Strategy | Decision point | Pros / cons |
|---|---|---|
| Head (probabilistic) | At trace start (e.g. 10 %) | Cheap; may miss rare errors |
| Parent-based | Follows upstream decision | Consistent traces |
| Tail sampling | In the collector after the trace completes | Keep all errors/slow traces; needs memory and all spans on one collector |
Typical: keep 100 % of error and slow traces with tail sampling, plus a small percentage of normal traffic.
In depth
Head sampling
The decision is made when the root span starts, and propagated in the sampled flag so every service keeps or drops the same trace.
OTEL_TRACES_SAMPLER=parentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG=0.1 # 10 % of new traces; children follow the parent
Cheap and simple, but it decides before anything is known: 90 % of the rare error traces are discarded too.
Tail sampling
The collector waits until a trace is complete (a decision wait of, say, 10 s) and then applies policies:
processors:
tail_sampling:
decision_wait: 10s
policies:
- { name: errors, type: status_code, status_code: { status_codes: [ERROR] } }
- { name: slow, type: latency, latency: { threshold_ms: 1000 } }
- { name: baseline, type: probabilistic, probabilistic: { sampling_percentage: 5 } }
Keeps all errors and slow traces plus 5 % of the rest. Cost: memory for every in-flight trace, and all spans of a trace must reach the same collector instance — put a load-balancing exporter (routing by trace ID) in front of a tail-sampling tier.
Consequences to plan for
| Effect | Handling |
|---|---|
| Counts from traces are scaled samples | Take request rates and error rates from metrics, not from trace counts |
| Exemplars may point to dropped traces | Sample traces with exemplars, or accept occasional empty links |
| Different rates per service | Use parent-based samplers everywhere so traces are complete |
| Debugging a single request | Force sampling with a header or attribute for that request |
The OpenTelemetry documentation suggests sampling becomes worthwhile at roughly a thousand traces per second or more; below that, keeping everything is often cheaper than running the sampling infrastructure.
Common mistakes
- Sampling away the errors you need.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.