diff --git a/CHANGELOG.md b/CHANGELOG.md index 16a7edb01..f3d81d6f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Add `getDefaultConfig` option to `getSentryExpoConfig` ([#3690](https://github.com/getsentry/sentry-react-native/pull/3690)) +### Fixes + +- Do not enable NativeFramesTracking when native is not available ([#3705](https://github.com/getsentry/sentry-react-native/pull/3705)) + ### Dependencies - Bump CLI from v2.30.0 to v2.30.2 ([#3678](https://github.com/getsentry/sentry-react-native/pull/3678)) diff --git a/samples/expo/app/_layout.tsx b/samples/expo/app/_layout.tsx index e0cbc9c7d..6fac65744 100644 --- a/samples/expo/app/_layout.tsx +++ b/samples/expo/app/_layout.tsx @@ -54,7 +54,6 @@ process.env.EXPO_SKIP_DURING_EXPORT !== 'true' && Sentry.init({ Sentry.metrics.metricsAggregatorIntegration(), new Sentry.ReactNativeTracing({ routingInstrumentation, - enableNativeFramesTracking: !isExpoGo(), // Only in native builds, not in Expo Go. }), ); return integrations.filter(i => i.name !== 'Dedupe'); diff --git a/src/js/tracing/reactnativetracing.ts b/src/js/tracing/reactnativetracing.ts index e3c4a64cf..397cc1ee5 100644 --- a/src/js/tracing/reactnativetracing.ts +++ b/src/js/tracing/reactnativetracing.ts @@ -187,7 +187,10 @@ export class ReactNativeTracing implements Integration { /** * Registers routing and request instrumentation. */ - public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { + public async setupOnce( + addGlobalEventProcessor: (callback: EventProcessor) => void, + getCurrentHub: () => Hub, + ): Promise { const hub = getCurrentHub(); const client = hub.getClient(); const clientOptions = client && client.getOptions(); @@ -203,7 +206,6 @@ export class ReactNativeTracing implements Integration { tracePropagationTargets: thisOptionsTracePropagationTargets, routingInstrumentation, enableAppStartTracking, - enableNativeFramesTracking, enableStallTracking, } = this.options; @@ -240,20 +242,7 @@ export class ReactNativeTracing implements Integration { }); } - if (enableNativeFramesTracking) { - NATIVE.enableNativeFramesTracking(); - this.nativeFramesInstrumentation = new NativeFramesInstrumentation(addGlobalEventProcessor, () => { - const self = getCurrentHub().getIntegration(ReactNativeTracing); - - if (self) { - return !!self.nativeFramesInstrumentation; - } - - return false; - }); - } else { - NATIVE.disableNativeFramesTracking(); - } + this._enableNativeFramesTracking(addGlobalEventProcessor); if (enableStallTracking) { this.stallTrackingInstrumentation = new StallTrackingInstrumentation(); @@ -366,6 +355,40 @@ export class ReactNativeTracing implements Integration { return this._inflightInteractionTransaction; } + /** + * Enables or disables native frames tracking based on the `enableNativeFramesTracking` option. + */ + private _enableNativeFramesTracking(addGlobalEventProcessor: (callback: EventProcessor) => void): void { + if (this.options.enableNativeFramesTracking && !NATIVE.enableNative) { + // Do not enable native frames tracking if native is not available. + logger.warn( + '[ReactNativeTracing] NativeFramesTracking is not available on the Web, Expo Go and other platforms without native modules.', + ); + return; + } + + if (!this.options.enableNativeFramesTracking && NATIVE.enableNative) { + // Disable native frames tracking when native available and option is false. + NATIVE.disableNativeFramesTracking(); + return; + } + + if (!this.options.enableNativeFramesTracking) { + return; + } + + NATIVE.enableNativeFramesTracking(); + this.nativeFramesInstrumentation = new NativeFramesInstrumentation(addGlobalEventProcessor, () => { + const self = getCurrentHub().getIntegration(ReactNativeTracing); + + if (self) { + return !!self.nativeFramesInstrumentation; + } + + return false; + }); + } + /** * Sets the current view name into the app context. * @param event Le event.