Skip to main content
Sampling allows you to control the volume of data sent to Sentry by only capturing a percentage of events.

Overview

Sentry supports two types of sampling:
  1. Error Sampling - Controls error events
  2. Trace Sampling - Controls transaction/span events

Error Sampling

sampleRate

Simple percentage-based sampling for error events:
number
default:"1.0"
Float between 0.0 (0%) and 1.0 (100%) of error events to send.
Implementation: From packages/core/src/client.ts:

Trace Sampling

tracesSampleRate

Simple percentage-based sampling for traces:
number
Float between 0.0 (0%) and 1.0 (100%) of traces to send.

tracesSampler

Dynamic sampling function for fine-grained control:
SamplingContext
Context data for making sampling decisions.
string
Transaction/span name.
SpanAttributes
Span attributes including operation, HTTP method, etc.
boolean
Whether the parent span was sampled.
object
Additional transaction context.
object
Request data (Node.js/server-side).
object
Browser location (browser-side).

Sampling Strategies

Sample by Transaction Name

Sample by HTTP Method

Sample by URL Pattern

Sample by User

Sample by Environment

Sample by Response Status

Parent Sampling

Child spans inherit sampling decisions from their parent:

beforeSampling Hook

Force sampling decisions before sampling runs:

Head-Based Sampling

Sampling decisions are made at the root span and inherited by all children:

Dynamic Sampling Context

Sampling context is propagated across services:

Sampling Best Practices

1. Start with Low Rates

2. Sample Critical Paths Higher

3. Don’t Sample Health Checks

4. Use Consistent Sampling

5. Consider Cost vs Value

Monitoring Sampling

Track sampling rates in your application: