feat(core): add opt-in loud invariants assertion instrumentation - #6592
Draft
antonis wants to merge 2 commits into
Draft
feat(core): add opt-in loud invariants assertion instrumentation#6592antonis wants to merge 2 commits into
antonis wants to merge 2 commits into
Conversation
Add an opt-in Metro/Babel transform that rewrites assertion call sites (invariant, assert, warning, console.assert) so a violated assertion reports a non-fatal Sentry event instead of being stripped from release bundles or crashing with a minified message. Adds the captureInvariantViolation runtime API and fixes a related gap in the RN global error handler so an already-captured, re-thrown error is not reported a second time. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. No changelog entries will be generated from this PR. 🤖 This preview updates automatically when you update the PR. |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
Contributor
Author
|
@cursor review |
Contributor
Author
|
@sentry review |
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.
📢 Type of change
📜 Description
Adds an opt-in Metro/Babel transform that rewrites assertion call sites (
invariant,assert,warning,console.assert) so a violated assertion reports a non-fatal Sentry event instead of being stripped from release bundles or crashing with a minified message.loudInvariantsin the Sentry Metro config; off by default. First-party code is instrumented by default; dependencies are opt-in through anincludeNodeModulesallowlist.invariant/assert) still throw after reporting;warning/console.assertare report-only.captureInvariantViolation()(also usable by hand).💡 Motivation and Context
Assertions are usually stripped from release builds or, when they do fire, surface as unreadable minified crashes. This surfaces them as grouped, non-fatal Sentry events with the condition, runtime values, and a stack anchored at the assertion site — without changing app source.
💚 How did you test it?
Unit tests for the reporter, the Babel plugin, the transformer wiring, and the RN error handler. Manually verified on the RN sample (iOS):
invariantfrom a dependency, first-partyconsole.assert, and a hand-written call each produced the expected handled events.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps