Skip to content

fix(core): Fix sourcemap upload when withSentry is used programmatically#6006

Merged
antonis merged 3 commits into
mainfrom
fix/withsentry-sourcemap-upload
Apr 16, 2026
Merged

fix(core): Fix sourcemap upload when withSentry is used programmatically#6006
antonis merged 3 commits into
mainfrom
fix/withsentry-sourcemap-upload

Conversation

@antonis

@antonis antonis commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix

📜 Description

When withSentry is used programmatically in app.config.ts, the Expo sourcemap upload script (sentry-expo-upload-sourcemaps) fails because it discovers Sentry config by looking for @sentry/react-native/expo in the plugins array of expo config --json. Programmatically-applied plugins don't appear in this array.

This PR fixes the issue by:

  1. Stashing build-time properties in config._internal — The withSentry plugin now stores organization, project, and url in config._internal.sentryBuildProperties during config resolution. This field is included in expo config --json output but is stripped from the public app manifest (isPublicConfig: true deletes _internal), so no metadata leaks into production builds.

  2. Reading _internal.sentryBuildProperties in the upload script — When the plugin isn't found in the plugins array, the script now checks config._internal.sentryBuildProperties from the same expo config --json response.

  3. Fallback to sentry.properties files — As additional defense-in-depth, the script also tries reading android/sentry.properties or ios/sentry.properties (created during expo prebuild).

  4. Improved error message — When no config source is found, the error now mentions the SENTRY_ORG/SENTRY_PROJECT/SENTRY_URL environment variable workaround.

Resolution chain (in order of priority)

  1. Environment variables (SENTRY_ORG, SENTRY_PROJECT, SENTRY_URL)
  2. Declarative plugin in config.plugins array
  3. config._internal.sentryBuildProperties (new — fixes the reported issue)
  4. sentry.properties files from prebuild (new — defense-in-depth)
  5. Error with actionable guidance

💡 Motivation and Context

Follow up to #5303 (comment)

Users following the withSentry documentation for app.config.ts hit this error when uploading sourcemaps for EAS Update:

Could not fetch '@sentry/react-native' plugin properties from expo config.

The root cause is that createRunOncePlugin (used by withSentry) applies config modifications through Expo's mod system but doesn't add the plugin to config.plugins. The expo config --json output therefore lacks the plugin entry, and the upload script can't find it.

💚 How did you test it?

  • Added 6 new tests covering _internal.sentryBuildProperties fallback, sentry.properties fallback, priority ordering, and error messaging
  • End-to-end verified locally: created a minimal app.config.js using programmatic withSentry, confirmed expo config --json includes _internal.sentryBuildProperties while plugins array does not contain the sentry plugin
  • Verified _internal is stripped from the public config (app manifest) by Expo's getConfig({ isPublicConfig: true }), so no metadata ships in the production app
  • All 196 existing SDK tests pass
  • Lint passes

📝 Checklist

  • I added tests to verify 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.
  • All tests passing
  • No breaking changes

🔮 Next steps

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

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


  • fix(core): Fix sourcemap upload when withSentry is used programmatically by antonis in #6006
  • chore(deps): bump follow-redirects from 1.15.11 to 1.16.0 by dependabot in #6004
  • chore: Bump sample app to React Native 0.85.1 by antonis in #5991
  • chore(deps): Bump E2E tests to 0.85.1 by antonis in #5990
  • Add deeplinkIntegration for automatic deep link breadcrumbs by alwx in #5983
  • fix(core): Retry native module resolution to prevent silent event drops by antonis in #5981
  • feat(core): Name navigation spans using dispatched action payload by alwx in #5982
  • ci: Gate size analysis on ready-to-merge label for PRs by antonis in #5963
  • chore(deps): update Android SDK to v8.38.0 by github-actions in #5971
  • chore(deps): update Sentry Android Gradle Plugin to v6.4.0 by github-actions in #5974
  • chore(deps): update Cocoa SDK to v9.10.0 by github-actions in #5972
  • chore(deps): update JavaScript SDK to v10.48.0 by github-actions in #5975
  • chore(deps): bump actions/github-script from 8 to 9 by dependabot in #5980
  • chore(deps): bump actions/create-github-app-token from 3.0.0 to 3.1.1 by dependabot in #5979
  • chore(deps): update Bundler Plugins to v5.2.0 by github-actions in #5968
  • chore(deps): bump axios from 1.13.5 to 1.15.0 by dependabot in #5978
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /performance-tests by dependabot in #5969
  • chore(deps): bump basic-ftp from 5.2.0 to 5.2.2 by dependabot in #5977
  • fix(profiling): Fix app start transaction profile timestamp offset by antonis in #5962
  • fix(android): Use componentStack as fallback for missing error stack traces by antonis in #5965
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /samples/react-native-macos by dependabot in #5967
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /samples/react-native by dependabot in #5966
  • fix(ios): Add SENTRY_PROJECT_ROOT env var for monorepo support by antonis in #5961
  • feat(ios): Add attachAllThreads option by antonis in #5960

Plus 12 more


🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against 62fe3dc

@antonis

antonis commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

@sentry review

Comment thread packages/core/scripts/expo-upload-sourcemaps.js
The early return when `config.plugins` was undefined prevented the
`_internal.sentryBuildProperties` fallback from being reached. Default
to an empty array instead so the fallback chain continues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antonis

antonis commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5083219. Configure here.

@antonis antonis marked this pull request as ready for review April 16, 2026 09:01
}
}

function getSentryPropertiesFromFile() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be a more general function to read .properties — I think it could go to some sort of utils, for example the code to write properties already exists in packages/core/plugin/src/utils.ts so maybe it should be there as well?
but also feel free to skip it since it doesn't seem to be very related to the purpose of this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considered this but the upload script is a standalone .js file that runs directly with Node. I'll keep a note to recheck if we can extract a utils for the scripts under https://github.com/getsentry/sentry-react-native/tree/main/packages/core/scripts

@alwx alwx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one small comment regarding the code to read properties — it feels like we could create one file with everything related to reading/writing properties

but again, it's not really important to do that as part of this PR

@antonis antonis merged commit 0572a71 into main Apr 16, 2026
55 of 61 checks passed
@antonis antonis deleted the fix/withsentry-sourcemap-upload branch April 16, 2026 10:02
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.

2 participants