Skip to content

Commit

Permalink
fix(nativeframes): Do not enable NativeFramesTracking when native is …
Browse files Browse the repository at this point in the history
…not available (#3705)
  • Loading branch information
krystofwoldrich authored Mar 22, 2024
1 parent 74b7585 commit f47de13
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion samples/expo/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
55 changes: 39 additions & 16 deletions src/js/tracing/reactnativetracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const hub = getCurrentHub();
const client = hub.getClient();
const clientOptions = client && client.getOptions();
Expand All @@ -203,7 +206,6 @@ export class ReactNativeTracing implements Integration {
tracePropagationTargets: thisOptionsTracePropagationTargets,
routingInstrumentation,
enableAppStartTracking,
enableNativeFramesTracking,
enableStallTracking,
} = this.options;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f47de13

Please sign in to comment.