sentry-react-native: Doesn't Catch Native Exceptions before the Javascript Runs
OS:
- Windows
- MacOS
- Linux
Platform:
- iOS
- Android
Output of node -v && npm -v && npm ls --prod --depth=0
v10.8.0
6.7.0
LightOS@0.0.1 /Users/hhff/dev/light-two/LightOS
├── appcenter@1.7.1
├── appcenter-analytics@1.7.1
├── appcenter-crashes@1.7.1
├── libphonenumber-js@1.4.4
├── lodash.get@4.4.2
├── luxon@1.5.0
├── raven-for-redux@1.3.1
├── react@16.4.1
├── react-mixin@5.0.0
├── UNMET PEER DEPENDENCY react-native@0.56.0
├── react-native-config@0.11.5
├── react-native-contacts@2.2.2
├── react-native-device-battery@1.0.0
├── react-native-fs@2.11.15 invalid
├── react-native-incall-manager@3.2.2
├── react-native-keyevent@0.1.1
├── react-native-loud-speaker@1.0.4
├── react-native-orientation@3.1.3
├── react-native-secure-key-store@1.0.9
├── react-native-sentry@0.39.0
├── react-native-sound@0.10.9
├── react-native-telephony@1.5.1 invalid
├── react-native-timer@1.3.4
├── react-navigation@2.11.2
├── react-redux@5.0.7
├── react-timer-mixin@0.13.4
├── redux@4.0.0
├── redux-promise-middleware@5.1.1
├── redux-saga@1.0.0-beta.3
├── redux-thunk@2.3.0
├── reselect@3.0.1
└── styled-components@3.4.5
npm ERR! peer dep missing: react-native@^0.51.0, required by react-native-fs@2.11.15
npm ERR! peer dep missing: react-native@^0.51, required by react-native-telephony@1.5.1
npm ERR! invalid: react-native-fs@2.11.15 /Users/hhff/dev/light-two/LightOS/node_modules/react-native-fs
npm ERR! extraneous: base-64@0.1.0 /Users/hhff/dev/light-two/LightOS/node_modules/base-64
npm ERR! extraneous: utf8@2.1.2 /Users/hhff/dev/light-two/LightOS/node_modules/utf8
npm ERR! invalid: react-native-telephony@1.5.1 /Users/hhff/dev/light-two/LightOS/node_modules/react-native-telephony
Config:
Sentry.config('https://...@sentry.io/...', {
....
}).install()
I have following issue:
I’d like to use Sentry to capture information in early Android hooks like MainActivity#onCreate
. Unfortunately, because this lib requires the JS to initialize the Native client over the bridge, those early hooks will no-op because it hasn’t initialized yet.
Steps to reproduce:
- Use this Lib
- Add
Sentry.capture("Hello!")
toMainActivity#onCreate
Actual result:
- The message doesn’t make it to Sentry
Expected result:
- The message should make it to Sentry
FWIW, my current work around is to init the client early in the MainApplication#onCreate
. Then my JS runs, and re-inits the Sentry client through the Native Module API. Seems OK, but not ideal!
Thanks for all the hard work!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (10 by maintainers)
We’re planning to tackle this soon. Sorry for the delay
We’ve been discussing possible solutions internally, this is a pretty complex and difficult issue and if we find a good solution we’ll make it happen. But for now as a workaround you can initialize the SDKs twice, by this I mean calling
.init
on the Andrid/Cocoa SDK in your own code and it should work fine.I was thinking that the DSN could be a native variable rather than a JS string, and that var could be passed back to the JS side if necessary as a const (React Native supports constants over the bridge).
IMO if your app is crashing from native exceptions before the JS runs, but not reporting them to Sentry, thats a big deal!
Is there any problem with the approach above? ie - instantiating the native client twice? Kinda feels like something this lib should do by default.