fix(core): Always re-initialize native SDK from JS in dev builds#5872
Merged
fix(core): Always re-initialize native SDK from JS in dev builds#5872
Conversation
When `sentry.options.json` exists (generated by the Expo config plugin with `useNativeInit: true`), the SDK was setting `autoInitializeNativeSdk = false`, skipping the JS-side `initNativeSdk` call entirely. This prevented the native log bridge and runtime values (devServerUrl, defaultSidecarUrl) from being set up, causing zero envelopes to be sent to sentry.io in development builds. The fix adds a `!__DEV__` guard so that in dev builds, JS always re-initializes native (the native SDK handles double-init gracefully with "Previous configuration will be overwritten"). In release builds, the existing behavior is preserved for app start crash capture. Closes #5734 Co-Authored-By: Claude Opus 4.6 (1M context) <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. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
Contributor
lucas-zimerman
approved these changes
Mar 24, 2026
Collaborator
lucas-zimerman
left a comment
There was a problem hiding this comment.
Tested locally, all working!.
LGTM!
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
When
sentry.options.jsonexists (generated by the Expo config plugin withuseNativeInit: trueandoptions), the Metro serializer injects__SENTRY_OPTIONS__into the JS bundle. The SDK then setsautoInitializeNativeSdk = false, skipping the JS-sideinitNativeSdkcall entirely.This prevents the native log bridge (
rnLogger.setReactContext) and runtime values (devServerUrl,defaultSidecarUrl,mobileReplayOptions) from being configured, resulting in zero envelopes being sent to sentry.io in development builds.The fix adds a
!__DEV__guard so that:initNativeSdk, which re-initializes native (the native SDK handles this gracefully:"Sentry has been already initialized. Previous configuration will be overwritten."). The log bridge and runtime values are properly set up.autoInitializeNativeSdk = falsekeeps the native-only init for app start crash capture.💡 Motivation and Context
Closes #5734
Reproduction: With
sentry.options.jsonin the project root, the Expo sample sends zero envelopes to sentry.io (events only appear in Spotlight). Without the file, everything works — JS re-initializes native and envelopes are sent successfully.The root cause: when
autoInitializeNativeSdk = false, the JS wrapper'sinitNativeSdkreturns early at line 250-257 without ever callingRNSentry.initNativeSdk(). The native module never receives the JS options, the React context isn't set on the logger, andcaptureEnvelopecalls from JS don't result in envelopes being delivered.💚 How did you test it?
__DEV__=trueand__DEV__=falsemodes, verifyingautoInitializeNativeSdkis set correctly in each casesentry.options.jsonin the Expo sample project rootdidCallNativeInit: false, zeroEnvelope sent successfullyin logsdidCallNativeInit: true, multipleEnvelope sent successfully.in logs📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
#skip-changelog since this only affects the development workflow