Observability / Advanced: bias, trust, and evidence engineering / Lesson 21
Tail sampling, routing, and capacity
Design tail-sampling decisions, routing and capacity limits, and interpretation of selected traces.
On this page
Lesson goals
- Connect sampling decisions to span routing and collector capacity.
- Test loss and delay and interpret selection bias.
Define the sampling decision
Tail sampling decides whether to retain a trace using information from all or most spans available for that trace. This can support policies based on errors or duration that are not known when the first span begins. Define the operational question, selection policy, expected volume, and owner before enabling it. A selected trace population is biased by that policy and cannot automatically be treated as all requests.
Route related spans consistently
A distributed sampling tier needs the spans for a trace to reach the decision point that can evaluate them together. Routing by trace identity is one approach; topology changes, retries, or inconsistent routing can still affect completeness. The synthetic sketch shows the intended relationship, not a deployed collector configuration. Document the actual collector version and routing contract, and test changes to replica membership in a disposable environment.
trace A spans -> trace-aware routing -> sampler 1
trace B spans -> trace-aware routing -> sampler 2
The sketch illustrates collecting related spans; it is not deployable configuration.
Budget memory and delay
A decision point must retain enough trace information for its policy, which consumes memory and introduces a decision delay. Late spans, unusually long traces, overload, and collector restarts can affect the available evidence. Define capacity, decision window, loss indicators, and backpressure behavior for the chosen implementation. Avoid promising that every error trace is complete merely because a policy intends to retain errors.
Interpret selected traces
A tail-sampled dataset can overrepresent errors or slow requests by design. Use a suitable metric over the intended request population for aggregate rates and use traces to investigate selected examples. The example record identifies policy and selection, not an unbiased denominator. Document any earlier head sampling, because spans dropped before the tail decision cannot be recovered by a later policy. Protect trace attributes and access.
policy: retain selected errors and slow traces
population: selected traces, not all requests
aggregate error rate: use an appropriate full-population metric
The record shows selection bias and the need for an appropriate rate denominator.
Exercise routing and loss
In an isolated lab, generate synthetic traces with known success, error, and duration cases, including a delayed span and a collector restart. Verify routing, retained relationships, decision timing, loss indicators, and backend visibility against the documented contract. Repeat under bounded load and after a routing change. Record unsupported cases and uncertainty; a passing sample does not establish complete coverage under every production failure.
Common errors and fixes
Randomly distributing related spans without a contract
- Why it happens
- The decision point may not see related spans together.
- How to fix it
- Inspect routing and completeness in the lab.
- Prevent it next time
- Test routing when replicas change.
Calculating error rate from error-selected traces
- Why it happens
- The population is biased by the policy.
- How to fix it
- Use a suitable metric for the request population.
- Prevent it next time
- Document selection and denominator.
Assuming early-dropped spans can be recovered
- Why it happens
- Head sampling occurred before the tail decision.
- How to fix it
- Inspect the earlier collection policy and coverage limits.
- Prevent it next time
- Design and test interacting policies together.
2 practice exercises
1. The policy retained most error traces. Is their fraction the service error rate?
Show worked solution
No. The population is selected. Use a metric with an appropriate all-request denominator and compare its limits.
2. A traceโs spans arrive at different collectors. What can happen?
Show worked solution
The decision point may lack sufficient information. Inspect trace-aware routing, implementation behavior, and replicas in the lab.
Key takeaways
- A decision needs documented routing, capacity, and window.
- Selected traces do not automatically represent all requests.