feat(replay): add beforeErrorSampling callback to Session Replay#5214
Open
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 ✨
🤖 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
|
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