Test OpenTelemetry Tail Sampling With Traffic You Control
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:
| Run | Traffic | What you should see in the backend |
|---|---|---|
| 1. Baseline | E-Commerce with a 5% error rate | Every error trace, every slow trace, and about 10% of the healthy ones |
| 2. Error storm | Error Storm scenario (80% errors) | Nearly everything kept — the errors policy is doing its job |
| 3. Latency | Latency Spike scenario (30% of spans take 2–8 s) | All slow traces kept even though few are errors — the latency policy |
| 4. Healthy only | A scenario at 0% errors and no latency injection | About 10% of traces — the probabilistic policy alone |
How to check
- 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.
- 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_waitexpired. - Verify no error is lost. Search for error status spans by service and compare with the activity stream's error entries.
- Watch the collector. The processor exposes metrics about decisions and dropped traces; if you see traces dropped before a decision, raise
num_tracesor the memory limit.
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
- One trace, one collector. Tail sampling needs every span of a trace in the same Collector instance. With several Collectors you need a load-balancing exporter that routes by trace ID in front of them. Test the whole topology, not just a single instance.
- Memory. Buffered traces cost memory in proportion to rate times
decision_wait. Ramp the speed multiplier (up to 10×) and watch the Collector's memory; set a memory limiter ahead of the sampler.