TracekitTracekit

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.

Terry Osayawe5 min read
OpenTelemetry Collector Tail Sampling Policy: A Practical Test

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

TraceIntended resultWhy
Any span has status ERRORKeepPreserve a failed request for investigation.
Whole trace lasts at least 1,500 msKeepPreserve a slow request, even without an error.
Neither condition matchesKeep 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 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.

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

CheckWhat to inspectLikely action
SDKIs head sampling enabled? Did the SDK export the trace?Keep the trace upstream or change the SDK sampling plan.
ReceiverDid all expected spans reach the Collector?Inspect exporter errors and context propagation.
RoutingDid every span with this trace ID reach the same Collector instance?Route by trace ID before tail sampling.
DecisionDid the relevant span arrive before the decision?Review decision_wait and late spans.
BufferWas the pending trace evicted?Review num_traces, memory, and dropped-early metrics.
ExporterDid a kept trace leave the Collector?Inspect queue, retry, and backend response errors.

The tail sampler is stateful. OpenTelemetry's Collector scaling guide 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 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 and shows their spans in 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. It explains how sampling changes trace-based signals. For a single exported trace, the 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 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.

Share this post

Related Posts

How to Correlate Logs with Traces When Debugging
6 min

How to Correlate Logs with Traces When Debugging

Correlate logs with traces using trace IDs, span IDs, and a request test. Find missing context across services without relying on timestamps alone.

distributed-tracingopentelemetry
How to Visualize OpenTelemetry Traces Online
9 min

How to Visualize OpenTelemetry Traces Online

Visualize OpenTelemetry traces online, read the waterfall, fix export errors, and choose the right OTel trace viewer for each debugging job.

opentelemetrydistributed-tracing