34 / 67 · 06 Observability-Driven Testing · Distributed Tracing with OpenTelemetry← prev⊞ allnext →☰ Read as one page
5.7Sampling Strategies
In high-traffic systems, collecting every trace is expensive. Choose a sampling strategy:
| Strategy | Description | Pros | Cons |
|---|---|---|---|
| Head-based (probability) | Decide at trace start whether to sample | Simple, predictable cost | May miss rare errors |
| Tail-based | Decide after trace completes, based on outcome | Keeps all errors and slow traces | Higher memory usage in collector |
| Rate-limited | Sample N traces per second | Predictable cost | Misses bursts |
| Always-on for errors | Sample 100% of error traces | Never misses failures | Does not reduce volume of error traces |
Recommendation: Use tail-based sampling with always-on for errors and slow traces. This gives you 100% visibility into problems while keeping costs manageable for successful fast requests.
Distributed tracing is the backbone of observability in microservices. Combined with structured logging and metrics, it provides the complete picture needed for effective production testing.