CodePush

Upload source maps for CodePush releases.

Sentry's React Native SDK works out of the box with CodePush. To see readable stack traces in the product, you must upload source maps to Sentry. This guide explains how to upload source maps for CodePush releases, that are created with the AppCenter CLI.

Ensure codePush is the outer most function because it needs access to the root component in order to swap out the bundle.

Copied
export default codePush(Sentry.wrap(App));

To ensure Sentry can symbolicate events from your CodePush releases, you need to generate and upload the necessary assets. When creating a CodePush release, include the --sourcemap-output-dir flag to generate source maps. This allows you to upload these files to Sentry in the next step.

Copied
appcenter codepush release-react \
  --app "${APP_NAME}" \
  --deployment-name "${DEPLOYMENT_NAME}" \
  --output-dir ./build \
  --sourcemap-output-dir ./build

If you are using Hermes make sure jq is installed on your system. If it's not, you can install it using your system's package manager. For example apt-get install jq on Ubuntu, or brew install jq on macOS with Homebrew.

Upload source maps for your CodePush release by setting up your environment variables and running the react-native appcenter command.

Before running the upload command, make sure to set up your environment variables.

Copied
export SENTRY_ORG=example-org
export SENTRY_PROJECT=example-project
export SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE

To upload source maps for your CodePush release, use the react-native appcenter command.

Copied
npx sentry-cli sourcemaps upload \
  --debug-id-reference \
  --strip-prefix /path/to/project/root \
  ./build

To associate the uploaded artifacts with the CodePush release, use the --release and --dist options, which are parameters of the sentry-cli command. Make sure that events reported by the SDK have the same release and dist values. You can follow the default schema ${BUNDLE}@${VERSION}+${BUILD} for release and ${BUILD} for dist or set the values manually in Sentry.init. This is optional when uploading artifacts with Debug IDs.

If you rely on codePush.getUpdateMetadata to get the CodePush Update Label, use Sentry.setTag to associate the CodePush Update Label with the captured events. This will enable you to filter events in the Sentry UI based on the label. We discourage using codePush.getUpdateMetadata to initialize the SDK as it delays the initialization and errors before the CodePush Update Label is available won't be reported to Sentry.

Copied
codePush.getUpdateMetadata().then((update) => {
  Sentry.setTag("codepush", update.label);
});
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").