Skip to content

Commit f47de13

Browse files
fix(nativeframes): Do not enable NativeFramesTracking when native is not available (#3705)
1 parent 74b7585 commit f47de13

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Add `getDefaultConfig` option to `getSentryExpoConfig` ([#3690](https://github.com/getsentry/sentry-react-native/pull/3690))
88

9+
### Fixes
10+
11+
- Do not enable NativeFramesTracking when native is not available ([#3705](https://github.com/getsentry/sentry-react-native/pull/3705))
12+
913
### Dependencies
1014

1115
- Bump CLI from v2.30.0 to v2.30.2 ([#3678](https://github.com/getsentry/sentry-react-native/pull/3678))

samples/expo/app/_layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ process.env.EXPO_SKIP_DURING_EXPORT !== 'true' && Sentry.init({
5454
Sentry.metrics.metricsAggregatorIntegration(),
5555
new Sentry.ReactNativeTracing({
5656
routingInstrumentation,
57-
enableNativeFramesTracking: !isExpoGo(), // Only in native builds, not in Expo Go.
5857
}),
5958
);
6059
return integrations.filter(i => i.name !== 'Dedupe');

src/js/tracing/reactnativetracing.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ export class ReactNativeTracing implements Integration {
187187
/**
188188
* Registers routing and request instrumentation.
189189
*/
190-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
190+
public async setupOnce(
191+
addGlobalEventProcessor: (callback: EventProcessor) => void,
192+
getCurrentHub: () => Hub,
193+
): Promise<void> {
191194
const hub = getCurrentHub();
192195
const client = hub.getClient();
193196
const clientOptions = client && client.getOptions();
@@ -203,7 +206,6 @@ export class ReactNativeTracing implements Integration {
203206
tracePropagationTargets: thisOptionsTracePropagationTargets,
204207
routingInstrumentation,
205208
enableAppStartTracking,
206-
enableNativeFramesTracking,
207209
enableStallTracking,
208210
} = this.options;
209211

@@ -240,20 +242,7 @@ export class ReactNativeTracing implements Integration {
240242
});
241243
}
242244

243-
if (enableNativeFramesTracking) {
244-
NATIVE.enableNativeFramesTracking();
245-
this.nativeFramesInstrumentation = new NativeFramesInstrumentation(addGlobalEventProcessor, () => {
246-
const self = getCurrentHub().getIntegration(ReactNativeTracing);
247-
248-
if (self) {
249-
return !!self.nativeFramesInstrumentation;
250-
}
251-
252-
return false;
253-
});
254-
} else {
255-
NATIVE.disableNativeFramesTracking();
256-
}
245+
this._enableNativeFramesTracking(addGlobalEventProcessor);
257246

258247
if (enableStallTracking) {
259248
this.stallTrackingInstrumentation = new StallTrackingInstrumentation();
@@ -366,6 +355,40 @@ export class ReactNativeTracing implements Integration {
366355
return this._inflightInteractionTransaction;
367356
}
368357

358+
/**
359+
* Enables or disables native frames tracking based on the `enableNativeFramesTracking` option.
360+
*/
361+
private _enableNativeFramesTracking(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
362+
if (this.options.enableNativeFramesTracking && !NATIVE.enableNative) {
363+
// Do not enable native frames tracking if native is not available.
364+
logger.warn(
365+
'[ReactNativeTracing] NativeFramesTracking is not available on the Web, Expo Go and other platforms without native modules.',
366+
);
367+
return;
368+
}
369+
370+
if (!this.options.enableNativeFramesTracking && NATIVE.enableNative) {
371+
// Disable native frames tracking when native available and option is false.
372+
NATIVE.disableNativeFramesTracking();
373+
return;
374+
}
375+
376+
if (!this.options.enableNativeFramesTracking) {
377+
return;
378+
}
379+
380+
NATIVE.enableNativeFramesTracking();
381+
this.nativeFramesInstrumentation = new NativeFramesInstrumentation(addGlobalEventProcessor, () => {
382+
const self = getCurrentHub().getIntegration(ReactNativeTracing);
383+
384+
if (self) {
385+
return !!self.nativeFramesInstrumentation;
386+
}
387+
388+
return false;
389+
});
390+
}
391+
369392
/**
370393
* Sets the current view name into the app context.
371394
* @param event Le event.

0 commit comments

Comments
 (0)