티스토리 수익 글 보기
React Native
Learn how to set up Sentry's React Native SDK.
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry React Native SDK.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.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
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:
npx @sentry/wizard@latest -i reactNative
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.
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.jsimport * 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
});
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.jsexport default Sentry.wrap(App);
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.
throw new Error("My first Sentry error!");
throw new Error("My first Sentry error!");
Sentry.nativeCrash();
Alternatively, you can use the Sentry Playground to interactively test your SDK setup with multiple error scenarios.
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Learn about the features of Sentry's React Native SDK
- Add readable stack traces to errors
- Add Apple Privacy manifest
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").