Skip to content

feat(replay): add beforeErrorSampling callback to Session Replay#5214

Open
romtsn wants to merge 3 commits intomainfrom
rz/feat/session-replay-before-error-sampling
Open

feat(replay): add beforeErrorSampling callback to Session Replay#5214
romtsn wants to merge 3 commits intomainfrom
rz/feat/session-replay-before-error-sampling

Conversation

@romtsn
Copy link
Member

@romtsn romtsn commented Mar 19, 2026

📜 Description

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. Fail-open behavior: if the callback throws, replay capture proceeds normally.

💡 Motivation and Context

Currently, when an error occurs, SentryClient unconditionally calls captureReplay() — 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).

💚 How did you test it?

5 new unit tests in SentryClientTest.kt:

  • beforeErrorSampling returning false skips captureReplay
  • beforeErrorSampling returning true proceeds with captureReplay
  • beforeErrorSampling not set proceeds with captureReplay (default behavior unchanged)
  • beforeErrorSampling throwing exception proceeds with captureReplay (fail-open)
  • beforeErrorSampling receives correct event and hint

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

  • Update documentation with usage examples

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>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (replay) Add beforeErrorSampling callback to Session Replay by romtsn in #5214

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 54bcce4

romtsn and others added 2 commits March 19, 2026 19:39
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
Copy link

sentry bot commented Mar 19, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.36.0 (1) release Install Build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant