Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,26 @@ Create a `sentry.options.json` file in your React Native project root with the s

When `Sentry.init()` runs in JavaScript, the native SDK is re-initialized with the JS options merged on top of the file options. This means JavaScript options take precedence for events captured **after** JS loads.

However, crashes and errors that occur **before** JavaScript loads (which is the purpose of this feature) are captured using only the values from `sentry.options.json` and native auto-detection. If you set a custom `release` or `dist` in `Sentry.init()`, make sure the same values are also in `sentry.options.json`. Otherwise, pre-JS crashes will be attributed to a different release than post-JS events.
However, crashes and errors that occur **before** JavaScript loads (which is the purpose of this feature) are captured using only the values from `sentry.options.json` and native auto-detection. If you set a custom `environment`, `release`, or `dist` in `Sentry.init()`, make sure the same values are also in `sentry.options.json`. Otherwise, pre-JS crashes will be attributed to a different release or environment than post-JS events.

</Alert>

### Setting the Environment

If you need different `environment` values for build (e.g., production vs staging), set the `SENTRY_ENVIRONMENT` environment variable at build time. The SDK build scripts will use this to override the `environment` in your `sentry.options.json` without modifying the source file.
If you need different `environment` values for build (e.g., production vs staging), set the `SENTRY_ENVIRONMENT` environment variable at build time. The SDK build scripts will use this to override the `environment` in both the native copy of your `sentry.options.json` and the options bundled into JavaScript, without modifying the source file.

```bash
SENTRY_ENVIRONMENT=staging npx react-native run-android
```

This works in any CI/CD system by setting the environment variable in your build configuration.

<Alert level="info" title="JavaScript Alignment Requires SDK 8.16.0">

Applying `SENTRY_ENVIRONMENT` (and `SENTRY_RELEASE`/`SENTRY_DIST`) to the JavaScript-bundled options requires Sentry React Native SDK version 8.16.0 or higher. On earlier versions these build variables override only the native side, so also set matching values in `Sentry.init()`.

</Alert>

### Setting Release and Distribution

If you use a custom `release` or `dist` in `Sentry.init()`, you should set matching values in `sentry.options.json` so that pre-JavaScript crashes are attributed to the correct release:
Expand All @@ -64,15 +70,15 @@ If you use a custom `release` or `dist` in `Sentry.init()`, you should set match
}
```

For dynamic values that change per build, set the `SENTRY_RELEASE` and `SENTRY_DIST` environment variables at build time. The SDK build scripts will use these to override the values in your `sentry.options.json`, similar to how `SENTRY_ENVIRONMENT` works.
For dynamic values that change per build, set the `SENTRY_RELEASE` and `SENTRY_DIST` environment variables at build time. The SDK build scripts will use these to override the values in both the native copy of your `sentry.options.json` and the options bundled into JavaScript, similar to how `SENTRY_ENVIRONMENT` works.

```bash
SENTRY_RELEASE="my-app@1.0.0+42" SENTRY_DIST="42" npx react-native run-ios
```

<Alert level="warning" title="Release Alignment">

If the `release` or `dist` in `sentry.options.json` doesn't match what you pass to `Sentry.init()`, you'll see two separate releases in Sentry — one for native crashes captured before JS loads and another for events captured after. Make sure both sources use the same values.
If the `environment`, `release`, or `dist` in `sentry.options.json` doesn't match what you pass to `Sentry.init()`, you'll see two separate releases or environments in Sentry — one for native crashes and sessions captured before JS loads and another for events captured after. This splits release health, so the **Releases** page shows **Failure Rate** instead of **Crash Free Session Rate**. Make sure both sources use the same values.

</Alert>

Expand Down Expand Up @@ -210,3 +216,5 @@ For per-environment builds with EAS Build, set `SENTRY_ENVIRONMENT` in your buil
}
}
```

Applying `SENTRY_RELEASE` and `SENTRY_DIST` from EAS to the JavaScript-bundled options requires Sentry React Native SDK version 8.16.0 or higher (see [Setting the Environment](#setting-the-environment) above). On earlier versions, also set matching values in `Sentry.init()`.

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.

⚠️ Adding a note to remember to validate the actual release version before merging

Loading