Skip to content

Commit b245b17

Browse files
authored
RN: Add beforeErrorSampling callback to mobileReplayIntegration (#15583)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## 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.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ Merge after getsentry/sentry-react-native#5393 is released ## 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) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 5d923b2 commit b245b17

File tree

1 file changed

+26
-0
lines changed
  • docs/platforms/react-native/session-replay

1 file changed

+26
-0
lines changed

docs/platforms/react-native/session-replay/index.mdx

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

9393
Sampling begins as soon as a session starts. <PlatformIdentifier name="replays-session-sample-rate" /> is evaluated first. If it's sampled, the replay recording will begin. Otherwise, <PlatformIdentifier name="replays-on-error-sample-rate" /> 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.
9494

95+
### Ignore Certain Errors from Error Sampling
96+
97+
Once you've enabled <PlatformIdentifier name="replays-on-error-sample-rate" />, 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.
98+
99+
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.
100+
101+
```javascript {tabTitle:Mobile}
102+
import * as Sentry from "@sentry/react-native";
103+
104+
Sentry.init({
105+
dsn: "___PUBLIC_DSN___",
106+
replaysOnErrorSampleRate: 1.0,
107+
integrations: [
108+
Sentry.mobileReplayIntegration({
109+
beforeErrorSampling: (event, hint) => {
110+
// Only capture replays for unhandled errors
111+
const isHandled = event.exception?.values?.some(
112+
exception => exception.mechanism?.handled === true
113+
);
114+
return !isHandled;
115+
},
116+
}),
117+
],
118+
});
119+
```
120+
95121
## Privacy
96122
97123
<Alert level="warning">

0 commit comments

Comments
 (0)