feat(replay): add beforeErrorSampling callback to Session Replay#5214
Merged
feat(replay): add beforeErrorSampling callback to Session Replay#5214
Conversation
Add a BeforeErrorSamplingCallback to SentryReplayOptions that lets developers filter which errors trigger replay capture. The callback runs before the onErrorSampleRate dice roll - returning false skips captureReplay entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sentry Build Distribution
|
romtsn
commented
Mar 20, 2026
markushi
approved these changes
Mar 20, 2026
Member
markushi
left a comment
There was a problem hiding this comment.
LGTM, once small concern, but that doesn't affect overall functionality.
3 tasks
romtsn
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Mar 26, 2026
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 <noreply@anthropic.com>
Merged
6 tasks
romtsn
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Mar 26, 2026
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
Add a
BeforeErrorSamplingCallbacktoSentryReplayOptionsthat lets developers filter which errors trigger replay capture. The callback runs before theonErrorSampleRatedice roll — returningfalseskipscaptureReplay()entirely. Fail-open behavior: if the callback throws, replay capture proceeds normally.💡 Motivation and Context
Currently, when an error occurs,
SentryClientunconditionally callscaptureReplay()— developers have no way to skip replay capture for specific error types (e.g. handled exceptions, specific error classes).This mirrors the same feature added in the React Native SDK (getsentry/sentry-react-native#5393).
beforeXyzoptions sentry#86905💚 How did you test it?
5 new unit tests in
SentryClientTest.kt:beforeErrorSamplingreturningfalseskipscaptureReplaybeforeErrorSamplingreturningtrueproceeds withcaptureReplaybeforeErrorSamplingnot set proceeds withcaptureReplay(default behavior unchanged)beforeErrorSamplingthrowing exception proceeds withcaptureReplay(fail-open)beforeErrorSamplingreceives correct event and hint📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps