Head vs tail sampling: where OpenTelemetry should decide what to keep
If trace volume and back-end cost are rising, you have to decide where sampling happens: inside the application SDKs, in the OpenTelemetry Collector, or in both places. Head sampling makes the keep-or-drop decision when a trace starts, before the rest of the request is known, so it is cheap and simple but cannot see whether the request later failed or ran slowly. Tail sampling waits until a trace is complete and decides on its contents, which lets you keep errors and slow requests, but it needs a Collector tier that can hold traces in memory while the decision is pending.
It helps to be precise about the components. OpenTelemetry is an observability framework and toolkit for generating, exporting and collecting traces, metrics and logs. It is not an observability backend, so storage, query and visualization remain separate products that you choose and pay for. Sampling decisions can be made in the language SDKs, where a sampler is set in application code or configuration, or in the Collector, which is a vendor-agnostic service that receives, processes and exports telemetry and can run as an agent beside services or as a gateway for many sources. Trace APIs and SDKs are stable in most languages, so SDK-side sampling is usually the first control to check, while Collector-side tail sampling depends on which components your chosen Collector distribution includes and their stability levels, which you should confirm in each component's README.
Use SDK head sampling when you need a simple, predictable cut in volume and can accept losing some rare failures. Add tail sampling when you must keep every error or slow trace and the cost of dropping them is unacceptable. Many teams run both: a head sampler in the SDK limits what leaves the service, and a gateway tail sampler applies policies to what remains. Before you choose, ask your team to confirm the sampler types in your SDK versions, the memory and decision-wait settings the gateway will need, and whether all spans of one trace reach the same Collector instance. Those three answers determine the effort and the operational risk of each option.
How a sampling decision flows from SDK to back end
The trace starts in the application SDK, where a head sampler decides up front whether to record a trace, so unsampled spans never leave the process. Sampled spans go to an agent Collector beside the service, then to a gateway Collector, where the tail sampling processor holds all spans for a trace in a decision wait buffer until it has seen the whole trace. Spans that no policy keeps are dropped at that gateway, and only the kept spans reach the back end. Check that every span of a trace reaches the same gateway instance, because the buffer can only decide on complete traces it has seen.
Head sampling happens in the SDK, tail sampling in the gateway Collector after a wait buffer.
How head sampling decides at the root span
Probability sampling in an OpenTelemetry SDK makes its keep-or-drop decision when the root span starts. The sampler, configured in the application's tracer provider, evaluates the request once, records the outcome in the trace flags of the trace context, and every downstream service that honors that context follows the same decision. Because the verdict is made up front, nothing has to be held in memory while the request runs, and no component waits for the trace to finish. The sampling rate is set in the SDK configuration of each service, so the decision is only as consistent as the configuration you deploy across services that call each other.
The trade-off follows directly from timing. At the root span, the sampler knows the route, the headers and the parent sampling decision, but it cannot know that a downstream database call will fail, that a payment service will time out or that the response will take several seconds. A trace that turns out to be an error is discarded with the same probability as a healthy one, so the traces you most need for incident review are often the ones that were never recorded. Before you commit to head sampling, ask your team to list the failures they investigate most often and confirm, in a test environment, which of those traces would survive a given rate.
The Collector's probabilistic sampler applies a similar percentage-based decision after spans have left the SDK, and it is covered on its own sibling page. For this section, the point is that a fixed probability is a cheap, stateless control that works well for volume reduction but cannot, by itself, protect error or slow traces. Teams that need that protection usually plan a second decision point, which is the subject of the tail sampling sections that follow.
Which sampling placement fits which situation
This table compares head sampling in SDKs, tail sampling in a gateway Collector, and a combined layout across infrastructure, engineering effort, error and latency visibility, consistency and operational risk. Read each row as the driver that should decide placement for your environment, then check the combined column first if you already run both tiers.
| Factor | Head sampling in SDKs | Tail sampling in a gateway Collector | Both combined |
|---|---|---|---|
| Infrastructure needs | Little beyond the application runtime, since the decision happens inside each service before export | A gateway tier that receives every span of a trace, sized for memory held while decisions wait | Two tiers: SDK sampling at the edge plus a gateway tier that holds the remaining spans |
| Engineering effort | Set a sampler and ratio per service, which is quick but needs agreement across teams on rates | Write policies for errors, latency and key customers, then tune decision wait and buffer size over time | Highest, because both sampling layers need configuration, testing and ownership |
| Error and latency visibility | Errors and slow requests can be dropped because the outcome is unknown when the decision is made | Keeps traces with errors or high latency, provided all spans of the trace reach the same gateway instance | Keeps the pre-sampled traffic at the edge, so visibility of rare failures depends on the SDK rate chosen |
| Consistency across services | Works only if parent sampling decisions propagate, so mismatched rates across services can break traces | Decisions are made on complete traces, so every service in a trace is kept or dropped together | Consistency depends on the edge rate; tail decisions only see spans that survived the first layer |
| Operational risk | Low moving parts, but a misconfigured ratio can silently remove the traces you later need | A gateway outage or uneven routing can lose data, and memory pressure can drop spans before decisions | Compounded risk: failures in either tier are harder to attribute and must be monitored separately |
| Best fit | Services with steady, low-risk traffic and a clear acceptable loss | Teams that need errors and slow traces kept reliably and can operate a stateful gateway | Large estates where edge volume must drop sharply before a gateway can handle the rest |
Layouts for running head and tail sampling together
In this layout, applications send all traces straight to one Collector gateway, and that gateway runs tail sampling as the only sampling decision. Every span for a trace reaches the same instance, so the tail sampling processor can evaluate a complete trace before deciding whether to keep it. This is the simplest layout to operate because there is one tier to deploy, configure and monitor. Illustrative example: a small team with a few services sends everything to one gateway, which keeps error traces and drops most successful requests.
- Components: one gateway running the Collector with a tail sampling processor and an OTLP receiver, plus an exporter to the chosen back end.
- Platform team needs: enough memory to hold traces for the decision wait period, a load balancer or DNS name that all services can reach, and monitoring of the gateway itself.
- Scaling limit: a single instance is a single point of failure and a memory ceiling, so growth usually forces the two-tier layout.
- Cannot see: traffic sent to other gateways or any spans dropped by SDK sampling before they reach this instance.
- Stability: core Collector components have mixed stability levels, so confirm the status of the tail sampling processor in its README before you commit.
Confirm the gateway's memory sizing and decision wait settings in a test environment with production-like trace shapes.
This layout applies probability sampling in the SDK, so the application decides up front which traces are recorded. Agents run next to workloads and forward data to a central gateway, which runs tail sampling on the traces that survived head sampling. Head sampling cuts the volume reaching the network, while tail sampling still makes outcome-based decisions for the traces it receives. The trade-off is that a trace dropped at the SDK can never be recovered as an error later.
- Components: SDK samplers in each service, agents as a local receiver and forwarder, and a gateway with tail sampling and an exporter.
- Platform team needs: a routing rule that keeps all spans of one trace on the same gateway instance, usually through a load-balancing exporter keyed on trace ID, plus a consistent sampler configuration across services.
- Application team needs: agreed sampler settings and a shared way to propagate the sampling decision in trace context.
- Cannot see: errors and slow requests that SDK sampling discarded, so the gateway's keep rules only apply to the sampled subset.
- Check: the sampling settings in each language SDK, since trace APIs and SDKs differ in maturity across languages.
Test the layout by comparing error counts from the SDK-sampled stream with those from an unsampled reference service.
On Kubernetes, the agent and gateway tiers are usually deployed as separate workloads, often with the Collector Operator or Helm charts. Agents run as a DaemonSet so each node has a local receiver, and a gateway Deployment handles tail sampling. Autoscaling the gateway is a common need, but scaling changes which instance holds a trace, so the trace-ID routing tier must scale with it. Kubernetes also adds metadata that can be used in sampling rules, such as namespace or workload labels.
- Components: a DaemonSet of agents, a gateway Deployment, a trace-aware load-balancing layer and a Kubernetes service for the gateway.
- Platform team needs: RBAC and service accounts for the Collector, resource requests sized for the gateway, and a plan for rolling updates that does not split in-flight traces.
- Operations needs: alerts for gateway restarts and memory pressure, since a restarted gateway loses traces still waiting for a decision.
- Cannot see: traces that cross clusters unless a multi-cluster gateway forwards them to a shared tail sampling tier.
- Check: the Operator and chart versions, plus the stability notes in each Collector component README for the processors used.
Confirm the autoscaling and rollout behavior in a staging cluster before enabling it in production.
How to roll out sampling without losing the traces you need
This sequence moves sampling from an inventory of current trace volume to a two-tier Collector layout with tail policies, so errors and slow requests stay visible while volume drops. Each step ends with a check that tells you whether to move on.
Inventory trace volume and critical services
Your platform team, with service owners, measures current trace volume per service and environment, and lists the services where missing traces would hurt most, such as payments, login and customer-facing APIs. Record which errors and latency thresholds matter to each owner. Done when you have a ranked table of services with volume, owner and the questions their traces must answer. Confirm the volume figures from your own back-end billing or usage reports, not from estimates.
Set SDK sampler configuration in non-production
Engineers configure the head sampler in the SDK or instrumentation layer for a non-production environment first, choosing a parent-based probability sampler and keeping the rate explicit in configuration. Confirm the sampler names and options in the OpenTelemetry documentation for each language your teams use, since support varies by SDK. Done when test services emit the expected share of traces and downstream spans respect the parent decision.
Deploy a load-balanced tier routing by trace ID
The platform team deploys a first-tier Collector set that receives spans from applications and forwards them through a load-balancing exporter keyed on trace ID, so every span of a trace reaches the same second-tier instance. Confirm that the trace ID routing works across all replicas and that no trace is split across instances. Done when a sample trace shows all of its spans arriving at one second-tier Collector in your logs or debug output.
Enable tail policies in shadow mode
The second-tier Collectors run tail sampling policies for errors, slow requests and critical services, but first in a mode that evaluates decisions and records them without dropping data from the production path, or on one service subset. Platform engineers review which policies would match and at what rate. Done when the decision counts per policy match the expectations from step one and no policy keeps far more than planned.
Verify kept and dropped traces with owners
Service owners review a set of kept and dropped traces for their services, checking that failed requests, slow requests and traces for critical customers are present and complete, and that the dropped traces are the ones they accept losing. Platform engineers check decision wait time against the slowest trace shape in each service so late spans are not missed. Done when each owner signs off on a sample and the missing-span rate for kept traces is within the tolerance you agreed in step one.
Watch Collector resources before promotion
Before promoting the policies, the platform team watches memory use, queue behavior and dropped-span counts on the second-tier Collectors under normal and peak load, using the Collector's own telemetry. Confirm that the Collector is not dropping data for memory reasons and that the chosen decision wait and buffer sizes hold at peak traffic. Done when the Collector runs through a peak period without data loss or restarts that you cannot explain.
Promote policies and document the fallback
The platform team switches the tail policies from shadow mode to enforced mode for the agreed services, then writes down the policy set, the owners of each rule, the head sampling rate and a fallback that restores full capture for a named service. Done when the policies are live, the runbook is in version control, and each owner confirms that their alerting still fires from the kept traces.
Security and operations of sampling pipelines
Sampling decisions move telemetry through more Collector tiers, buffers and back ends, and each hop adds configuration, credentials and failure modes. The cards below cover the security controls and operating risks that come with head sampling, tail sampling or both, so the team can size them before the layout is chosen.
Protect Collector configuration at rest
Sampling policies, exporter endpoints and credentials all live in Collector configuration, so that file is a sensitive asset. Store it in a secrets-aware location, restrict who can read or edit it, and keep it encrypted at rest. Review every change to tail policies, since an edit that drops error traces is a data loss event that no alert may catch.
Collector security practicesAuthenticate receivers and exporters
Authenticator extensions check incoming connections on receivers, for example with OIDC, and add credentials to outgoing exporter requests, such as through the oauth2client extension. In a two-tier layout, apply this on the link between SDKs and the first tier and again between tiers, so a rogue sender cannot flood the tail sampler or read traces from the gateway.
Collector configuration docsBuild minimal Collector distributions
Use the Collector Builder to include only the receivers, processors and exporters your sampling design needs. A smaller binary has less code to patch and fewer components that can be misconfigured. Confirm that the tail sampling and load-balancing components you depend on are in your build, and that their stability level is acceptable for production, since stability varies by component.
Keep server ports on localhost by default
Since v0.110.0, Collector server components bind to localhost rather than all interfaces by default. Upgrading past that version does not expose a tier you intended to keep private, but any explicit bind address you set in an older config still applies. Check each receiver endpoint, especially the gateway tier that load-balancing sampling depends on, and confirm it binds only where the sending services can reach it.
Redact data before the back end
Span attributes often carry user identifiers, tokens or query strings that should never reach storage. Use the redaction processor early in the pipeline, before the tail sampler stores spans, so sensitive values are removed from buffered traces as well as exported ones. Test redaction with real-looking sample traces, because a rule that misses one attribute leaves the data exposed in every tier.
Plan for buffer memory and restarts
Tail sampling holds spans in memory until the decision wait ends, so traffic spikes and large traces raise memory use quickly. Set memory limits and watch Collector memory during load tests. When a gateway tier restarts, spans still buffered for in-flight traces can be lost, which means error traces may disappear. Ask how spans are routed by trace ID during restarts and whether the design accepts that loss window.
Questions teams ask before choosing a sampling approach
How much effort does head sampling take compared with tail sampling?
Head sampling takes less effort because the decision is made in the SDK at the start of a trace, and the setup is mostly a sampler choice and a ratio per service. Tail sampling takes more effort because the decision waits until a trace is complete, so it needs a Collector tier that groups spans by trace ID, memory sized for the decision wait window, and policies written for errors, latency and important customers. The main drivers are the number of services, the trace volume per service, the number of policies, and how many clusters or regions send data to one tail sampling tier. Ask any partner to show the effort split between SDK changes, Collector work and testing.
Can our own engineers build and run sampling in-house?
Often yes, if your team already runs the OpenTelemetry Collector and has owners for both application instrumentation and the telemetry backend. Head sampling is usually a configuration change that application teams can make themselves. Tail sampling needs someone who understands load balancing by trace ID, Collector memory behavior, and how dropped or incomplete traces show up in your dashboards. Decide who owns the policies, who reviews changes, and who watches the Collector during peak traffic. If those owners do not exist yet, a fixed-scope engagement can design and document the setup so your team can operate it afterward.
What does the work need from our team?
Plan for time from people who know the services and the business rules that define an important trace. Expect requests for service owners who can name the endpoints and customer segments that must always be kept, platform engineers who can provide Collector hosts and network paths, and a security or compliance reviewer if trace attributes may contain regulated data. You will also need a non-production environment with realistic traffic so sampling rates and policy effects can be measured before rollout. Confirm these access needs and named contacts in the written scope.
How long should we plan for a sampling project?
Timing depends on scope and environment, so treat any number as something to confirm in writing rather than a fixed estimate. The factors that most often lengthen the work are the number of services that need SDK changes, whether the Collector already runs in a gateway pattern, how many policies must be validated, and how quickly change approvals move in your organization. Ask for a phased plan that separates design, a non-production rollout, measurement of kept and dropped data, and production rollout, with the dependencies for each phase listed.
Do head and tail sampling conflict with each other?
They do not conflict if the roles are clear, but combining them without a plan can distort results. A head sampler in the SDK drops a share of traces before they reach the Collector, so the tail sampler only sees what survived that decision. Errors and slow requests dropped at the head cannot be recovered later. Many teams use a modest head ratio to limit volume at the source and rely on tail policies for the traces they must keep, or they keep the SDK at full recording and let the tail tier decide. Document which tier makes the final decision for each trace type, and test that policies still see the traces you expect.
What should a quote for sampling work include?
A quote should follow from a written scope and list the work as separate lines so you can compare options. Ask for the services and environments in scope, the sampling tiers to be built (SDK, gateway Collector, or both), the policies to be designed and tested, the load balancing and memory sizing approach, the validation method for kept and dropped traces, the documentation and handover, and any post-rollout tuning. Also ask which items are one-time and which are recurring, such as ongoing support or policy changes, and what assumptions about your infrastructure and access are built in. You can review the outcome with OpenTelemetry Collector documentation when checking how each component is described.
Does sampling affect security or compliance evidence?
It can. Sampling decides which traces remain for investigation, so a policy that drops too many error or access-related traces can weaken incident response and audit trails. Confirm with your security and compliance owners which events must be retained, for how long, and whether sampled-out data still needs to be counted in metrics. Trace attributes that carry personal or regulated data should be removed before data leaves the Collector, and the Collector configuration should be stored and access-controlled like other sensitive infrastructure code.
What to ask a partner before committing to a design
Start with the question that decides whether tail sampling is needed at all: which services actually require it. Ask the partner to name the services where a head decision would lose the traces you care about, such as checkout paths, payment calls or upstream dependencies that fail intermittently, and to justify each one. A partner who proposes tail sampling for every service without a list of services and the errors or latency thresholds they would protect has not yet scoped the work. Ask for the list to be written into the statement of work so it can be checked after go-live.
Next, ask where the Collector tier runs and how it is sized. Tail sampling in the Collector needs all spans of a trace to reach the same instance, so the partner should explain how spans are routed by trace ID to a tier of gateway Collectors, how that tier is scaled, and what happens to memory when a traffic spike arrives. Ask which Collector components hold traces while the decision wait runs, how the decision wait is set, and what the partner will do if spans arrive after a decision has been made. Confirm the stability level of each component in use against the OpenTelemetry status page, since components carry mixed stability levels.
Finally, ask how the partner will keep dashboards accurate and what evidence you receive. Sampled traces alone will undercount request rates and error counts, so ask whether metrics are derived from all spans before sampling, and how the two sources will be reconciled on a dashboard. Require a written rollout record: the sampling configuration as deployed, a test showing that seeded error and slow traces are kept, measured trace volume before and after, and a rollback procedure. Ask for each of these to be delivered before acceptance, so your team can review them without the partner in the room.
How DeployOpen scopes and delivers sampling work
The sequence below takes a sampling decision from a written scope to a verified, supported Collector and SDK configuration inside your own infrastructure. Each step ends with a check you can review before the next one begins.
Agree the scope and telemetry inventory in writing
Before any configuration changes, DeployOpen and your team list the services, languages, trace volumes, back ends and the traces that must never be lost, such as errors and requests tied to regulated transactions. The written scope names which sampling layers are in scope (SDK probabilistic sampling, Collector tail sampling, or both), what is deliverable, and what is excluded. The check is a signed scope document that both sides can point to when a question about dropped data comes up later.
Confirm infrastructure and Collector topology
DeployOpen reviews where Collectors can run in your environment, whether as agents beside services or as gateways, and whether tail sampling can route all spans of a trace to the same Collector instance. It also confirms memory and network limits, the Collector distribution and version you will standardize on, and how the Collector will be built and stored under your security policies. The output is a topology diagram and a list of open questions for your platform team, which must be answered before the configuration is written.
Define sampling policies and their baseline
Working from the agreed inventory, DeployOpen drafts the head sampling rate in each SDK and the tail sampling policies in the gateway, such as keeping errors and slow requests while sampling the remainder. Your team reviews which attributes the policies depend on and whether any of them carry sensitive data that should be scrubbed first. The check is an approved policy file and a record of the baseline trace volume and back-end cost measured before any change.
Implement SDK and Collector configuration in your environment
DeployOpen makes the configuration changes in your cloud accounts, data centers or air-gapped networks, using your change control and version control process. Configuration keys, secrets and Collector settings are stored according to your standards, and server components are kept on the bindings and authentication your security team requires. The check is a configuration change set reviewed and merged by your team, deployed to a non-production environment first.
Verify kept and dropped traces
DeployOpen runs test traffic that includes healthy requests, errors, slow requests and traffic for high-value customers, then checks which traces reach the back end and which are dropped. It confirms that all spans of a kept trace arrive, that metrics derived from spans remain accurate where they are used, and that the Collector stays within its memory limits under load. The output is a verification report listing each policy, the test result and any gaps, with the fixes applied and retested.
Hand over runbooks and documentation
DeployOpen documents the final sampling design, the reasons for each policy, the dashboards that show the Collector's own health and the steps for adjusting rates. Your operators are trained on how to find dropped data and how to change a policy through review. The check is a handover package accepted by your platform owner, with the design rationale recorded so that auditors and future engineers can see why traces were sampled as they were.
Operate and retest through a retainer
Sampling needs change as services, traffic patterns and Collector releases change. Ongoing support, upgrades and continuous testing are available as a retainer, where DeployOpen reviews policy effects, retests after Collector upgrades and updates the design when the inventory changes. The check is a recurring review record that shows which policies were changed, why, and what the verification showed. Retainer scope and terms are agreed in writing separately from the initial fixed-scope engagement.

