Collector

Test OpenTelemetry Tail Sampling With Traffic You Control

Make sure the traces you most need are the ones you keep.

Tail-based sampling decides whether to keep a trace after seeing all of it, so you can keep every error and every slow request and only a sample of the rest. It is powerful, and easy to get wrong: a policy that quietly drops error traces looks exactly like a healthy system. This guide shows how to test a tail-sampling configuration with traffic whose errors and latency you control.

A configuration to test

The Collector's tail_sampling processor (in the contrib distribution) evaluates policies against buffered traces. This one keeps every error, every request slower than one second, and ten percent of the rest:

processors:
  tail_sampling:
    decision_wait: 10s        # how long to wait for a trace to complete
    num_traces: 50000         # traces held in memory while waiting
    policies:
      - name: keep-errors
        type: status_code
        status_code: { status_codes: [ERROR] }
      - name: keep-slow
        type: latency
        latency: { threshold_ms: 1000 }
      - name: sample-the-rest
        type: probabilistic
        probabilistic: { sampling_percentage: 10 }

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [tail_sampling, batch]
      exporters: [otlp/backend]

Generate traffic with a known mix

You can only check a sampling decision if you know what went in. Run these in turn, each for a few minutes, resetting the counters on the Stats page between runs:

RunTrafficWhat you should see in the backend
1. BaselineE-Commerce with a 5% error rateEvery error trace, every slow trace, and about 10% of the healthy ones
2. Error stormError Storm scenario (80% errors)Nearly everything kept — the errors policy is doing its job
3. LatencyLatency Spike scenario (30% of spans take 2–8 s)All slow traces kept even though few are errors — the latency policy
4. Healthy onlyA scenario at 0% errors and no latency injectionAbout 10% of traces — the probabilistic policy alone

How to check

  1. Count in, count out. The Stats page shows how many traces OTel Studio sent. Compare with the number your backend stored; the ratio should match your policies.
  2. Check that kept traces are complete. Open a few error traces. Every span should be present with correct parent-child links. Missing child spans mean spans arrived after decision_wait expired.
  3. Verify no error is lost. Search for error status spans by service and compare with the activity stream's error entries.
  4. Watch the collector. The processor exposes metrics about decisions and dropped traces; if you see traces dropped before a decision, raise num_traces or the memory limit.
Why spans arrive at different times. In OTel Studio each service in a scenario exports through its own tracer provider, so the spans of one trace can reach the Collector in different batches — as they do from real, separately deployed services. That is exactly the situation decision_wait exists for, which makes it a good test: set it too low and you will see incomplete traces.

Two production gotchas to test for

Keep going