Skip to content

Commit aa58af7

Browse files
romtsnclaude
andauthored
docs(android): Add beforeErrorSampling callback for Session Replay (#17134)
## DESCRIBE YOUR PR Document the new `beforeErrorSampling` callback on `SentryReplayOptions` that lets developers filter which errors trigger replay capture before the `onErrorSampleRate` dice roll. - Add `beforeErrorSampling` row to the configuration options table - Add "Ignore Certain Errors from Error Sampling" section with Kotlin and Java examples Refs getsentry/sentry-java#5214 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): - [ ] Other deadline: - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) Co-authored-by: Claude <noreply@anthropic.com>
1 parent b6c7809 commit aa58af7

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

docs/platforms/android/session-replay/configuration.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and the following options provide further customization:
2929
| networkRequestHeaders | `io.sentry.session-replay.network-request-headers` | List&lt;String&gt; | `['Content-Type', 'Content-Length', 'Accept']` | Request header names to capture for enabled URLs. |
3030
| networkResponseHeaders| `io.sentry.session-replay.network-response-headers` | List&lt;String&gt; | `['Content-Type', 'Content-Length', 'Accept']` | Response header names to capture for enabled URLs. |
3131
| debug | `io.sentry.session-replay.debug` | boolean | `false` | Enables Session Replay debug logging, which prints diagnostic information when a replay is recorded. |
32+
| 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). |
3233

3334

3435
## Network Details

docs/platforms/android/session-replay/index.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,37 @@ Sampling allows you to control how much of your website's traffic will result in
121121

122122
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.
123123

124+
### Ignore Certain Errors from Error Sampling
125+
126+
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.
127+
128+
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).
129+
130+
```kotlin {tabTitle:Kotlin}
131+
SentryAndroid.init(context) { options ->
132+
options.dsn = "___PUBLIC_DSN___"
133+
options.sessionReplay.onErrorSampleRate = 1.0
134+
135+
options.sessionReplay.beforeErrorSampling =
136+
SentryReplayOptions.BeforeErrorSamplingCallback { event, hint ->
137+
// Only capture replays for unhandled/crashed events
138+
event.isCrashed
139+
}
140+
}
141+
```
142+
143+
```java {tabTitle:Java}
144+
SentryAndroid.init(context, options -> {
145+
options.setDsn("___PUBLIC_DSN___");
146+
options.getSessionReplay().setOnErrorSampleRate(1.0);
147+
148+
options.getSessionReplay().setBeforeErrorSampling((event, hint) -> {
149+
// Only capture replays for unhandled/crashed events
150+
return event.isCrashed();
151+
});
152+
});
153+
```
154+
124155
## Privacy
125156

126157
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.

0 commit comments

Comments
 (0)