feat(mobile): start Sentry natively so launch crashes carry native context
Problem
Sentry's native iOS SDK only starts when JS calls Sentry.init (app/_layout.tsx), after the whole bundle has loaded. A crash during launch arrives with nothing native before it. MOBILE-7 (the keychain read at module load, 4 devices, still recurring) came in with one breadcrumb, JS starting 100 ms before the crash, so there was no way to tell what launched the app.
Change
Follows Sentry's Capture App Start Errors Expo setup:
useNativeInit: trueplusoptionson the@sentry/react-native/expoplugin. At prebuild the plugin writessentry.options.jsonand insertsRNSentrySDK.start()as the first line ofdidFinishLaunching, before React Native starts. In release builds the JSSentry.initthen leaves the already-started native SDK alone;beforeSendstill runs in JS.enableMetricKit: true(docs) forwards Apple's MetricKit hang, CPU-exception and disk-write diagnostics. It is in both the plugin options andSentry.init: OTA bundles are exported without prebuild, so they carry no options file and re-initialize the native SDK from the JS options alone. MetricKit hangs can duplicate the SDK's own app-hang events, as Sentry's docs note.sentry.options.jsonis gitignored. The plugin generates it and merges into any existing copy, so a committed or stale one would keep keysapp.config.tsno longer sets.
Without a DSN (dev builds) the file carries only enableMetricKit and the native SDK stays off, as today.
Native change: needs a new binary; the fingerprint runtime keeps it off existing builds' OTA channel.
Verification
expo prebuild --platform ioswith a DSN:sentry.options.json={dsn, environment, enableMetricKit},RNSentrySDK.start()atAppDelegate.swift:17, first line ofdidFinishLaunching. Without a DSN:{enableMetricKit}only. Generated files removed afterwards.bun run lintclean,bun run typecheck42/42,apps/mobilebun test129 pass.- Not yet run: a real native build and a forced crash on device. The
mobile-buildlabel would build one.
Summary by cubic
Starts Sentry's native iOS SDK at launch so crashes during launch arrive with native context, not just the JS breadcrumb that follows bundle load. The native SDK previously only started when JS called Sentry.init, making launch crashes like MOBILE-7 nearly impossible to diagnose.
useNativeInithas the@sentry/react-native/expoplugin generatesentry.options.jsonat prebuild and callRNSentrySDK.start()as the first line ofdidFinishLaunching.- MetricKit diagnostics are enabled in both the plugin options and
Sentry.init, since OTA bundles are exported without prebuild and re-initialize the native SDK from JS options alone. sentry.options.jsonis gitignored because the plugin merges into any existing copy, and a stale one would keep optionsapp.config.tsno longer sets.- Requires a new binary; the fingerprint runtime keeps it off existing builds' OTA channel.
Summary by CodeRabbit
- New Features
- Improved mobile app error monitoring with native initialization.
- Added environment-specific Sentry configuration using the mobile app’s DSN and environment settings.
- Enabled MetricKit support for enhanced iOS performance and diagnostic data.