Skip to content

Commit 2b90b3d

Browse files
fix(tracing): Performance Tracing should be disabled by default (#3533)
1 parent 1cc72a3 commit 2b90b3d

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
- Fix `WITH_ENVIRONMENT` overwrite in `sentry-xcode-debug-files.sh` ([#3525](https://github.com/getsentry/sentry-react-native/pull/3525))
2727
- Sentry CLI 2.25.1 fixes background debug files uploads during Xcode builds ([#3486](https://github.com/getsentry/sentry-react-native/pull/3486))
28+
- Performance Tracing should be disabled by default ([#3533](https://github.com/getsentry/sentry-react-native/pull/3533))
2829

2930
### Dependencies
3031

src/js/integrations/default.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { hasTracingEnabled } from '@sentry/core';
21
import { HttpClient } from '@sentry/integrations';
32
import { Integrations as BrowserReactIntegrations } from '@sentry/react';
43
import type { Integration } from '@sentry/types';
@@ -77,7 +76,14 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
7776
}
7877
}
7978

80-
if (hasTracingEnabled(options) && options.enableAutoPerformanceTracing) {
79+
// hasTracingEnabled from `@sentry/core` only check if tracesSampler or tracesSampleRate keys are present
80+
// that's different from prev imp here and might lead misconfiguration
81+
// `tracesSampleRate: undefined` should not enable tracing
82+
const hasTracingEnabled =
83+
options.enableTracing ||
84+
typeof options.tracesSampleRate === 'number' ||
85+
typeof options.tracesSampler === 'function';
86+
if (hasTracingEnabled && options.enableAutoPerformanceTracing) {
8187
integrations.push(new ReactNativeTracing());
8288
}
8389
if (options.enableCaptureFailedRequests) {

src/js/sdk.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ export function init(passedOptions: ReactNativeOptions): void {
7676
stackParser: stackParserFromStackParserOptions(passedOptions.stackParser || defaultStackParser),
7777
beforeBreadcrumb: safeFactory(passedOptions.beforeBreadcrumb, { loggerMessage: 'The beforeBreadcrumb threw an error' }),
7878
initialScope: safeFactory(passedOptions.initialScope, { loggerMessage: 'The initialScope threw an error' }),
79-
tracesSampler: safeTracesSampler(passedOptions.tracesSampler),
8079
};
80+
if ('tracesSampler' in options) {
81+
options.tracesSampler = safeTracesSampler(options.tracesSampler);
82+
}
83+
8184
if (!('environment' in options)) {
8285
options.environment = getDefaultEnvironment();
8386
}

test/profiling/integration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ function initTestClient(
334334
const transportSendMock = jest.fn<ReturnType<Transport['send']>, Parameters<Transport['send']>>();
335335
const options: Sentry.ReactNativeOptions = {
336336
dsn: MOCK_DSN,
337+
enableTracing: true,
337338
_experiments: {
338339
profilesSampleRate: 1,
339340
},

test/sdk.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ describe('Tests the SDK functionality', () => {
115115
return new ReactNativeTracing({ routingInstrumentation: nav });
116116
};
117117

118+
it('Auto Performance is disabled by default', () => {
119+
init({});
120+
121+
expect(autoPerformanceIsEnabled()).toBe(false);
122+
});
123+
124+
it('Auto Performance is disabled when tracesSampleRate is set to undefined', () => {
125+
init({
126+
tracesSampleRate: undefined,
127+
});
128+
129+
expect(autoPerformanceIsEnabled()).toBe(false);
130+
});
131+
132+
it('Auto Performance is disabled when tracesSampler is set to undefined', () => {
133+
init({
134+
tracesSampler: undefined,
135+
});
136+
137+
expect(autoPerformanceIsEnabled()).toBe(false);
138+
});
139+
118140
it('Auto Performance is enabled when tracing is enabled (tracesSampler)', () => {
119141
init({
120142
tracesSampler: () => true,

0 commit comments

Comments
 (0)