Tail sampling
- See who owns an open trace and what happens when the sampler pool changes.
Select a component to trace its direct connections. Drag to pan · Ctrl + wheel or pinch to zoom.
- Trace T contains several spans from one request. A tail sampler holds spans in memory for a decision window, then uses what it has seen to decide whether to keep the trace.
- The routers use the trace ID and the same list of workers to send both T spans to S1. If the worker list changes mid-request, a later span can reach S2 while S1 still holds the earlier ones.
- With a 10-second wait and an error-based policy, an error arriving at S1 after 9 seconds can retain T. At 14 seconds, S1 may already have discarded the earlier spans.
Reading
- Routers A and B can see different spans of the same trace. With stable membership, both route T to sampler S1.
- The alternate lower path illustrates a membership change. Unrelated trace IDs continue to use S2 in normal operation.
Trace affinity and tail decisions
Trace affinity and tail decisions
OpenTelemetry Collector Contrib 0.136.0
Bring related spans to one sampler
- A distributed request can create a parent on one node and children on other nodes. The same trace ID must reach one sampling replica from every router.
- The routing tier uses a consistent hash of traceID over its discovered sampler endpoints. Configure each router with the same membership view. Hashing one shared Service VIP can still let the network choose different replicas.
- The two configuration files belong to different Collector processes. The router connects to individual sampler DNS names with TLS. Supply the trust roots, certificates, keys and private receiver listen address before a deployment.
Select a sampler using the trace IDyaml
# Collector Contrib 0.136.0. One ingress router with same-host senders.
# Each router must discover the same distinct sampler instance endpoints.
receivers:
otlp:
protocols:
grpc:
endpoint: 127.0.0.1:4317
exporters:
loadbalancing:
routing_key: traceID
resolver:
static:
hostnames:
- sampler-a.example.invalid:4317
- sampler-b.example.invalid:4317
protocol:
otlp:
timeout: 5s
tls:
ca_file: /etc/otel/tls/sampler-ca.crt
cert_file: /etc/otel/tls/router.crt
key_file: /etc/otel/tls/router.key
service:
pipelines:
traces:
receivers: [otlp]
exporters: [loadbalancing]
Keep traces containing an error spanyaml
# Collector Contrib 0.136.0. One sampler instance.
# Bind this instance's private interface and install a server certificate
# covering its DNS name. Only approved router clients may connect.
receivers:
otlp:
protocols:
grpc:
endpoint: ${env:OTEL_SAMPLER_LISTEN}
tls:
cert_file: /etc/otel/tls/server.crt
key_file: /etc/otel/tls/server.key
client_ca_file: /etc/otel/tls/router-ca.crt
processors:
tail_sampling:
decision_wait: 10s
num_traces: 5000
expected_new_traces_per_sec: 250
decision_cache:
sampled_cache_size: 10000
non_sampled_cache_size: 10000
policies:
- name: any-error
type: status_code
status_code:
status_codes: [ERROR]
batch: {}
exporters:
otlp/kept:
endpoint: trace-a.example.invalid:4317
service:
pipelines:
traces:
receivers: [otlp]
processors: [tail_sampling, batch]
exporters: [otlp/kept]
Evaluate one incomplete trace
- Suppose a parent reaches S1 at 0 s, a child reaches it at 3 s and an error span reaches it at 9 s. With a 10 s decision window, S1 can see the error before evaluating the trace.
- Now move that error span to 14 s. An earlier drop decision can already be cached. A late error cannot reconstruct discarded spans. Decision tick timing, queue delays and cache retention affect actual results.
- Remove S1 from a router’s membership while the trace is open. Some trace IDs remap. S1 and S2 can each hold fragments and make different decisions. A consistent hash reduces movement across the fleet; moved traces still need a rollout plan.
Choose a sampling boundary
| Choice | State and cost | Where it fits |
|---|---|---|
| Head decision at the SDK | Early decision, little Collector state. Spans discarded before export cannot reach a tail sampler. | Bound producer volume where a probability or parent decision is sufficient. |
| Tail decision with one worker | Buffers spans until policy evaluation; loss of the worker loses its open trace state. | Low volume or a lab that can tolerate the instance boundary. |
| Sharded sampler pool | Supports higher throughput with per-trace ownership. Ring changes, restarts and skew can fragment open traces. | Provision memory for pending traces, large traces and decision caches. Review how the routing layer drains old owners. |
- At 400 new traces/s and a 10 s wait, roughly 4,000 trace identities can be pending across the fleet before burst headroom. Two balanced replicas average 2,000 each. Span count, attributes and skew determine actual bytes.
- The example limits retained traces to 5,000 per replica and sets 250 expected new traces/s as an allocation hint. Finite capacity can evict an older trace before a complete decision.