Skip to main content

How can I configure Sentry Replays to only send data when an error occurs?

Updated over a month ago

Issue

Non-error replays are not useful in my application, I would like to only accept Replays that contain an error to better manage my Replays quota.

Applies To

  • All customers

  • Session Replay

Resolution

To configure Sentry to send replays only when an error occurs, you can adjust the replaysOnErrorSampleRate and replaysSessionSampleRate parameters in your Sentry setup.

replaysSessionSampleRate: Defines the percentage of overall user sessions to sample. Setting this to 0 disables replays for all sessions.

replaysOnErrorSampleRate: Defines the percentage of error sessions to sample for replays. This ensures that replays are captured when an error occurs.

Sampling begins as soon as a session starts. replaysSessionSampleRate is evaluated first. If it's sampled, the replay recording will begin. Otherwise, replaysOnErrorSampleRate is evaluated and if it's sampled, the integration will begin buffering the replay and will only upload it to Sentry if an error occurs.

Here’s an example configuration in JavaScript:

Sentry . init ( {

dsn : 'your dsn' ,

replaysSessionSampleRate : 0.0 , // Disable all session replays

replaysOnErrorSampleRate : 1.0 , // Capture replays for 100% of error sessions

} ) ;

Did this answer your question?