Compare head-based and tail-based sampling. What does each keep, and what does each cost?
Sketch your own answer first, then compare it with the one below.
A strong answer
Head-based sampling decides at the start of a request, usually with a random draw, and passes the decision along in the trace context. It is cheap and needs no buffering. Because the outcome is not known yet, it keeps slow and failing requests at the same rate as healthy ones, so the stored sample is a fair picture of traffic and a poor picture of problems.
Tail-based sampling decides after the trace is complete. A rule can keep every slow or failed trace and a small baseline of the rest. The cost is that every span of every trace must be held until the decision, and all spans of one trace must reach the same collector to be judged. Storage grows with the share of traces that are interesting, which can be large during an incident.
Either way the stored sample is biased. Compute rates from metrics that see every request, and use traces to explain individual requests.
Sources
- Benjamin H. Sigelman, Luiz André Barroso, Mike Burrows, Pat Stephenson, Manoj Plakal, Donald Beaver, Saul Jaspan, Chandan Shanbhag (2010). Dapper, a Large-Scale Distributed Systems Tracing Infrastructure.
- OpenTelemetry project (2024). Sampling.