> 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/datadog.md).

# Datadog

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

Follow [Datadog's Expo guide](https://docs.datadoghq.com/real_user_monitoring/mobile_and_tv_monitoring/react_native/setup/expo/), then add Datadog's Metro config so it can match a crash to its source map.

In `metro.config.js`:

```js
const { getDatadogExpoConfig } = require('@datadog/mobile-react-native/metro');

const config = getDatadogExpoConfig(__dirname);

module.exports = config;
```

Add `@datadog/datadog-ci` to your dev dependencies.

#### 2. Set the environment variables

| Variable          | When                                |
| ----------------- | ----------------------------------- |
| `DATADOG_API_KEY` | Always                              |
| `DATADOG_SITE`    | If your site is not `datadoghq.com` |

#### 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.

```bash
example: npx eoas publish --branch production --nonInteractive

for platform in ios android; do
  npx datadog-ci react-native upload \
    --platform "$platform" \
    --service com.example.app \
    --bundle dist/_expo/static/js/$platform/*.hbc \
    --sourcemap dist/_expo/static/js/$platform/*.hbc.map \
    --release-version 1.0.0 \
    --build-version 42
done
```

Replace `--service`, `--release-version` and `--build-version` with the values your app reports to Datadog.

If you publish with `--platform ios` or `--platform android`, loop over that platform only. If you publish with `--outputDir`, replace `dist` with that directory.
