Prompt
Need tail-based sampling for distributed traces
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
Tail-based sampling for distributed traces means deciding which traces to keep after the trace is complete, instead of deciding upfront on the first span.
Why use it
Tail sampling is useful when you want to keep:
- slow traces
- error traces
- rare/important requests
- traces matching certain attributes, services, or routes
It’s better than head-based sampling when you need to make decisions using the full trace.
Common options
OpenTelemetry Collector
The most common way is to use the OpenTelemetry Collector with the tail_sampling processor.
Example idea:
- applications send traces to the collector
- collector buffers spans until a trace finishes or a timeout occurs
- collector applies policies
- only selected traces are exported
Typical policies
status_code: keep error traceslatency: keep traces slower than X msprobabilistic: keep a percentagestring_attribute: keep traces with certain attributesspan_count: keep traces with many spans
Example OpenTelemetry Collector config
receivers:
otlp:
protocols:
grpc:
http:
processors:
batch:
tail_sampling:
decision_wait: 10s
num_traces: 50000
expected_new_traces_per_sec: 1000
policies:
- name: errors
type: status_code
status_code:
status_codes: [ERROR]
- name: slow-traces
type: latency
latency:
threshold_ms: 2000
- name: keep-some
type: probabilistic
probabilistic:
sampling_percentage: 10
exporters:
otlp:
endpoint: your-backend:4317
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
processors: [tail_sampling, batch]
exporters: [otlp]
Important considerations
- Memory usage: the collector must store traces temporarily
- Latency: export is delayed until sampling decision is made
- Scaling: tail sampling is harder in multi-instance collectors unless traces are routed consistently
- Timeout tuning:
decision_waitmust be long enough for late spans but not too long
Best practices
- Use head sampling at the SDK for coarse reduction if traffic is huge
- Use tail sampling in the collector to preserve important traces
- Start with simple policies:
- errors
- slow traces
- small probabilistic baseline
- Monitor collector memory and dropped traces
If you want, I can give you:
- a production-ready OpenTelemetry Collector tail sampling config, or
- setup examples for Kubernetes / AWS / GCP / Datadog / Jaeger.