Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Observability & SREMixed 23 series

Trace sampling: head, tail, always-on errors

Sampling is where tracing stops being free. A busy service can produce more spans than you can store, so every tracing system decides which traces to keep, and the interesting part is where that decision happens.

Quick reference

Head, tail and the errors you never drop.

Read it bottom to top: head, then tail.

LayerWhat it doesTypical tech
SDK samplerDecides at span start, before the trace exists.HEAD
Ratio 1 in 10Keeps a tenth, children follow the parent.10%
Collector tailWaits for the whole trace, then decides.TAIL
Error policyKeeps every trace with an error span.ERR
Latency policyKeeps traces slower than the SLO.P99
TempoStores what the policies kept.STORE

In one line: Sample the boring, keep the broken. Head sampling is cheap; tail sampling keeps the trace that explains the page.

Set the ratio:

OTEL_TRACES_SAMPLER_ARG=0.1

Explained

Head sampling decides at the start of the trace, in the SDK. The trace id is hashed and one in ten traces is kept, with all its children following the parent decision. It costs almost nothing and it cannot know whether the request will fail.

Tail sampling decides at the collector, after the trace is complete. A buffer holds the spans for a few seconds, then a policy looks at the whole trace: keep it if it has an error span, keep it if it is slower than the SLO, keep a small percentage of the rest. It costs memory, and it needs every span of a trace to reach the same collector, which is why the collector fleet routes by trace id.

Errors are the policy that pays for itself. Keep every trace with an error, then cap it with a rate-limiting policy during a broad outage so a million failures do not become a million traces.

The honest caveat: tail sampling is stateful and harder to run than a ratio. Start with head sampling at ten per cent and add tail policies when the first incident needs a trace you dropped.

Your turn: Which traces would you regret dropping tomorrow?

More notes: Observability & SRE

Open in the notes app: search, filters, copy This note on GitHub