Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Babel Transformers to Sentry Metro Plugin page #12495

Merged
merged 3 commits into from
Feb 3, 2025
Merged
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
45 changes: 40 additions & 5 deletions docs/platforms/react-native/manual-setup/metro.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Metro
description: "Learn about the Metro bundler and how to configure it for your your application with Sentry React Native SDK."
description: "Learn about the Metro bundler and how to configure it for your application with Sentry React Native SDK."
sidebar_order: 3
---

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.
Sentry's React Native SDK package ships with a Sentry Metro Plugin which allows you to automatically generate Debug IDs for your applications' bundles. This is crucial for making source maps work properly with Sentry. The plugin also helps you to annotate React component names so they are available in breadcrumbs and minimize the bundle size by removing unused SDK features.
This page will guide you through the process of setting up the Metro Plugin for your application.

## Prerequisities
Expand All @@ -15,11 +15,11 @@ This page will guide you through the process of setting up the Metro Plugin for

## Configuration

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 Sentry React Native SDK allows multiple ways to configure the Sentry Metro Plugin, depending on your current use of the Metro configuration.

### Use Sentry Metro Serializer
### Use the Sentry Metro Plugin

The example below shows how to use the Sentry Metro Serializer if you don't have any `customSerializers` (the default configuration).
The example below shows how to use the Sentry Metro Plugin with the default config.

```javascript {tabTitle:React Native} {filename:metro.config.js}
const { getDefaultConfig } = require("@react-native/metro-config");
Expand All @@ -37,6 +37,41 @@ const { getSentryExpoConfig } = require("@sentry/react-native/metro");
const config = getSentryExpoConfig(__dirname);
```

### Add a Custom Babel Transformer

If you already have a custom transformer, ensure that the Sentry Metro Plugin is applied as the last step. The Sentry Metro Plugin doesn't overwrite the existing configuration, it extends or wraps existing properties.

```javascript {tabTitle:React Native} {filename:metro.config.js}
const { getDefaultConfig } = require("@react-native/metro-config");
const { withSentryConfig } = require('@sentry/react-native/metro');

const config = getDefaultConfig(__dirname);

config.transformer = {
...config.transformer,
babelTransformerPath: require.resolve('react-native-custom-transformer'),
};

module.exports = withSentryConfig(config);
```

```javascript {tabTitle:Expo} {filename:metro.config.js}
const { getDefaultConfig } = require('@expo/metro-config');
const { getSentryExpoConfig } = require('@sentry/react-native/metro');

const config = getSentryExpoConfig(__dirname, {
getDefaultConfig: (projectRoot, options) => {
const config = getDefaultConfig(projectRoot, options);

config.transformer = {
...config.transformer,
babelTransformerPath: require.resolve('react-native-custom-transformer/expo'),
};
return config;
},
});
```

### Wrap Your Custom Serializer

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.
Expand Down
Loading