AutoMerge is generally available

  • 12 min read

Tail Sampling Traces on the Edge: Keep Every Error, Pay for 1% of the Rest

Probabilistic sampling at 10% keeps 10 traces and none of the 3 error or 3 slow traces. Tail sampling keeps 7 traces, including every error and slow trace.

Ask a team how they sample their traces and you will usually hear one number: "we keep 10%". Ask which 10% and the room goes quiet. Most of the time the honest answer is "a random 10%", and a random 10% has a habit of not including the one trace you need at 3 a.m.

This post covers the concepts behind sampling, what probabilistic sampling is good at, where it lets you down, and how tail sampling on the Dash0 edge collector keeps every error and every slow trace while you pay for a small fraction of the rest.

Why sample at all

Most requests in a healthy system look the same. The thousandth successful GET /products tells you nothing the first nine hundred and ninety-nine didn't. You still pay to ship, store, and index every one of them.

The OpenTelemetry sampling concepts put the goal in one sentence: you don't need 100% of your traces, you need the right sampling. The idea that makes this work is representativeness: a smaller group can accurately stand in for a larger one. The more traffic you have, the smaller that group can be. At high volume, 1% or less can represent the other 99%.

Two terms are worth getting right, because they get mixed up constantly:

  • Sampled: The trace or span is processed and exported. It is the one you keep.
  • Not sampled: The trace or span is neither processed nor exported.

So "sampled out" is wrong, and so is calling the dropped data "sampled". Sampled means kept.

The real question is when you decide what to keep. That question splits sampling into two families.

Head sampling: decide at the first span

Head sampling makes the keep-or-drop decision as early as possible, usually when the root span starts. Nothing about the rest of the request is known yet. The service has not called the database, and the payment has not failed.

The most common form is consistent probability sampling, also called deterministic sampling. You pick a rate, say 10%, and the sampler hashes the trace ID against it. Every service that sees the same trace ID computes the same answer, so a trace is kept or dropped as a whole.

Probabilistic sampling earns its popularity:

  • It is cheap: One hash per trace. No buffering, no state, and no memory that grows with traffic.
  • It is predictable: 10% of traffic in means 10% out. Your bill follows your rate, not your incident count.
  • It is statistically honest: A uniform sample is representative. Percentiles and request mixes computed from it describe all of your traffic, not a biased slice of it.
  • It works anywhere: In the SDK, in an agent collector, in a gateway. Any component that can read a trace ID can apply it, and it needs no coordination.
  • It protects the pipeline: Dropping early means less data to move. At very high volume that alone can keep a collector fleet upright.

The downside is spelled out in the same OpenTelemetry page: head sampling cannot base its decision on the whole trace, so it cannot guarantee that you keep every trace with an error. The same goes for slow traces. In practice, that shows up in two ways. The animation below walks through both, using 100 traces across four services: three fail and three are slow. Drag the sample rate to see how high it has to go before those six survive, or switch to tail sampling to compare.

Failure one: broken traces. If the services in a request don't agree on the decision, every service keeps its own 10% of spans. That happens when samplers are configured differently, when a service drops the incoming trace context, or when two collectors run the probabilistic sampler with different hash seeds. You store 10% of the spans and get back almost no complete traces, just fragments. The worst fragment is an error span without its parents: you can see that something failed, but not what led up to it.

Failure two: the errors and slow requests are gone. Fix the consistency and the traces are whole again. But the decision was still made at the first span, before anything failed or slowed down. At a 10% rate, each of those traces has a 90% chance of being dropped. In the animation, 10% stores ten healthy traces and none of the six you would open first during an incident. Push the rate to 50% and you keep about half of them, for five times the storage.

Neither failure is a bug in probabilistic sampling. It does exactly what it says. It just doesn't know what happens later in the request.

Tail sampling: decide after the trace is done

Tail sampling waits. It holds the spans of a trace until all, or most, of them have arrived, and only then decides. Because it sees the whole trace, its rules can look at what actually happened:

  • Keep every trace that contains an error.
  • Keep traces slower than a latency threshold.
  • Keep more traces from a service you deployed an hour ago.
  • Sample high-volume services at a lower rate than low-volume ones.

That is the sampling you wanted in the first place. It comes with a cost, and the OpenTelemetry page is honest about it too.

Tail sampling is stateful. Something has to hold every span until its trace is decided. With the upstream tail sampling processor, that something is a single collector, and every span of a trace must reach the same one. So you put a load balancing exporter in front that routes spans by trace ID, and you run a second tier of collectors that buffer in memory. You size that tier for your peak traffic, and you monitor it, because it gets busiest exactly when your system misbehaves. If your services run in several clusters or networks, that tier has to receive spans from all of them, so every span crosses a network boundary before anything is dropped.

Tail sampling rules are not "set and forget". Rules grow with your system, and a rule that matches too much during an outage can flood your backend at the worst possible moment.

How the Dash0 edge collector does tail sampling

SignalControl Edge runs Dash0's distribution of the OpenTelemetry Collector inside your own network and tail samples there, before your telemetry leaves. What makes it different is where the decision is made.

Spans stay on whichever edge collector received them and wait there until their trace has a decision. The wait is configurable. Each collector reports which sampling conditions its spans match to Dash0's decision maker. Dash0 makes one keep-or-drop decision per trace for the whole collector fleet, and every collector applies it to the spans it holds. That distributed decision buys you three things:

  • No load balancing tier. The spans of one trace can land on different collectors. Nothing has to route them to one place first, so there is no extra network hop and no second tier of collectors to size for peak traffic. Your fleet can scale out in the middle of a peak without splitting traces.
  • One trace across clusters and networks. A request that starts in one Kubernetes cluster and calls services in another cluster, another cloud account, or an on-premises data center is still sampled as one trace. Each site runs its own edge collectors and only needs an outbound connection to Dash0, directly or through one edge proxy per site. Spans never travel between your networks to be sampled.
  • Dropped traces never leave your network. Only the spans of kept traces are sent to Dash0. You save egress on top of ingest and storage.

The decision is made per dataset, so send every span of a trace to the same dataset, whichever cluster it comes from.

Sampling also leaves your numbers alone. RED metrics are computed on the edge from 100% of spans, before sampling drops anything, so the request rates, error rates, and latency on your dashboards reflect all of your traffic.

Here is the same traffic, now split across two clusters in separate networks, sampled on the edge with three rules: keep every trace with an error span, keep every trace with a span slower than 500 ms, and keep 1% of everything. Move the baseline rule and watch what changes. The errors and slow traces never do.

Compare the two results. Probabilistic sampling at 10% stored ten traces and none of the six that matter. Tail sampling stored seven: all three errors, all three slow requests, and one baseline trace. You store less, and you lose none of the traces you would open first.

Three rules that cover most teams

The rule set from the animation is a good starting point for almost everyone. In Dash0, open the Sampling stage for spans in the SignalControl pipeline and click Add sampling rule. Sample Traces walks through the form.

  1. Keep errors: A rule with the Error condition type. It needs no further input.
  2. Keep slow traces: A rule with the Conditional condition type, the OTTL editor, and span.duration > 500ms. Pick the threshold your latency objective uses.
  3. Baseline: A rule with the Probabilistic condition type and a Sampling rate of 1.

A trace is kept when any rule matches it. Error and slow traces are kept as soon as their rule matches, and the baseline keeps a representative slice of everything else. That slice includes healthy requests, so you can still compare a failing request with what a normal one looks like.

If you manage rules through the API, the same three rules look like this:

json
keep-errors.json{
  "kind": "Dash0Sampling",
  "metadata": {
    "name": "keep-errors"
  },
  "spec": {
    "enabled": true,
    "display": {
      "name": "Keep error traces"
    },
    "conditions": {
      "kind": "error",
      "spec": {}
    },
    "rateLimit": {
      "rate": 1000
    }
  }
}
json
keep-slow.json{
  "kind": "Dash0Sampling",
  "metadata": {
    "name": "keep-slow"
  },
  "spec": {
    "enabled": true,
    "display": {
      "name": "Keep slow traces"
    },
    "conditions": {
      "kind": "ottl",
      "spec": {
        "ottl": "span.duration > 500ms"
      }
    },
    "rateLimit": {
      "rate": 1000
    }
  }
}
json
baseline-1-percent.json{
  "kind": "Dash0Sampling",
  "metadata": {
    "name": "baseline-1-percent"
  },
  "spec": {
    "enabled": true,
    "display": {
      "name": "Keep 1% of everything"
    },
    "conditions": {
      "kind": "probabilistic",
      "spec": {
        "rate": 0.01
      }
    }
  }
}

The rateLimit on the error and latency rules is there on purpose. When a dependency goes down, every trace becomes an error trace or a slow one, and "keep 100% of errors" turns into "keep 100% of everything". A cap of 1,000 traces per minute keeps the outage visible while capping what leaves your network and what you pay to store.

Your first enabled rule turns sampling on for the whole dataset. From then on, a trace is kept only if a rule matches it, and dropped traces can't be recovered. Create the error and latency rules first, then the baseline.

From there, add rules as you learn what you actually look at: a tighter latency rule for your checkout path, or a higher rate for a service you are rolling out. The Conditional condition type takes a filter or an OTTL expression for anything the built-in types don't cover.

Probabilistic sampling still has a job

None of this makes probabilistic sampling obsolete. It changes where it sits.

  • As the baseline inside tail sampling: The baseline rule above is probabilistic sampling. It gives you the representative sample of healthy traffic that error and latency rules can't.
  • In front of the pipeline at extreme volume: OpenTelemetry suggests combining the two. A light head sample protects the pipeline, and tail sampling makes the smart decision later. Keep the head rate generous, because anything it drops never reaches your tail rules.
  • As the fallback: If the edge collector can't reach the decision maker, it falls back to probabilistic sampling at 1% by default. You keep a representative trickle instead of nothing.

And sometimes the right sampling is no sampling. If you have tens of traces per second, or you only ever use traces in aggregate, keep everything and spend your effort elsewhere.

The point of sampling was never to keep less. It is to keep the right things. Probabilistic sampling keeps a fair share. Tail sampling keeps the traces you'll actually open. With the edge collector you get both, and the traces you drop never leave your network.