OpenTelemetry (OTel) sampling is how you control which traces you keep without losing visibility into what matters. Head-based sampling is fast and cheap but blind to outcomes; tail-based sampling is intelligent but operationally heavy. For most teams, a hybrid approach—a head-based ratio sampling paired with a managed observability backend—delivers the best balance for cost, fidelity, and reliability.
Observability is a big data problem in modern distributed architectures. A single user request in a microservices environment can generate hundreds of spans across dozens of services. Capturing 100% of this data—sometimes called full trace collection—leads to prohibitive storage costs and a volume of noise that obscures the signals you actually need.
Sampling is the strategic process of selecting which traces to export and store. In OpenTelemetry, sampling is not just about reducing volume; it is about maintaining trace fidelity—ensuring that when a trace is sampled, the entire end-to-end transaction is preserved across every service boundary.
This article covers the core mechanics of OTel trace sampling, the real tradeoffs between head-based and tail-based approaches, the production challenges most guides gloss over, and a practical strategy for getting this right without building a complex infrastructure from scratch.
The mechanics of OpenTelemetry sampling
Three components govern the OTel sampling life cycle:
The sampler is the logic—either at the SDK or Collector level—that makes one of three decisions for each span: Drop (no data recorded), RecordOnly (data recorded locally but not exported), or RecordAndSample (data fully recorded and exported to the backend).
The decision is the result of that logic. Once made at the head of a trace, it is transmitted to every downstream service via the W3C Trace Context standard.
The propagator carries that decision across service boundaries. The sampled flag inside the traceparent header tells every downstream service whether to follow the sampling decision made upstream. If any service in the chain does not support W3C Trace Context propagation, it may restart the decision independently—producing fragmented traces with orphan spans that have no link to the root. This is one of the most common sources of incomplete traces in production.
Head-based sampling: fast, stateless, and blind
Head-based sampling makes the keep-or-drop decision the moment the root span is created, before any downstream data exists. It is the default approach for most OTel SDKs and the lowest-overhead option available.
The three most common head-based samplers are:
- AlwaysOnSampler: Records everything; suited for development and test environments only.
- TraceIdRatioBased: Uses a deterministic hash of the TraceID to sample a percentage of traffic. The setting OTEL_TRACES_SAMPLER_ARG=0.1 captures 10% of all traces.
- ParentBased: A decorator that ensures child spans respect the decision already made by their parent span. This is critical for keeping traces complete when your sampling decision originates upstream.
Ideal use case: High-throughput, predictable systems where controlling ingestion cost is the primary concern and the traffic profile is relatively uniform.
Core limitation: Because the decision happens before the trace completes, head sampling cannot guarantee that traces containing errors or latency spikes are kept. A 10% sample rate is just as likely to drop a critical failure as a routine success.
Tail-based sampling: intelligent but operationally heavy
Tail-based sampling defers the decision until after a configurable wait or timeout when the Collector believes the trace is complete. This requires an OTel Collector sitting between your application and the backend, acting as a stateful buffer.
The Collector holds all incoming spans in memory while waiting for the trace to finish. Once complete, it evaluates the full trace against a set of sampling policies.
Common policies include:
- Latency-based: Keep any trace taking longer than 1,000ms.
- Error-based: Keep traces containing a span with status_code = ERROR.
- Attribute-based: Keep traces matching specific values, such as a particular tenant_id or deployment.environment.
Ideal use case: Debugging rare or intermittent failures, capturing performance outliers, and ensuring that high-severity traces are never dropped regardless of overall sample rate.
Core limitation: The Collector must receive all spans for a given TraceID on the same instance. In horizontally scaled deployments, this requires a dedicated load-balancing tier of collectors that route spans by TraceID hash before they reach the tail-sampling tier. This is a nontrivial operational commitment.
Head-based vs. tail-based sampling: A comparison
| Feature | Head-based sampling | Tail-based sampling |
|---|---|---|
| Decision point | Start of trace (SDK) | End of trace (Collector) |
| Data visibility | Probabilistic, random selection | Deterministic, rule-based selection |
| Operational overhead | Low; stateless, no buffering | High; stateful, requires sticky routing |
| Network cost | Low; unsampled spans are never sent | High; all spans travel to the Collector first |
| Error coverage | May drop critical errors | Guaranteed error capture via policy |
| Memory risk | None | Out of memory (OOM) crash if buffer limits are exceeded |
| Best for | Cost control at scale | Reliability and rare-event capture |
Why sampling is harder than it looks in production
Context propagation failures
If a single service in your call chain does not implement W3C Trace Context propagation—whether because it uses an older instrumentation library, a third-party SDK, or a custom HTTP client—it will generate a new TraceID at that hop. The result is fragmented traces, spans that are orphaned from the root and cannot be stitched back together in your backend. Auditing every service in your chain for propagator support before deploying a sampling strategy is a prerequisite step most teams skip.
The high-cardinality trap
Tail-sampling policies that filter on high-cardinality attributes—such as customer_id or session_id with millions of unique values—can rapidly exhaust the Collector's in-memory buffer. The mitigation is to use the memory_limiter processor ahead of the tail-sampling processor and to monitor otelcol_processor_tail_sampling_sampling_traces_dropped to catch buffer pressure early. If this metric trends above zero consistently, your buffer is undersized for your traffic volume.
Load balancing complexity
For tail sampling to work correctly, every span belonging to a single TraceID must arrive at the same Collector instance. A standard round-robin load balancer will scatter spans across instances, breaking the tail-sampling logic entirely. The solution is a two-tier Collector architecture, with a first tier that load-balances by TraceID hash using the loadbalancingexporter, and a second tier that performs the actual tail-sampling decision. This architecture is operationally sound but requires careful capacity planning and adds a point of failure that needs monitoring as a tier-1 service.
Best practices for a production sampling strategy
Start with ParentBased ratio sampling
A ParentBased(TraceIdRatioBased(0.1)) configuration captures a statistically representative 10% sample of traffic at a predictable cost. Set this using the OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG environment variables so it can be changed without a code deployment.
Use Baggage for on-demand tracing
OpenTelemetry Baggage lets you pass a debug=true flag through your entire call chain. Configure your sampler to always keep traces where this flag is present. This gives your engineers a lightweight way to force full trace capture for a specific user session during active debugging without touching sampling configuration.
Implement adaptive sampling
Link your OTEL_TRACES_SAMPLER_ARG to a dynamic source like a Kubernetes ConfigMap. By triggering a webhook via anomaly detection alerts, you can automatically scale up to 100% sampling during incidents and revert to your cost-effective baseline once the system stabilizes.
Monitor your Collector as a tier-1 service
Track otelcol_processor_tail_sampling_sampling_traces_dropped for buffer overflow signals and otelcol_processor_tail_sampling_sampling_decision_latency_count for decision latency. A spike in decision latency often precedes an OOM event by several minutes and gives you a window to act on.
Consider the probabilistic sampling processor for lighter-weight paths
If you are not already running a tail-sampling Collector, the probabilistic sampling processor offers a significantly lower-overhead alternative for volume reduction. It makes decisions based on TraceID, similar to TraceIdRatioBased at the SDK level, but operates within the Collector pipeline without requiring stateful buffering.
Simplifying the complexity with ManageEngine OpManager Nexus
Building and operating a stateful tail-sampling Collector cluster is a significant engineering commitment. You need a two-tier architecture as described above, persistent monitoring of Collector health, and ongoing tuning as your traffic profile evolves.
OpManager Nexus removes this overhead by hosting and managing the OpenTelemetry Collector for you. You configure your application's SDK or local agent to export telemetry to OpManager Nexus' secure OTLP endpoint, and the platform handles ingestion at scale—without requiring you to deploy, size, or maintain a Collector cluster.
The platform maps traces, spans, and service flows into an interface that surfaces performance bottlenecks, latency trends, error rates, and log drill-downs—all powered by your OTel data. AI-powered anomaly detection highlights top exceptions and performance regressions across your sampled data, helping your team focus on the traces that matter without manually sifting through dashboards.
For teams that want the diagnostic power of tail-based sampling without the operational overhead, OpManager Nexus' managed infrastructure is a practical alternative to building and running that pipeline yourself. See the OpManager Nexus OpenTelemetry integration guide for step-by-step setup instructions.
Which strategy should you choose?
For most organizations, the answer is a hybrid approach:
- Head-based ratio sampling (10–20%) as your baseline for general health monitoring. This keeps costs predictable and gives you a statistically representative view of normal traffic. At 10%, a service handling 10,000 requests per minute will still produce 1,000 sampled traces per minute, more than enough to surface trends.
- Layer error-based or latency-based tail sampling only for the services where rare-event capture is business-critical, and only if your team has the capacity to operate the required Collector infrastructure reliably.
- If your team is not yet ready to operate a stateful Collector cluster, use a managed observability backend like OpManager Nexus to take intelligent action on head-sampled data without building the tail-sampling infrastructure yourself.
The goal is never to capture everything. It is to capture the right things reliably and at a cost your organization can sustain.
Ready to gain deep visibility without the data complexity? Explore OpManager Nexus' OpenTelemetry integration and start your 30-day free trial.
Frequently asked questions
What is OpenTelemetry sampling?
OpenTelemetry sampling is the process of deciding which traces to record and export to a backend. Because 100% trace capture is rarely cost-effective at scale, sampling lets teams reduce data volume while retaining representative and high-value traces. OTel provides built-in samplers at both the SDK level and the Collector level.
What is the difference between head-based and tail-based sampling?
Head-based sampling makes the keep-or-drop decision at the moment a trace starts, before any downstream spans exist. It is fast and stateless but cannot guarantee that errors or slow traces are retained. Tail-based sampling waits until the entire trace completes before making a decision. It allows rule-based policies to capture errors and outliers, but not without requiring a stateful Collector infrastructure to do so.
How do I configure TraceIdRatioBased sampling in OpenTelemetry?
Set two environment variables before starting your application: OTEL_TRACES_SAMPLER=traceidratio and OTEL_TRACES_SAMPLER_ARG=0.1 for 10% sampling. Wrap it in parentbased_traceidratio to ensure that child spans respect the parent's decision: OTEL_TRACES_SAMPLER=parentbased_traceidratio.
What are the main risks of tail-based sampling in production?
There are three primary risks: out-of-memory crashes if the Collector's span buffer is exceeded, fragmented traces if your load balancer does not route by TraceID, and decision latency if the Collector is under-resourced. All three require active monitoring and capacity planning to manage safely.
When should I use head sampling instead of tail sampling?
Head sampling is the right default for most teams. Use it when your primary goal is cost control, your traffic is relatively uniform, and you do not need guaranteed capture of every error or latency spike. Tail sampling adds value when you are debugging rare failures or need deterministic coverage of specific trace conditions, but only if your team can commit to operating the required infrastructure.
What is OpenTelemetry Baggage and how does it enable forced tracing?
OpenTelemetry Baggage is a key-value propagation mechanism that travels with the trace context across every service boundary. You can use it to pass a debug=true flag from a client request through your entire microservices chain. Configuring your sampler to always keep traces where this flag is present lets engineers force complete trace capture for a specific session without changing global sampling rates.
How does OpManager Nexus simplify OpenTelemetry trace sampling?
OpManager Nexus provides a hosted, managed OTel Collector and OTLP endpoint, eliminating the need to deploy or operate your own Collector infrastructure. It supports standard OTel samplers configurable via environment variables, correlates traces with metrics and logs in a unified dashboard, and uses AI-powered anomaly detection to surface the traces that require attention. Teams get the observability depth of a full OTel pipeline without the operational burden of running one.
How does OpenTelemetry sampling affect APM accuracy?
Head-based sampling makes keep-or-drop decisions before span data exists, which can skew latency and error-rate metrics if high-severity traces are statistically dropped. To preserve accuracy, generate span-based metrics before the sampling stage in your OpenTelemetry Collector pipeline, then apply tail-based sampling only to the raw trace data sent to storage.