Why teams need OpenTelemetry tail sampling policies
Trace volume and storage cost tend to rise together, and teams that sample at the SDK with a fixed probability discard traces without looking at what they contain. Head sampling makes the keep-or-drop decision when a trace starts, before anyone knows whether it will fail or run slowly. The result is that rare errors and slow requests are dropped at random, often at the same rate as healthy traffic, which is the data teams most need during an incident.
Tail sampling moves that decision into the Collector and makes it after a trace completes, so the Collector can see the whole trace, including its status codes, latency and attributes, before deciding to keep it. That is the reason teams adopt it: they can keep every error, every request above a latency threshold and traffic from accounts that matter, and sample the remainder. The trade-off is that a tail sampler must hold spans in memory until each trace finishes, so it needs a Collector layout that routes all spans of a trace to the same instance. Confirm the current behavior and configuration keys in the OpenTelemetry Collector documentation before you commit to a design.
OpenTelemetry is not an observability backend. It generates, processes and exports telemetry, and the storage, indexing and query costs of the traces you keep remain with the backend you choose. Tail sampling lowers what reaches that backend, but the savings only materialize if your backend is priced on ingested volume and your sampling policy is tuned against the traffic you actually have. Ask the backend vendor or operator how billing and retention work, and plan to measure accepted and dropped span counts before and after the change.
How spans flow from services to a tail sampling tier
The path starts in the instrumented services, whose SDKs export spans to a first-tier Collector running in load-balancing mode. That tier uses the trace ID to send every span of one trace to the same second-tier sampling Collector, which holds spans until the trace is complete, applies the tail sampling policies, and exports only the kept traces to the backend. Check that the load-balancing tier can see the trace ID on every hop and that the sampling tier is inside the same controlled network boundary.
Spans reach one sampling Collector per trace before any decision is made.
Tail sampling policy types and when each fits
This table compares the main tail sampling policy types, the question each one answers and the trade-off it carries. Read it by starting from what you must never lose, then choose the policy that keeps that data and only then add rules for the remaining traffic. Exact policy names and fields vary by release, so confirm them against the contrib tail sampling processor README for the version you run.
| Policy type | Question it answers | Trade-off | When it fits |
|---|---|---|---|
| Status code | Did the trace contain an error or a specific HTTP or gRPC status? | Simple and cheap to evaluate, but keeps every error, including noisy client errors you may not need. | Always keep server failures and error traces as a baseline rule. |
| Latency | Did the trace take longer than a threshold? | Surfaces slow requests well, but thresholds must be set per route, or fast endpoints and slow batch jobs distort the result. | Keep slow user-facing requests, with separate thresholds for background work. |
| String attribute | Does a span or resource attribute match a value or pattern, such as a route, tenant or customer tier? | Targets business value precisely, but depends on consistent attribute naming and adds rules to maintain as services change. | Keep traces for priority customers, critical routes or specific feature flags. |
| Numeric attribute | Is a numeric attribute inside a range, such as order value or retry count? | Captures high-impact transactions, but only works if the attribute is set reliably by every service in the trace. | Keep large transactions or traces with many retries when those signal risk. |
| Rate limiting | How many traces per second may this policy keep? | Caps storage cost predictably, but under heavy load it can drop interesting traces that arrive after the limit is reached. | Put a ceiling on a broad rule so a traffic spike cannot overwhelm back-end storage. |
| Probabilistic | What fixed share of the remaining traces should be kept? | Easy to reason about and cheap, but it has no awareness of value, so rare failures can be lost. | Sample routine, healthy traffic at a low rate after the explicit keep rules. |
| Composite | Does a trace fit a set of sub-policies with a rate ceiling and ordering? | Expresses layered budgets well, but its configuration is harder to test and review. | Combine a keep rule with a capped share of other traffic in one decision. |
| Combined (AND or OR logic) | Must a trace match several conditions, or any one of them? | Precise targeting, but AND rules can silently keep nothing when attributes are missing. | Keep checkout errors only, or errors and slow traces, once fields are verified. |
Decision wait, memory and trace completeness trade-offs
Tail sampling makes its decision only after a trace has been buffered in memory, so every setting that controls how long the Collector waits also controls how much memory it needs. The cards below cover the levers that connect wait time, buffered volume and decision accuracy, and what to measure before you settle on values.
Decision wait trades latency for completeness
The decision wait is how long the processor holds a trace before deciding whether to keep it. A longer wait gives slow child spans time to arrive, so a trace that finishes late is still judged on its full content. The cost is that every trace sits in memory for that longer period. Check the slowest realistic request in your system, then set the wait with margin above it rather than guessing a round number.
Collector configuration docsMemory grows with buffered span volume
Memory use follows the number of spans held during the decision wait, not the number of traces you eventually keep. High span counts per trace, large attributes and bursts of traffic all raise the footprint. Ask your team to measure Collector memory under a replayed peak load, and set memory limits in the Collector so a surge causes visible pressure instead of an unexplained restart.
Concurrent trace limit caps the buffer
The number of traces held at once is a separate ceiling from the wait time. When that limit is reached, the processor must drop or evict traces, and those losses can fall on exactly the slow or failing requests you wanted to keep. Size the limit against your request rate multiplied by the decision wait, then confirm it with a load test that includes peaks.
Unfinished traces get the wrong decision
If a trace is judged before its last spans arrive, the policy sees an incomplete picture. A trace with a fast root span and a slow downstream call can be dropped because the error or latency shows up after the decision. Spans that arrive late may then appear as orphans or as partial traces. Check this by comparing kept-trace counts against a known error rate, and by inspecting whether kept traces contain their full span trees.
Traffic volume drives the sizing
Buffer requirements scale with traffic, so a configuration tuned for a quiet staging environment can fail in production. Plan separate sizing for normal load, batch jobs and known peak windows, and include the number of services that emit spans into each gateway. Revisit the values after traffic changes, since a new service or a marketing event can move the balance without any change to the configuration.
Why tail sampling needs a two-tier Collector layout
A tail sampling decision is only correct if every span of a trace reaches the same Collector instance. The tail sampling processor holds spans in memory until it has seen enough of a trace to decide whether to keep it, so it can only judge errors, latency and customer attributes for the whole request if all of its spans are present. In practice this means two tiers. The first tier is a set of agents or a load-balancing tier running the load-balancing exporter, which hashes each span by its trace ID and forwards all spans with that ID to one backend gateway. The second tier is the sampling gateway, where the tail_sampling processor runs. Applications and agents should send to the first tier only, never directly to the gateways, so that the routing decision is made in one place.
When routing is wrong, the failure is quiet. If spans from one trace are split across gateways, each gateway sees an incomplete trace, so policies such as error or latency checks may never match and the trace is dropped or kept with missing spans. Errors then look rarer than they are, and the team may only notice when an incident review finds no trace for a failed request. Scaling changes the risk as well: adding or removing gateway instances changes the hash ring, so traces in flight can be sent to a different instance than the one holding their earlier spans. Memory also scales with the number of concurrent traces held for the decision wait, so the gateway count and per-instance memory limits must be sized together, and an undersized tier will drop or evict spans under load.
Before you build, read the load-balancing exporter documentation for the Collector release you plan to run, and confirm how it resolves backends (static list, DNS for a Kubernetes headless service, or another resolver), how it behaves when membership changes, which routing key it uses, and whether it sends spans or traces. Then test the layout with a known error trace and a slow trace, and confirm both arrive complete at the same gateway. Ask your Collector build team to confirm the component stability levels in the component READMEs, as tail sampling and load balancing behavior can differ between versions. The OpenTelemetry Collector documentation is the natural starting point for this check.
Setting up tail sampling policies step by step
This sequence takes tail sampling from an inventory of what must be kept to a tested two-tier Collector layout that keeps errors, slow requests and key customers while sampling the rest. Each step ends with a check so the team knows whether the decision logic does what the business expects.
Inventory signals and business rules to keep
The platform owner and service owners list the traces that must survive sampling: requests that return errors, requests above latency targets agreed with each service team, and traffic from named customers, tenants or regulated flows. For each rule, record the attribute that identifies it (for example, status code, service name, or a customer tenant attribute) and confirm that the SDKs already emit it. Check: every rule has a named owner, an attribute that exists in sampled spans, and a written note on what happens to traces that match no rule. Ask the team to confirm attribute names in a staging environment before writing any policy.
Deploy the two Collector tiers
Choose the Collector distribution and build method for your environment, then deploy the first tier as agents or a load-balancing layer next to applications and the second tier as gateways that run the tail sampling processor. If you build a custom binary, include only the components this design uses, as the OpenTelemetry security guidance recommends building with only needed components through the Collector Builder. Your platform team owns the deployment and the configuration repository. Check: both tiers start, report healthy status, and the gateway tier accepts spans from the first tier in a test environment.
Configure trace-ID routing between tiers
Tail sampling needs every span of a trace to reach the same gateway instance, so the first tier must route by trace ID. Configure the load-balancing exporter on the first tier with the gateway endpoints discovered from your orchestrator, and confirm the resolver refreshes when gateways scale. Keep the gateway tier stateful in mind: a restart or scale event can split traces, so plan for a short period of incomplete traces. Check: sending a test trace with spans from two services yields one complete trace on a single gateway, confirmed in the back end.
Write policies in priority order with a catch-all
Write the tail sampling processor policies in the order your inventory defines, with the most important rules first, such as errors, then latency thresholds, then key customers, then a probabilistic policy for the remainder. Use a final catch-all policy so every trace has a defined outcome. Keep each policy small and named, and document which policy kept each trace so later reviews can explain decisions. Check: a policy review confirms every inventory rule maps to exactly one named policy, and the catch-all is the last entry in the list.
Set decision wait and memory limits
Set the decision wait so that slow traces finish arriving before the gateway decides, using the longest trace duration your services produce as the reference. Set memory limits on the gateway and the number of traces held in memory, then size the gateway pods or instances against those values with load tests. Confirm the values with the Collector documentation for the version you run, since parameter names and defaults are component-specific. Check: under a replayed peak load, the gateway stays within its memory limit, and the dropped-trace counter for memory pressure stays at zero or below an agreed threshold.
Test with synthetic traces
Generate synthetic traces that cover each policy: an error trace, a slow trace above each threshold, a trace tagged with a key customer, a normal trace, and a trace split across two gateway-routed services. Send them through both tiers and check the back end for the expected outcome of each. Record the result for every case in a test log that the security or compliance reviewer can read. Check: every synthetic case produces the expected kept or dropped result, and the split-service trace arrives complete.
Measure kept versus dropped volume
Compare span counts received at the gateway with counts exported to the back end over a representative period, grouped by policy. Pair these numbers with the cost the back end charges for ingested data, which the back end vendor or your own billing data will show. Confirm that error and key-customer traces are kept at the expected rate, since sampling mistakes on these rules matter more than total savings. Check: a report shows kept and dropped volume per policy, and the platform owner signs off that high-value traces are retained before the policy moves to production.
Illustrative policy sets for three common goals
An error-focused policy keeps every trace that contains an error status so that failed requests are always available for investigation. It is usually the first policy to add because it protects the traces that incident responders need most. The fragment below is illustrative: it uses the status_code policy type under the tail_sampling processor.
```yaml # Illustrative fragment, validate against your Collector release processors: tail_sampling: decision_wait: 10s policies:
- name: keep-errors
type: status_code status_code: status_codes: [ERROR] ```
- Error status only: The policy matches spans whose status is ERROR, so it depends on services setting span status correctly.
- HTTP 5xx responses: Some teams also keep traces with server-side HTTP errors, which requires a separate attribute-based policy whose attribute names depend on the instrumentation.
- Decision wait: Errors often appear late in a trace, so
decision_waitmust be long enough for the slowest span to arrive. - Volume check: Error traces can spike during incidents, so confirm the sampled volume stays within the back end budget.
- Ordering: Policies are evaluated together, so an error policy sits alongside the others rather than replacing them.
Check that error spans from your highest-traffic services appear in the back end before you add any probabilistic policy.
A latency-focused policy keeps traces whose total duration crosses a threshold, so slow requests remain visible even when most healthy traffic is sampled out. It answers a different question from the error policy: not whether something failed, but which requests were too slow to meet expectations. The fragment below is illustrative and uses the latency policy type.
```yaml # Illustrative fragment, validate against your Collector release processors: tail_sampling: decision_wait: 10s policies:
- name: keep-slow
type: latency latency: threshold_ms: 2000 ```
- Threshold per route: A single threshold suits one endpoint; set separate policies for endpoints with very different normal durations.
- Trace duration: Latency is measured across the whole trace, so a slow downstream call is captured by the same rule.
- Decision wait: Traces longer than
decision_waitare decided before they finish, which can hide the slowest cases. - Baseline sample: Pair the latency policy with a low probabilistic policy so normal traffic still shows typical behavior.
- Threshold tuning: Pick thresholds from your own duration percentiles in your metrics, and confirm them with service owners.
Compare the traces the latency policy keeps with your dashboards to confirm the threshold matches what your teams consider slow.
A key-customer-focused policy keeps all traces for accounts that carry contractual or support obligations, using an attribute that identifies the tenant or customer. This goal depends heavily on how your applications set attributes, so it needs the most verification. The fragment below is illustrative and uses the string_attribute policy type with a placeholder attribute name.
```yaml # Illustrative fragment, attribute name is a placeholder processors: tail_sampling: decision_wait: 10s policies:
- name: keep-key-customers
type: string_attribute string_attribute: key: customer.tier values: [enterprise] ```
- Attribute source: The attribute must be set on spans by your instrumentation or middleware, and its name depends on how your teams instrumented each service.
- Consistent placement: The attribute must appear on spans in every service the request crosses, or the trace may be decided without it.
- Privacy review: Customer identifiers in telemetry can be regulated data, so confirm with your compliance team which values may be stored.
- Coverage: Confirm that the number of key accounts is small enough that keeping all their traces stays within budget.
- Fallback: Keep a probabilistic policy for everyone else so unlisted customers are still sampled.
Before relying on this policy, send test requests for a key account through each service and confirm the attribute appears in the exported trace.
Securing the sampling tier and the data it sees
A tail sampling tier reads full span content before it decides what to keep, so it holds more sensitive data than a typical forwarding hop. The cards below cover the controls that apply to any Collector, plus the steps that protect attributes before sampling policies run.
Store Collector configuration securely
Tail sampling policies reference service names, customer identifiers and routing logic, so the configuration file is worth protecting. Keep it in version control with restricted access, inject secrets at runtime rather than embedding them in files, and restrict who can change the policy set. Confirm how your deployment tool stores and rotates the credentials the sampling tier uses to reach its exporters.
Collector security practicesAuthenticate receivers with extensions
Traces arriving from application agents and gateway Collectors should not be accepted from anonymous callers. Authenticator extensions can validate incoming connections on receivers, for example with OIDC, and the oauth2client extension can attach credentials to outgoing exporter requests. Confirm which authenticator your receivers support and test that a span from an unauthenticated client is rejected.
Collector configuration docsEncrypt the sampling tier's connections
The first tier forwards load-balanced spans to the second tier, and the second tier sends kept traces to the back end. Enable TLS on each receiver and exporter that crosses a network boundary, and decide whether the internal hop between tiers also needs mutual TLS. Ask your platform team which certificate authority issues these certificates and who renews them.
Keep server ports on localhost
Since v0.110.0, Collector server components bind to localhost by default instead of all interfaces. Keep that default for the sampling tier unless a load balancer or peer tier must reach it, and then bind only to the required interface. Check the effective bind address after each upgrade, because a configuration that sets an explicit address overrides the default.
Redact attributes before policies run
Redaction should run before tail sampling policies evaluate spans, so customer identifiers, tokens and personal data never reach the decision stage or its logs. Use the redaction processor to delete or hash sensitive attribute keys, and list the attributes your policies depend on so they still match after redaction. Test with sample traces that contain known sensitive values.
Build only the components you need
A contrib distribution includes many receivers, processors and exporters that a sampling tier never uses. Use the Collector Builder to produce a binary with only the tail sampling processor, the load-balancing exporter, the required authenticators and the redaction processor. Review the component list in each build and rebuild when you change a policy, so unused code does not stay in production.
Questions teams ask before designing tail sampling
What does it cost to design tail sampling policies?
The cost is mostly engineering time: someone must choose policies, size the Collector tier, test decisions and tune them over time, plus the infrastructure that runs the second tier. The main drivers are how many services emit traces, how many business rules must be encoded, how much trace volume the gateway receives, and whether the work is done in-house or by a partner. Costs are one-time for design and build, and recurring for infrastructure, retuning and support. No supplied figure exists for DeployOpen's fees, so ask for a quote built from a written scope that lists the services, policies, environments and deliverables. Ask the vendor or your own platform team to confirm the compute and memory needed for your trace volume.
How long does a first tail sampling rollout take?
The rollout length depends on how many services feed the gateway, how many policies must be agreed with business owners, and how much of the platform already exists. Teams that already run a gateway Collector with traces flowing into it usually spend less time than teams starting the two-tier layout from nothing. Time also goes to load testing, confirming that kept traces are complete, and staged rollout by service. No supplied duration applies to your environment, so ask any partner for a timeline in the written scope with milestones for policy design, a test environment, a staged production cutover and a review period.
What must our team provide before the design work starts?
Three inputs make the design workable. First, representative trace samples from each important service, including slow requests and errors, so policy thresholds reflect real latency and failure patterns. Second, written business rules: which customers, tenants, routes or transaction types must always be kept, and who approves changes. Third, platform access: a test cluster or staging environment, read access to current telemetry backends, permission to deploy Collector configuration, and a named owner for the gateway tier. Ask the partner to list these inputs in the scope so gaps are visible before the build begins.
Can our own team design tail sampling policies without a partner?
Yes, if your team already operates the OpenTelemetry Collector and understands its processors and deployment patterns. The Collector is Apache-2.0 licensed and its releases ship with signed artifacts, SHA256 checksums and SBOM files, so an in-house team can build and verify it. The harder parts are policy design, memory sizing for the decision wait window, and load testing under failure. Consider a partner when no one has run a gateway tier, when regulated data must stay out of telemetry, or when deadlines are tight. Confirm the component stability levels in the Collector documentation before you rely on a policy type in production.
How do head sampling and tail sampling work together?
Head sampling decides at the start of a trace, inside the SDK, whether to record it, which is cheap but cannot know whether a request will fail or run slowly. Tail sampling waits until the spans of a trace have arrived at the Collector, then decides based on errors, latency and attributes. A common layout keeps a modest head sampling rate to limit what leaves the application, then applies tail policies at the gateway. Because tail sampling needs all spans of a trace in one place, traces must be routed to the same gateway instance, usually with a load-balancing tier in front. Verify the chosen pattern against the current Collector configuration documentation.
How do we verify that the traces we keep are complete and correct?
Verification has three parts. Send known test traffic that covers each policy, such as an injected error, a slow request and a request from a priority customer, and confirm each appears at the backend with all spans. Compare kept trace counts against unsampled counts from the Collector's own metrics to check that the decision wait is long enough, since late spans that arrive after a decision are lost. Finally, check that sensitive attributes were removed before storage, using the redaction processor described in the Collector security guidance. Record these checks as a test plan so the same tests run after each configuration change.
What does ongoing tuning of tail sampling policies require?
Policies drift as services change, traffic grows and business priorities move, so tuning is a recurring task. Someone must review sampling rates and kept-trace volumes each release, update latency thresholds when baselines shift, and add or retire customer rules through a change process. Each Collector upgrade needs a test run because component stability levels differ and configuration keys can change. Ask any partner whether the ongoing scope includes tuning, upgrades and continuous checks, and whether it is offered as a retainer or as separate work items with their own quotes.
How DeployOpen scopes and delivers tail sampling work
Tail sampling work starts with a written scope agreed before any configuration changes. For this topic, that scope usually names the policies to build (errors, latency thresholds, named customer or tenant attributes, and a baseline probabilistic policy for everything else), the Collector tiers that will run them, the telemetry sources that feed the gateway, the back ends that receive kept traces, and the test evidence that proves the decision wait and memory settings hold under your real traffic. Most engagements are fixed-scope, so deliverables and timelines are set in that document rather than discovered during the build. Ask for the scope to list each policy by name, the trace load it was sized against, and which decisions remain with your team after handover.
Implementation happens inside your infrastructure, in your cloud accounts, data centers or air-gapped network. DeployOpen works with the Collector configuration, the load balancing layer that routes all spans of a trace to the same gateway instance, and the monitoring you need to see dropped spans and memory pressure. Configuration is stored in your version control and deployed through your change process, and secrets for exporters are handled through your existing secrets tooling. Ask who holds administrative access to the gateway tier during and after the engagement, and how changes to policy thresholds will be reviewed once the work is finished.
Each engagement ends with documentation and handover: the policy catalog with the reason for each rule, sizing notes, a runbook for changing thresholds safely, and the test results. Optional retainers cover Collector upgrades, policy tuning as traffic patterns change, and periodic checks of sampling accuracy. DeployOpen does not publish a price list, so a quote follows from the written scope. To compare proposals, ask each provider to itemize scope, deliverables, handover material and any retainer terms, and confirm what the quote excludes, such as additional back-end storage or application instrumentation work.

