# OpenTelemetry Collector Tail Sampling Policy: A Practical Test

> Configure an OpenTelemetry Collector tail sampling policy for errors, slow traces, and a baseline sample. Test what stays and find missing spans.

- Published: 2026-11-27T00:00:00.000Z
- Updated: 2026-11-27T00:00:00.000Z
- Author: Terry Osayawe
- Tags: opentelemetry, distributed-tracing, sampling, production-debugging
- Canonical: https://tracekit.dev/blog/opentelemetry-collector-tail-sampling-policy

An **OpenTelemetry Collector tail sampling policy** decides which traces to export after the Collector receives their spans. A useful first policy keeps error traces and slow traces. It also keeps a small sample of ordinary traffic. This guide shows the configuration, a repeatable test, and the checks to run when a trace disappears.

Tail sampling is a feature of the [OpenTelemetry Collector Contrib processor](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/README.md). It is not a feature that a tracing backend adds to a missing trace. If an SDK drops a trace through head sampling, the Collector cannot recover it.

## Start with three outcomes

| Trace | Intended result | Why |
| --- | --- | --- |
| Any span has status `ERROR` | Keep | Preserve a failed request for investigation. |
| Whole trace lasts at least 1,500 ms | Keep | Preserve a slow request, even without an error. |
| Neither condition matches | Keep 10% | Retain a baseline view of normal traffic. |

The 1,500 ms threshold and 10% baseline are **example settings**, not universal defaults. Pick values from your service objective and trace volume. The [OpenTelemetry sampling guide](https://opentelemetry.io/docs/concepts/sampling/) explains why a tail decision can use errors and latency from the trace, while a head decision cannot see the final outcome.

## Configure the tail sampling processor

Use a Collector distribution that includes `tail_sampling`, such as the Contrib distribution. Put the processor in the traces pipeline between the receiver and exporter. This example assumes that your existing `otlp` receiver and `otlphttp/backend` exporter are already configured.

```yaml
processors:
  tail_sampling:
    decision_wait: 10s
    num_traces: 20000
    policies:
      - name: keep-errors
        type: status_code
        status_code:
          status_codes: [ERROR]
      - name: keep-slow
        type: latency
        latency:
          threshold_ms: 1500
      - name: baseline
        type: probabilistic
        probabilistic:
          sampling_percentage: 10

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [tail_sampling]
      exporters: [otlphttp/backend]
```

The processor evaluates policies for each trace. A matching keep policy can retain the trace. These three rules form a union: an error trace does not need to win a race against the baseline rule. Do not treat policy order as a priority list. The [processor's decision flow](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/README.md#policy-decision-flow) has special behavior for explicit `drop` policies, so add those only after you test their interaction with keep policies.

`decision_wait` gives spans time to arrive before the decision. `num_traces` limits the number of traces held in memory. The values above illustrate the shape of a configuration. Size them against your arrival rate, trace duration, memory limit, and Collector metrics. A busy service can evict traces before the timer fires.

## Test the policy with four requests

Run this test in a nonproduction environment. Keep a single Collector instance for the first test, and give every request a unique trace ID.

1. Send a successful request below 1,500 ms. Repeat it enough times to observe the baseline sample. Do not expect any one request to be kept.
2. Send a request with a span whose OpenTelemetry status is `ERROR`. Check that its trace appears after the decision wait.
3. Send a successful request whose complete trace lasts more than 1,500 ms. Check that it appears.
4. Send a request that is both slow and in error. Check that you get one complete trace, not two copies.

Record the trace IDs at the application and receiver before you look in the backend. Wait longer than `decision_wait` before you mark an expected trace missing. A small set of baseline requests does not prove that the 10% rule works. Use a larger repeatable sample, then compare counts rather than assuming an exact 10% result.

If you need a temporary control, replace the three policies with `always_sample` in the same test environment. This isolates export and backend problems from policy decisions. Restore the intended policy after the test.

## Find a missing error or slow trace

Check the path in order. A trace cannot reappear after an upstream component drops it.

| Check | What to inspect | Likely action |
| --- | --- | --- |
| SDK | Is head sampling enabled? Did the SDK export the trace? | Keep the trace upstream or change the SDK sampling plan. |
| Receiver | Did all expected spans reach the Collector? | Inspect exporter errors and context propagation. |
| Routing | Did every span with this trace ID reach the same Collector instance? | Route by trace ID before tail sampling. |
| Decision | Did the relevant span arrive before the decision? | Review `decision_wait` and late spans. |
| Buffer | Was the pending trace evicted? | Review `num_traces`, memory, and dropped-early metrics. |
| Exporter | Did a kept trace leave the Collector? | Inspect queue, retry, and backend response errors. |

The tail sampler is stateful. [OpenTelemetry's Collector scaling guide](https://opentelemetry.io/docs/collector/scaling/) describes trace-aware routing when you use more than one sampling Collector. A normal round-robin load balancer can split one trace across instances. Each instance then makes a decision from incomplete spans.

The processor documents `otelcol_processor_tail_sampling_sampling_trace_dropped_too_early` for buffer eviction. It also documents decision timing and late-span behavior. Check the [current processor metrics](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/tailsamplingprocessor/documentation.md) for your Collector version. Do not assume that every missing backend trace is a sampling decision.

## Keep the backend role clear

The Collector decides which traces to export. The backend receives the traces that survive. Tracekit accepts [OTLP traces without a Tracekit SDK](/docs/integration/overview) and shows their spans in [distributed tracing](/features/distributed-tracing). Tail sampling remains in your Collector configuration. Tracekit cannot show a trace that the Collector never exports.

For an incident that needs alerts, read the [trace sampling and alert setup guide](/blog/trace-based-alerts-setup-sampling). It explains how sampling changes trace-based signals. For a single exported trace, the [OTel trace viewer guide](/blog/otel-trace-viewer-guide) helps you check the parent-child tree and timing. If a trace shows the slow path but not the variable that caused it, [dynamic logs](/docs/code-monitoring) can capture bounded runtime state at capture points.

## Roll out with a measurable result

Before production, record the share of traces kept by each condition, Collector memory use, dropped-early traces, exporter failures, and the delay between a request and a visible trace. Run the test again after you add Collector replicas or change SDK head sampling. Keep error and slow-trace examples as regression cases. A policy is useful only when the traces needed for an incident still reach the backend.
