In this lesson · topic 6 of 7
Topic 6
What a tail sampler costs to run
7 min read
The sampling topic ended with a promise and a warning: a tail sampler keeps the traces you want, and it has to hold every span until it decides. This topic puts numbers on the second half.
Sizing the buffer
A tail sampler holds each trace from its first span until a decision timer fires. The OpenTelemetry Collector’s tail sampling processor calls that timer decision_wait and defaults it to 30 seconds, so a trace waits half a minute after its first span.
Take a service that starts 5,000 traces a second, averaging 20 spans per trace, with each buffered span costing around 600 bytes. These are illustrative figures, not measurements of any product. At steady state the buffer holds 5,000 times 30, or 150,000 traces. That is 3 million spans, about 1.8 GB of memory, and that is before any burst.
The processor also caps how many traces it keeps, with a default of 50,000. At 5,000 traces a second that is only 10 seconds of traffic. If the cap is smaller than rate times wait, the buffer cannot hold a trace for the whole decision window, so traces are pushed out before their timer fires and the 30 second setting stops meaning what it says. Size the cap from the product of rate and wait, plus headroom for bursts.
Predict first
Every span to one place
A decision needs the whole trace, so all spans of a trace must reach the same sampler instance. In practice that means a two-tier layout. Services send to a first tier that routes by a hash of the trace identifier, and a second tier runs the sampling rules. Add or remove an instance of the second tier and the hash mapping shifts. Traces in flight at that moment have their spans split across two instances, and each judges a partial trace. Plan resizes for quiet periods and expect a short dip in quality.
Spans can also arrive after the decision. A slow service may report a span 40 seconds after the trace started. If the sampler has already decided and forgotten the trace, that span has nowhere to go. The processor offers caches of recent decisions so a late span can follow the earlier verdict, and they need sizing in the same way as the buffer.
When an incident multiplies the bill
Suppose the rules are: keep every trace with an error, and keep two percent of the rest. On a normal day half a percent of traces have errors, so the store keeps 0.5 plus 2 percent of the remaining 99.5, which is about 2.5 percent of traces.
Now an outage pushes the error rate to 40 percent. The store keeps 40 percent plus 2 percent of the remaining 60, or 41 percent. That is more than 16 times the normal volume, arriving exactly when everything else is struggling. Storage and ingest that were sized for 2.5 percent fall over.
The defence is a cap on the output. A rate-limiting policy keeps at most a fixed number of spans per second, so errors are favoured but bounded. You lose some error traces in a big incident, but the pipeline survives and the surviving sample is still full of the failure.
Sources
- Sampling, OpenTelemetry documentation, on head and tail sampling and their trade-offs.
- Tail sampling processor, OpenTelemetry Collector contrib repository, for
decision_wait,num_traces, decision caches and the rate-limiting policy.