From 48fc262de28398eea7683777b57e90645eecd12c Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 20 Nov 2025 17:22:19 +0100 Subject: [PATCH] RN: Add beforeErrorSampling callback to mobileReplayIntegration --- .../react-native/session-replay/index.mdx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/platforms/react-native/session-replay/index.mdx b/docs/platforms/react-native/session-replay/index.mdx index 8bda3062f0ade..e869393a32417 100644 --- a/docs/platforms/react-native/session-replay/index.mdx +++ b/docs/platforms/react-native/session-replay/index.mdx @@ -92,6 +92,32 @@ Sampling allows you to control how much of your website's traffic will result in Sampling begins as soon as a session starts. is evaluated first. If it's sampled, the replay recording will begin. Otherwise, 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. The remainder of the replay will behave similarly to a whole-session replay. +### Ignore Certain Errors from Error Sampling + +Once you've enabled , you can further customize which errors should trigger a replay capture by using the `beforeErrorSampling` callback. This is useful if you want to capture replays only for unhandled errors, or exclude certain error types from replay capture. + +The `beforeErrorSampling` callback is called when an error occurs and receives the event and hint as arguments. Returning `false` will prevent the replay from being captured for that specific error. + +```javascript {tabTitle:Mobile} +import * as Sentry from "@sentry/react-native"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + replaysOnErrorSampleRate: 1.0, + integrations: [ + Sentry.mobileReplayIntegration({ + beforeErrorSampling: (event, hint) => { + // Only capture replays for unhandled errors + const isHandled = event.exception?.values?.some( + exception => exception.mechanism?.handled === true + ); + return !isHandled; + }, + }), + ], +}); +``` + ## Privacy