Metro
Learn about the Metro bundler and how to configure it for your your application with Sentry React Native SDK.
Sentry's React Native SDK package ships with a Sentry Metro Serializer which allows you to automatically generate Debug IDs for your applications' bundles. This is crucial for making source maps work properly with Sentry. This page will guide you through the process of setting up the Metro Plugin for your application.
- Sign up for an account
- Install Sentry React Native SDK version 5.17.0 or newer
- Expo is supported from SDK version 5.16.0-alpha.1
The Sentry React Native SDK allows multiple ways to configure the Sentry Metro Serializer, depending on your current use of customeSerializer
in your Metro configuration.
The example below shows how to use the Sentry Metro Serializer if you don't have any customSerializers
(the default configuration).
metro.config.js
const { getDefaultConfig } = require("@react-native/metro-config");
const { withSentryConfig } = require("@sentry/react-native/metro");
const config = getDefaultConfig(__dirname);
module.exports = withSentryConfig(config);
If you already have a custom serializer, you can wrap it with the Sentry Metro Serializer and call options.sentryBundleCallback
before serializing the bundle content.
metro.config.js
const {
getDefaultConfig,
mergeConfig,
} = require("@react-native/metro-config");
const { withSentryConfig } = require("@sentry/react-native/metro");
const myCustomSerializer = (entryPoint, preModules, graph, options) => {
let bundle = prepareBundle(entryPoint, preModules, graph, options);
if (options.sentryBundleCallback) {
// Callback adds Sentry Debug IDs module to the bundle
bundle = options.sentryBundleCallback(bundle);
}
const code = createCode(bundle);
const map = createSourceMap();
return { code, map };
};
const config = {
serializer: {
customSerializer: myCustomSerializer,
},
};
module.exports = withSentryConfig(
mergeConfig(getDefaultConfig(__dirname), config),
);
Expected bundle intermediate structure:
export type Bundle = {
modules: Array<[id: number, code: string]>;
post: string;
pre: string;
};
- Sentry Metro Serializer can't add Debug ID to the Hermes Composed Source Maps. Please see Manual Upload With Hermes guide on how to add Debug ID to the Hermes Composed Source Maps.
- If you see
Debug ID was not found in the bundle.
error message thesentryBundleCallback
was not called by your custom serializer. - If Metro configuration is missing in your Expo project, create it using
npx expo customize metro.config.js
. Read more about Customizing Expo Metro Configuration.
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").