Prompt
I’m building an observability stack and need tail-based sampling
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
Tail-based sampling is a good fit when you want to decide whether to keep a trace after seeing how it ended, instead of deciding up front at the start of the trace.
Here’s the practical picture:
What it is
- Head-based sampling: decide at span/trace start.
- Tail-based sampling: ingest spans first, then sample based on:
- latency
- errors
- specific endpoints
- tenant/customer
- trace attributes
- service names
Why use it
- Keep slow/error traces with high fidelity
- Drop routine “healthy” traces
- Better signal-to-noise for debugging
- Useful for distributed systems where the “interesting” part is only visible at the end
Common architecture
You typically need a stateful collector or dedicated sampling component:
- Services send spans to an OpenTelemetry Collector
- Collector buffers spans by trace ID
- Once a trace is complete or a timeout is reached, sampler evaluates rules
- It exports kept traces and discards the rest
Key tradeoffs
-
Pros
- Better selection quality
- Can sample based on outcome
- Great for errors/latency SLO investigations
-
Cons
- Needs buffering/state
- Higher memory and operational complexity
- Adds latency to trace export
- Must handle partial traces and timeouts carefully
OpenTelemetry approach
If you’re using OpenTelemetry, tail sampling is usually done in the OpenTelemetry Collector Contrib with the tail_sampling processor.
Typical pattern:
- receivers: OTLP
- processors:
- memory_limiter
- batch
- tail_sampling
- exporters: your backend
Example use cases/rules
- Sample 100% of traces with status = error
- Sample 20% of traces for checkout service
- Sample traces with duration > 2s
- Sample traces containing
http.route=/pay - Keep all traces for premium customers
Design considerations
- Trace completeness timeout: how long to wait before deciding
- Decision cache: avoid re-evaluating
- Reservoir size / memory limits: prevent OOM
- Policy ordering: errors before probabilistic rules
- Sharding: ensure spans from the same trace go to the same sampler instance
- Backpressure: avoid overwhelming your pipeline
A simple recommended starting point
If you want a balanced production setup:
- keep all error traces
- keep all traces slower than a threshold
- sample 5–10% of normal traffic
- centralize sampling in OTel Collector
- monitor collector memory and dropped spans
If you want, I can help you with any of these next:
- a concrete OpenTelemetry Collector tail-sampling config
- a reference architecture for Kubernetes
- sampling policy design for SLOs/errors/latency
- choosing between tail vs head sampling for your stack