The Big Picture

The lifecycle of an event in Sentry is a complex process which involves many components. Dynamic Sampling is one of these components, and it is important to understand how it fits into the bigger picture.

Sequencing

Dynamic Sampling occurs at the edge of our ingestion pipeline, precisely in Relay.

When events arrive, in a simplified model, they go through the following steps:

  1. Inbound data filters: every event runs through inbound data filters as configured in project settings, such as legacy browsers or denied releases. Events dropped here are not counted towards quota and are not included in "total events" data.
  2. Quota enforcement: Sentry charges for all further events sent in, before they are passed on to dynamic sampling.
  3. Metrics extraction: after passing quotas, Sentry extracts metrics from the total incoming events. These metrics provide granular numbers for the performance and frequency of every event.
  4. Dynamic Sampling: based on an internal set of rules, Relay determines a sample rate for every incoming event. A random number generator finally decides whether a payload should be kept or dropped.
  5. Rate limiting: events that are sampled by Dynamic Sampling will be stored and indexed. To protect the infrastructure, internal rate limits apply at this point. Under normal operation, this rate limit is never reached since dynamic sampling already reduces the volume of events stored.

The ingestion pipeline has two kinds of rate limits that behave differently compared to organizations without dynamic sampling:

  1. High-level request limits on load balancers: these limits do not differentiate which data is sent by clients and drop requests as soon as the throughput from clients reaches the limit.
  2. Specific limits per data category in Relay: these limits apply once requests have been parsed and have gone through basic handling (see Sequencing above).

Dynamic sampling ensures complete traces by retaining all events associated with a trace if the head event is preserved.

Despite dynamic sampling providing trace completeness, events or other items (errors, replays, ...) may still be missing from a trace when rate limiting drops one or more of them. Rate limiting drops items without regard for the trace, making each decision independently and potentially resulting in broken traces.

Clients have their own traces sample rate. The client sample rate is a number in the range [0.0, 1.0] (from 0% to 100%) that controls how many events arrive at Sentry. While documentation will generally suggest a sample rate of 1.0, for some use cases it might be better to reduce it.

Dynamic Sampling further reduces how many events get stored internally. While most graphs and numbers in Sentry are based on metrics, accessing spans and tags requires stored events. The sample rates apply on top of each other.

An example of client side sampling and Dynamic Sampling starting from 100k events which results in 15k stored events is shown below:

Client and Dynamic Sampling

To collect unsampled information for “total” transactions in Performance, Alerts, and Dashboards, Relay extracts metrics from spans and transactions. In short, these metrics comprise:

  • Counts and durations for all events.
  • A distribution (histogram) for all measurements, most notably the web vitals.
  • The number of unique users (set).

Each of these metrics can be filtered and grouped by a number of predefined tags, implemented in Relay.

For more granular queries, stored events are needed. The purpose of dynamic sampling here is to ensure that there are always sufficient representative sample events.

If you want to learn more about Dynamic Sampling, continue to the next page.

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").