npx react-native@latest init ErrorHandling
npx @sentry/wizard@latest -s -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.
- Create src/config directory
- Create sentry.ts file inside this directory
- Copy the code below
- Create account in sentry
- Create new project in sentry
- Get the sentry DSN of the project
import * as Sentry from '@sentry/react-native';
Sentry.init({
// Replace with your sentry DSN
dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
tracesSampleRate: 1.0,
});
Now you can capture errors automatically with Sentry.captureException()
Example:
try {
aFunctionThatMightFail();
} catch (err) {
Sentry.captureException(err);
}
export default Sentry.wrap(App);