> For the complete documentation index, see [llms.txt](https://mercure-technologies.gitbook.io/xprem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mercure-technologies.gitbook.io/xprem/integrations/bugsnag.md).

# BugSnag

BugSnag matches a crash to its source map with a code bundle ID.

Your app reports its update ID as the code bundle ID, and your CI uploads the source map under the same ID.

{% hint style="warning" %}
`--emitMetadata` requires `eoas` and the server on v3.2.4 or later.
{% endhint %}

#### 1. Set up BugSnag in your app

Follow [BugSnag's Expo guide](https://docs.bugsnag.com/platforms/react-native/expo/), then report the update ID as the code bundle ID:

```tsx
import Bugsnag from '@bugsnag/react-native';
import * as Updates from 'expo-updates';

Bugsnag.start({
  codeBundleId: Updates.isEmbeddedLaunch ? undefined : (Updates.updateId ?? undefined),
});
```

The bundle embedded in the build reports no code bundle ID, because its source map is uploaded with the build.

Add `@bugsnag/cli` to your dev dependencies.

#### 2. Set up the CI

| Requirement       | Why                      |
| ----------------- | ------------------------ |
| `BUGSNAG_API_KEY` | Authenticates the upload |
| `jq`              | Reads the update IDs     |

#### 3. Upload the source maps after each publish

`eoas publish` writes each platform's bundle and source map to `dist/`. Do not pass `--no-dumpSourcemap`, which turns the source maps off.

Publish with `--emitMetadata`. It writes `dist/xprem-update-metadata.json`, with the update ID of each published platform:

```json
[
  { "id": "9f2c4a1e-7b3d-4e5f-8a6b-1c2d3e4f5a6b", "platform": "ios", "runtimeVersion": "1.0.0", "branch": "production" }
]
```

Then upload each platform's source map under its update ID:

```bash
npx eoas publish --branch production --nonInteractive --emitMetadata

jq -r '.[] | "\(.platform) \(.id)"' dist/xprem-update-metadata.json |
  while read -r platform id; do
    npx bugsnag-cli upload react-native-sourcemaps \
      --api-key "$BUGSNAG_API_KEY" \
      --platform "$platform" \
      --bundle dist/_expo/static/js/$platform/*.hbc \
      --source-map dist/_expo/static/js/$platform/*.hbc.map \
      --code-bundle-id "$id"
  done
```

A platform with no change is not published and has no entry in the file, so the loop skips it. If you publish with `--outputDir`, replace `dist` with that directory.

{% hint style="info" %}
A republished update gets a new update ID. BugSnag has no source map under that ID, so its crashes are not symbolicated.
{% endhint %}
