Skip to content

Commit 3320cf4

Browse files
authored
RN: Capture Startup Crashes (#16170)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ After getsentry/sentry-react-native#5582 is released ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent bbe4f2f commit 3320cf4

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Capture App Start Errors
3+
sidebar_order: 50
4+
description: "Learn how to capture app start errors and crashes that occur before JavaScript loads using native initialization."
5+
---
6+
7+
<Alert level="warning" title="Alpha Testing">
8+
9+
Sentry React Native SDK v8 is currently in alpha testing. This feature is available for early adopters and may undergo changes before the stable release.
10+
11+
</Alert>
12+
13+
By default, the React Native SDK initializes the native SDK underneath the `init` method called on the JS layer. As a result, the SDK has a current limitation of not capturing native crashes that occur prior to the `init` method being called on the JS layer.
14+
15+
Starting with SDK version 8.0.0, you can initialize Sentry natively before JavaScript loads, enabling capture of app start errors and crashes that occur during:
16+
17+
- Native module initialization
18+
- JavaScript bundle loading
19+
- Early React Native bridge setup
20+
21+
This feature uses a `sentry.options.json` configuration file and native initialization APIs that read from this file.
22+
23+
<Alert level="info" title="SDK Version Requirement">
24+
25+
This feature requires Sentry React Native SDK version 8.0.0 or higher.
26+
27+
</Alert>
28+
29+
## Configuration File
30+
31+
Create a `sentry.options.json` file in your React Native project root with the same options you currently have in `Sentry.init`:
32+
33+
```json {filename:sentry.options.json}
34+
{
35+
"dsn": "https://key@example.io/value",
36+
"debug": true,
37+
"environment": "production",
38+
"tracesSampleRate": 1.0,
39+
"enableTracing": true
40+
}
41+
```
42+
43+
<Alert level="info" title="Options Merging">
44+
45+
Options from `sentry.options.json` are merged with options from `Sentry.init()` in JavaScript. Options specified in JavaScript take precedence over the configuration file, allowing you to override settings at runtime.
46+
47+
</Alert>
48+
49+
## Android Setup
50+
51+
Initialize Sentry in your `MainApplication` class:
52+
53+
```kotlin {filename:android/app/src/main/java/.../MainApplication.kt}
54+
import io.sentry.react.RNSentrySDK
55+
56+
class MainApplication : Application(), ReactApplication {
57+
override fun onCreate() {
58+
super.onCreate()
59+
RNSentrySDK.init(this)
60+
// ... rest of your initialization code
61+
}
62+
}
63+
```
64+
65+
## iOS Setup
66+
67+
Initialize Sentry in your `AppDelegate`:
68+
69+
```objective-c {filename:ios/YourApp/AppDelegate.mm}
70+
#import <RNSentry/RNSentry.h>
71+
72+
@implementation AppDelegate
73+
74+
- (BOOL)application:(UIApplication *)application
75+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
76+
{
77+
[RNSentrySDK start];
78+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
79+
}
80+
81+
@end
82+
```
83+
84+
## Expo Setup
85+
86+
If you're using Expo, you can enable native initialization automatically using the Expo plugin:
87+
88+
```json {filename:app.json}
89+
{
90+
"expo": {
91+
"plugins": [
92+
[
93+
"@sentry/react-native/expo",
94+
{
95+
"useNativeInit": true
96+
}
97+
]
98+
]
99+
}
100+
}
101+
```
102+
103+
When `useNativeInit` is set to `true`, the Expo plugin automatically:
104+
- Creates `sentry.options.json` from your Expo config
105+
- Adds `RNSentrySDK.init()` to your Android `MainApplication`
106+
- Adds `RNSentrySDK.start()` to your iOS `AppDelegate`

docs/platforms/react-native/manual-setup/native-init.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ description: "Learn how to manually initialize the native SDKs."
66

77
By default, the React Native SDK initializes the native SDK underneath the `init` method called on the JS layer. As a result, the SDK has a current limitation of not capturing native crashes that occur prior to the `init` method being called on the JS layer. You can initialize the native SDKs yourself to overcome this limitation or if you want to provide custom options above what the React Native SDK currently provides.
88

9-
To do this, set [autoInitializeNativeSdk](/platforms/react-native/configuration/options/#autoInitializeNativeSdk) to `false` in the init options:
9+
<Alert level="info" title="Capture App Start Errors">
10+
11+
If you're using Sentry React Native SDK version 8.0.0 or higher, see the [Capture App Start Errors](/platforms/react-native/manual-setup/app-start-error-capture/) guide for a simpler approach using `sentry.options.json` and native initialization APIs.
1012

13+
</Alert>
14+
15+
To do this, set [autoInitializeNativeSdk](/platforms/react-native/configuration/options/#autoInitializeNativeSdk) to `false` in the init options:
1116

1217
```javascript
1318
Sentry.init({

0 commit comments

Comments
 (0)