Pcornel
Browse topics
Options
Recent
Favorites
Observability · Technical reference

Trace Sampling

Direct answer

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).

When to use this

Use it to control tracing cost while keeping useful traces.

First 30 seconds

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.

Operational verification

trace starts → sampling decision → kept or dropped → stored

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
OpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformOpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
Scope / prerequisiteUse it to control tracing cost while keeping useful traces.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

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.

Key checks
  • OTEL_TRACES_SAMPLER=parentbased_traceidratio — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool 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

StrategyDecision pointPros / cons
Head (probabilistic)At trace start (e.g. 10 %)Cheap; may miss rare errors
Parent-basedFollows upstream decisionConsistent traces
Tail samplingIn the collector after the trace completesKeep 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

EffectHandling
Counts from traces are scaled samplesTake request rates and error rates from metrics, not from trace counts
Exemplars may point to dropped tracesSample traces with exemplars, or accept occasional empty links
Different rates per serviceUse parent-based samplers everywhere so traces are complete
Debugging a single requestForce 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Terminology layer

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.

Aliases that resolve here
trace samplingtrace samplingtail sampling collector
Confirmation

Confirm action

Continue?