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(tracing): Performance Tracing should be disabled by default #3533

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

### Dependencies

Expand Down
7 changes: 5 additions & 2 deletions src/js/integrations/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { hasTracingEnabled } from '@sentry/core';
import { HttpClient } from '@sentry/integrations';
import { Integrations as BrowserReactIntegrations } from '@sentry/react';
import type { Integration } from '@sentry/types';
Expand Down Expand Up @@ -77,7 +76,11 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
}
}

if (hasTracingEnabled(options) && options.enableAutoPerformanceTracing) {
const hasTracingEnabled =
options.enableTracing ||
kahest marked this conversation as resolved.
Show resolved Hide resolved
typeof options.tracesSampleRate === 'number' ||
typeof options.tracesSampler === 'function';
if (hasTracingEnabled && options.enableAutoPerformanceTracing) {
integrations.push(new ReactNativeTracing());
}
if (options.enableCaptureFailedRequests) {
Expand Down
5 changes: 4 additions & 1 deletion src/js/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ export function init(passedOptions: ReactNativeOptions): void {
stackParser: stackParserFromStackParserOptions(passedOptions.stackParser || defaultStackParser),
beforeBreadcrumb: safeFactory(passedOptions.beforeBreadcrumb, { loggerMessage: 'The beforeBreadcrumb threw an error' }),
initialScope: safeFactory(passedOptions.initialScope, { loggerMessage: 'The initialScope threw an error' }),
tracesSampler: safeTracesSampler(passedOptions.tracesSampler),
};
if ('tracesSampler' in options) {
kahest marked this conversation as resolved.
Show resolved Hide resolved
options.tracesSampler = safeTracesSampler(options.tracesSampler);
}

if (!('environment' in options)) {
options.environment = getDefaultEnvironment();
}
Expand Down
1 change: 1 addition & 0 deletions test/profiling/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ function initTestClient(
const transportSendMock = jest.fn<ReturnType<Transport['send']>, Parameters<Transport['send']>>();
const options: Sentry.ReactNativeOptions = {
dsn: MOCK_DSN,
enableTracing: true,
_experiments: {
profilesSampleRate: 1,
},
Expand Down
22 changes: 22 additions & 0 deletions test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ describe('Tests the SDK functionality', () => {
return new ReactNativeTracing({ routingInstrumentation: nav });
};

it('Auto Performance is disabled by default', () => {
init({});

expect(autoPerformanceIsEnabled()).toBe(false);
});

it('Auto Performance is disabled when tracesSampleRate is set to undefined', () => {
init({
tracesSampleRate: undefined,
});

expect(autoPerformanceIsEnabled()).toBe(false);
});

it('Auto Performance is disabled when tracesSampler is set to undefined', () => {
init({
tracesSampler: undefined,
});

expect(autoPerformanceIsEnabled()).toBe(false);
});

it('Auto Performance is enabled when tracing is enabled (tracesSampler)', () => {
init({
tracesSampler: () => true,
Expand Down
Loading