React Native

Learn how to set up Sentry's React Native SDK.

Agent-Assisted Setup
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry React Native SDK.
Your agent will set up Sentry in your React Native app automatically. Works with Cursor, Claude Code, Codex, and more.View docs ↗
Install the full plugin

Install the Sentry plugin to give your assistant every skill. See the installation docs for more details.

Copied
npx @sentry/agent-plugin install

Read on to find out how to set up Sentry's React Native SDK which will automatically report errors and exceptions in your application. If you prefer to follow video instructions, see How to Install the Sentry React Native SDK in 60 Seconds.

In addition to error monitoring, here are some of the features you can configure when installing Sentry:

  • Logs: Send, view, and query logs from your app alongside your errors to get richer context when debugging.
  • Tracing: Monitor the timing and flow of requests and operations as they happen across different systems in your application to improve performance.
  • Session Replay: Get reproductions of user sessions to improve your app experience.
  • Profiling: Collect and analyze function-level information about your code to fine-tune performance.
  • Application Metrics: Send, view, and query counters, gauges, and measurements from your app to track health and drill down into related traces, logs, and errors.
  • User Feedback: Collect user feedback from anywhere inside your application at any time, without needing an error event to occur first.
  • Size Analysis: Monitor your mobile app's size in pre-production to prevent unexpected size increases (regressions) from reaching users.

Tracing, profiling, session replay, and logs can be added via the Configure section below. For the other features, refer to each product page for instructions on getting started.

Sentry captures data by using an SDK within your application's runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.

To install, run @sentry/wizard:

Copied
npx @sentry/wizard@latest -i reactNative

Sentry Wizard will patch your project accordingly, though you can set up manually if you prefer. You only need to patch the project once. Then you can add the patched files to your version control system.

The following tasks will be performed by the Sentry Wizard
  • Install the @sentry/react-native package.
  • Add the @sentry/react-native/metro to the metro.config.js Metro configuration.
  • Add the @sentry/react-native/expo to the app.json Expo configuration.
  • Enable the Sentry React Native Gradle build step for Android to auto-upload generated source maps and debug symbols.
  • Wrap the Bundle React Native code and images Xcode project build phase script to upload generated source maps and collect bundled node modules.
  • Add Upload Debug Symbols to Sentry Xcode project build phase.
  • Run pod install.
  • Store build credentials in ios/sentry.properties, android/sentry.properties and .env.local.
  • Configure Sentry for the supplied DSN in your layout.tsx/_App.tsx_file.

If you're using Expo, read our Expo guide to learn how to add Sentry to your Expo project. This SDK will work for both managed and bare projects.

To capture all errors, initialize the Sentry React Native SDK as soon as possible.

App.js
Copied
import * as Sentry from "@sentry/react-native";

Sentry.init({
  dsn: "___PUBLIC_DSN___",
  // Adds more context data to events (IP address, cookies, user, etc.)
  // For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/
  sendDefaultPii: true,
  // ___PRODUCT_OPTION_START___ performance
  // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
  // We recommend adjusting this value in production.
  // Learn more at
  // https://docs.sentry.io/platforms/react-native/configuration/options/#traces-sample-rate
  tracesSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ performance
  // ___PRODUCT_OPTION_START___ logs
  // Enable logs to be sent to Sentry
  // Learn more at https://docs.sentry.io/platforms/react-native/logs/
  enableLogs: true,
  // ___PRODUCT_OPTION_END___ logs
  // ___PRODUCT_OPTION_START___ profiling
  // profilesSampleRate is relative to tracesSampleRate.
  // Here, we'll capture profiles for 100% of transactions.
  profilesSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ profiling
  // ___PRODUCT_OPTION_START___ session-replay
  // Record session replays for 100% of errors and 10% of sessions
  replaysOnErrorSampleRate: 1.0,
  replaysSessionSampleRate: 0.1,
  integrations: [Sentry.mobileReplayIntegration()],
  // ___PRODUCT_OPTION_END___ session-replay
});

To automatically instrument your app with touch event tracking and automatic tracing, wrap it with Sentry.wrap:

App.js
Copied
export default Sentry.wrap(App);

This is not required if your app does not have a single parent "App" component.

Verify that your app is sending events to Sentry by adding the following snippet, which includes an intentional error. You should see the error reported in Sentry within a few minutes.

Copied
throw new Error("My first Sentry error!");

Alternatively, you can use the Sentry Playground to interactively test your SDK setup with multiple error scenarios.

Was this helpful?
Help improve this content
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").