Course contentsShow
← Cloud and Infrastructure
Lesson 2098 of 2,98944. Observability - TracingFree lesson

Tail-Based Sampling

Intelligent sampling decisions after trace completion: reducing storage while keeping error traces.

Tail-Based Sampling

What you'll learn: How to make intelligent sampling decisions after seeing the complete trace, ensuring you keep important data while dramatically reducing storage costs.

The Core Idea

So far, you've learned about sampling strategies that make decisions at the start of a trace (head-based sampling). But what if a trace looks normal at first, then encounters an error three services deep? Head-based sampling might discard it before the error even happens.

Tail-based sampling flips this approach: it collects all spans for a trace, waits for the trace to complete, then decides whether to keep or discard it based on the full picture. This lets you apply intelligent rules like "keep all traces with errors," "keep traces slower than 2 seconds," or "keep 1% of successful fast traces as samples."

Why It Matters

Think of it like reviewing security camera footage: instead of deciding what to record before anything happens (head-based), you record everything temporarily, review it, then only save the important incidents (tail-based).

This approach ensures you never lose critical error traces while still controlling storage costs. You might keep 100% of errors but only 1% of successful requests, giving you complete visibility into problems without drowning in routine data.

The Trade-off

The catch? All spans must be buffered temporarily (usually in memory or short-term storage) until the trace completes, which adds latency and resource overhead. Your tracing backend must also support assembling complete traces before making sampling decisions—not all backends do this natively, which is why you learned about backend storage and query performance first.

Key Takeaway: Tail-based sampling makes retention decisions after trace completion, letting you keep all error traces and interesting patterns while sampling routine requests—maximizing signal and minimizing storage.