Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nativeframes): Do not enable NativeFramesTracking when native is not available #3705

Merged
merged 11 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ([#3700](https://github.com/getsentry/sentry-react-native/pull/3700))
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved

### 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
Loading