From 41621c993703c9afd2602440920f213351028138 Mon Sep 17 00:00:00 2001 From: Roman Zavarnitsyn Date: Thu, 26 Mar 2026 14:07:01 +0100 Subject: [PATCH] docs(android): Add beforeErrorSampling callback for Session Replay Document the new beforeErrorSampling callback on SentryReplayOptions that lets developers filter which errors trigger replay capture. Adds a row to the configuration table and a new section with Kotlin and Java examples. Refs getsentry/sentry-java#5214 Co-Authored-By: Claude --- .../android/session-replay/configuration.mdx | 1 + .../android/session-replay/index.mdx | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/docs/platforms/android/session-replay/configuration.mdx b/docs/platforms/android/session-replay/configuration.mdx index 2c8438b01e28d..dc4e435a6a3a6 100644 --- a/docs/platforms/android/session-replay/configuration.mdx +++ b/docs/platforms/android/session-replay/configuration.mdx @@ -29,6 +29,7 @@ and the following options provide further customization: | networkRequestHeaders | `io.sentry.session-replay.network-request-headers` | List<String> | `['Content-Type', 'Content-Length', 'Accept']` | Request header names to capture for enabled URLs. | | networkResponseHeaders| `io.sentry.session-replay.network-response-headers` | List<String> | `['Content-Type', 'Content-Length', 'Accept']` | Response header names to capture for enabled URLs. | | debug | `io.sentry.session-replay.debug` | boolean | `false` | Enables Session Replay debug logging, which prints diagnostic information when a replay is recorded. | + | beforeErrorSampling | `—` | `BeforeErrorSamplingCallback` | `null` | A callback invoked before the `onErrorSampleRate` is checked. Return `false` to skip replay capture for this error, or `true` to proceed with the normal sample rate check. If the callback throws, replay capture proceeds normally (fail-open). Only configurable in code. See [Ignore Certain Errors from Error Sampling](/platforms/android/session-replay/#ignore-certain-errors-from-error-sampling). | ## Network Details diff --git a/docs/platforms/android/session-replay/index.mdx b/docs/platforms/android/session-replay/index.mdx index ffadf74c6e2bd..057c0b2362105 100644 --- a/docs/platforms/android/session-replay/index.mdx +++ b/docs/platforms/android/session-replay/index.mdx @@ -121,6 +121,37 @@ Sampling allows you to control how much of your website's traffic will result in Sampling begins as soon as a session starts. `sessionSampleRate` is evaluated first. If it's sampled, the replay recording will begin. Otherwise, `onErrorSampleRate` 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 `onErrorSampleRate`, 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. If the callback throws an exception, replay capture proceeds normally (fail-open). + +```kotlin {tabTitle:Kotlin} +SentryAndroid.init(context) { options -> + options.dsn = "___PUBLIC_DSN___" + options.sessionReplay.onErrorSampleRate = 1.0 + + options.sessionReplay.beforeErrorSampling = + SentryReplayOptions.BeforeErrorSamplingCallback { event, hint -> + // Only capture replays for unhandled/crashed events + event.isCrashed + } +} +``` + +```java {tabTitle:Java} +SentryAndroid.init(context, options -> { + options.setDsn("___PUBLIC_DSN___"); + options.getSessionReplay().setOnErrorSampleRate(1.0); + + options.getSessionReplay().setBeforeErrorSampling((event, hint) -> { + // Only capture replays for unhandled/crashed events + return event.isCrashed(); + }); +}); +``` + ## Privacy The SDK is recording and aggressively masking all text, images, and webviews by default. If your app has any sensitive data, you should only turn the default masking off after explicitly masking out the sensitive data, using the APIs described below.