Monitoring glossary
What is trace sampling?
Sampling keeps a share of traces so tracing stays affordable on busy services. Done well, you still see every error and slow request that matters.
3 min read9 sectionsUpdated
On this page
Key points
- Head sampling decides at the start of a trace; it is simple and cheap.
- Tail sampling decides at the end, so it can keep every error and slow trace.
- Use a parent-based rule so a trace is either fully kept or fully dropped.
- Counts reflect what you send: at 10% sampling, request counts show 10% of traffic.
Why sample at all
A service handling 2,000 requests per second with 20 spans each produces 40,000 spans per second: over 3 billion a day. Storing all of them is rarely worth it, because most are near-identical successful requests. Sampling keeps enough to describe normal behaviour while cutting volume and cost.
Do not sample too early, though. Under a few hundred requests per second, keeping 100% is often affordable and gives you complete data. Start at 100% and reduce when the bill or the volume says so.
| Type | Decides | Pros | Cons |
|---|---|---|---|
| Head (probabilistic) | At the root span, e.g. keep 10% | Simple, cheap, no buffering | Drops errors at the same rate as successes |
| Parent-based | Follows the parent’s decision | Traces are never half kept | Needs a root decision somewhere |
| Tail | After the trace completes, in a Collector | Keep all errors and slow traces | Needs buffering and more infrastructure |
| Rate limiting | At most N traces per second | Predictable cost | Uneven coverage under spikes |
Tail sampling with the Collector
The OpenTelemetry Collector (contrib distribution) has a tail_sampling processor. It waits for a trace to finish, then applies policies such as "keep every trace with an error" and "keep traces slower than 1 second", with a probabilistic policy for the rest. All spans of a trace must reach the same Collector instance, so this needs care when you run several.
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: some-of-the-rest
type: probabilistic
probabilistic: { sampling_percentage: 10 }What sampling does to your numbers
Request counts and throughput charts built from sampled spans show only the kept share. Percentiles stay representative under random head sampling, but tail sampling deliberately biases toward errors and slow requests, so error rates computed from tail-sampled data look worse than reality. Keep this in mind when comparing dashboards, and do not use sampled counts as billing-grade totals.
What sampling rate should I use?
Start at 100%. When volume becomes a cost problem, move to a parent-based ratio such as 10 to 25% on the busiest services, and consider tail sampling if you need every error.
Does sampling affect logs?
Not directly. Logs are sent separately. But a log line whose trace was dropped will link to a trace that does not exist, so some teams also sample debug logs.
Can different services use different rates?
Yes, but use parent-based sampling everywhere so downstream services respect the root decision and traces stay whole.
Related reading
- OpenTelemetry sampling: head vs tail, and how to choose: Choose an OpenTelemetry sampling strategy: head sampling with ParentBased, tail sampling for errors and slow traces, and what to know about the costs of each.
- What is a span in tracing?: What a span is in distributed tracing: its fields, parent and child spans, span kinds, attributes and status, with an annotated example you can read.
- What is context propagation?: How context propagation links spans across services: the W3C traceparent and tracestate headers, baggage, queues, and the usual reasons traces break.
- ECS and Fargate monitoring: Monitor Amazon ECS and Fargate: CPU and memory per service, stopped-task reasons, ALB target health, logs and traces.
- How to monitor a Next.js app: How to monitor a Next.js app in production: uptime checks, Core Web Vitals, server and edge errors, OpenTelemetry traces for SSR and API routes, and alerts.
- OpenTelemetry for FastAPI: Trace a FastAPI service with OpenTelemetry: instrument the app, async database drivers and httpx, run uvicorn workers correctly and export.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.