Sampling

Adding Sentry to your app gives you a great deal of very valuable information about errors and performance you wouldn't otherwise get. And lots of information is good -- as long as it's the right information, at a reasonable volume.

Sampling Error Events

To send a representative sample of your errors to Sentry, set the sample-rate option in your SDK configuration to a number between 0 (0% of errors sent) and 1 (100% of errors sent). This is a static rate, which will apply equally to all errors. For example, to sample 25% of your errors:

Copied
Sentry.init({ sampleRate: 0.25 });

The error sample rate defaults to 1, meaning all errors are sent to Sentry.

Inheritance

Whatever a transaction's sampling decision, that decision will be passed to its child spans and from there to any transactions they subsequently cause in other services.

(See Distributed Tracing for more about how that propagation is done.)

If the transaction currently being created is one of those subsequent transactions (in other words, if it has a parent transaction), the upstream (parent) sampling decision will be included in the sampling context data. Your traces-sampler can use this information to choose whether to inherit that decision. In most cases, inheritance is the right choice, to avoid breaking distributed traces. A broken trace will not include all your services.

Copied
tracesSampler: samplingContext => {
  // always inherit
  if (samplingContext.parentSampled !== undefined) {
    return samplingContext.parentSampled
  }

  ...
  // rest of sampling logic here
}

If you're using a traces-sample-rate rather than a traces-sampler, the decision will always be inherited.

Precedence

There are multiple ways for a transaction to end up with a sampling decision.

  • Random sampling according to a static sample rate set in traces-sample-rate
  • Random sampling according to a sample function rate returned by traces-sampler
  • Absolute decision (100% chance or 0% chance) returned by traces-sampler
  • If the transaction has a parent, inheriting its parent's sampling decision
  • Absolute decision passed to start-transaction

When there's the potential for more than one of these to come into play, the following precedence rules apply:

  1. If a sampling decision is passed to start-transaction, that decision will be used, overriding everything else.
  2. If traces-sampler is defined, its decision will be used. It can choose to keep or ignore any parent sampling decision, use the sampling context data to make its own decision, or choose a sample rate for the transaction. We advise against overriding the parent sampling decision because it will break distributed traces)
  3. If traces-sampler is not defined, but there's a parent sampling decision, the parent sampling decision will be used.
  4. If traces-sampler is not defined and there's no parent sampling decision, traces-sample-rate will be used.
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").