Services

Resources

Company

/

Trace sampling

Trace sampling

Trace sampling means a system records only some of its traces, so that storage and the tracing backend can keep up. With head sampling, the keep-or-drop decision is made when the request starts. With tail sampling, it waits until the trace is complete and looks at what happened, such as an error or high latency.

How it works

With head sampling at 10%, a service handling 1,000 traces per second keeps about 100, chosen at random by trace ID. It is cheap, but it drops most rare errors.

Tail sampling, for example the tail_sampling processor in the OpenTelemetry Collector, buffers spans for a decision window such as 20 seconds. When the window closes, it keeps every trace with an error and every trace slower than 2 seconds, plus a small random share of everything else. All spans of a trace must reach the same Collector instance, so gateways usually route by trace ID.

Why it matters in production

At 1,000 traces per second, keeping everything means storing and indexing every one of them. A 10% head sample cuts that to about 100, but the trace for the one failed request you are chasing during an incident is probably among the 900 dropped. Tail sampling keeps error and slow traces by policy. In exchange, the Collector holds 20 seconds of spans in memory, and the gateways in front of it have to route by trace ID.

See also

On the One2N blog

References

  1. Sampling (OpenTelemetry documentation)

Two-lane diagram of trace sampling for 1,000 traces a second. Head sampling decides at the start: a funnel keeps 10% by trace ID, about 100 kept, and a red dashed path ending in an X shows the rare error trace being dropped. Tail sampling decides when the trace is complete: spans wait in a 20 second buffer, then policies keep all errors, traces slower than 2 seconds and a small random share, at the cost of memory.

Putting this into practice?

Talk to One2N about our SRE consulting

Talk to One2N about our SRE consulting