diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ffddb833..831ca8df1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ### Changes +- `tracePropagationTargets` defaults to all targets on mobile and same origin on the web ([#4083](https://github.com/getsentry/sentry-react-native/pull/4083)) - Move `_experiments.profilesSampleRate` to `profilesSampleRate` root options object [#3851](https://github.com/getsentry/sentry-react-native/pull/3851)) - Add Android Logger when new frame event is not emitted ([#4081](https://github.com/getsentry/sentry-react-native/pull/4081)) - React Native Tracing Deprecations ([#4073](https://github.com/getsentry/sentry-react-native/pull/4073)) diff --git a/packages/core/src/js/tracing/reactnativetracing.ts b/packages/core/src/js/tracing/reactnativetracing.ts index 996c85c70..b6ee5e178 100644 --- a/packages/core/src/js/tracing/reactnativetracing.ts +++ b/packages/core/src/js/tracing/reactnativetracing.ts @@ -3,6 +3,7 @@ import { instrumentOutgoingRequests } from '@sentry/browser'; import { getClient } from '@sentry/core'; import type { Client, Event, Integration, StartSpanOptions } from '@sentry/types'; +import { isWeb } from '../utils/environment'; import { addDefaultOpForSpanFrom, defaultIdleOptions } from './span'; export const INTEGRATION_NAME = 'ReactNativeTracing'; @@ -60,7 +61,12 @@ export interface ReactNativeTracingOptions { shouldCreateSpanForRequest?(this: void, url: string): boolean; } -const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\/(?!\/)/]; +function getDefaultTracePropagationTargets(): RegExp[] | undefined { + if (isWeb()) { + return undefined; + } + return [/.*/]; +} export const defaultReactNativeTracingOptions: ReactNativeTracingOptions = { traceFetch: true, @@ -98,7 +104,7 @@ export const reactNativeTracingIntegration = ( traceFetch: finalOptions.traceFetch, traceXHR: finalOptions.traceXHR, shouldCreateSpanForRequest: finalOptions.shouldCreateSpanForRequest, - tracePropagationTargets: client.getOptions().tracePropagationTargets || DEFAULT_TRACE_PROPAGATION_TARGETS, + tracePropagationTargets: client.getOptions().tracePropagationTargets || getDefaultTracePropagationTargets(), }); }; diff --git a/packages/core/src/js/utils/environment.ts b/packages/core/src/js/utils/environment.ts index 19b120a56..214532b03 100644 --- a/packages/core/src/js/utils/environment.ts +++ b/packages/core/src/js/utils/environment.ts @@ -53,6 +53,11 @@ export function getExpoSdkVersion(): string | undefined { return expoSdkVersion; } +/** Checks if the current platform is web */ +export function isWeb(): boolean { + return Platform.OS === 'web'; +} + /** Checks if the current platform is not web */ export function notWeb(): boolean { return Platform.OS !== 'web'; diff --git a/packages/core/test/tracing/reactnativetracing.test.ts b/packages/core/test/tracing/reactnativetracing.test.ts index 2b049f5ed..3605a25f7 100644 --- a/packages/core/test/tracing/reactnativetracing.test.ts +++ b/packages/core/test/tracing/reactnativetracing.test.ts @@ -1,12 +1,3 @@ -jest.mock('@sentry/utils', () => { - const originalUtils = jest.requireActual('@sentry/utils'); - - return { - ...originalUtils, - timestampInSeconds: jest.fn(originalUtils.timestampInSeconds), - }; -}); - import * as SentryBrowser from '@sentry/browser'; import type { Event } from '@sentry/types'; @@ -31,7 +22,18 @@ jest.mock('../../src/js/tracing/utils', () => { }; }); +jest.mock('@sentry/utils', () => { + const originalUtils = jest.requireActual('@sentry/utils'); + + return { + ...originalUtils, + timestampInSeconds: jest.fn(originalUtils.timestampInSeconds), + }; +}); + +jest.mock('../../src/js/utils/environment'); import { reactNativeTracingIntegration } from '../../src/js/tracing/reactnativetracing'; +import { isWeb } from '../../src/js/utils/environment'; import type { TestClient } from '../mocks/client'; import { setupTestClient } from '../mocks/client'; @@ -66,7 +68,24 @@ describe('ReactNativeTracing', () => { ); }); - it('uses defaults', () => { + it('uses mobile defaults', () => { + (isWeb as jest.MockedFunction).mockReturnValue(false); + const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); + setupTestClient({ + enableStallTracking: false, + integrations: [reactNativeTracingIntegration()], + }); + + expect(instrumentOutgoingRequests).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + tracePropagationTargets: [/.*/], + }), + ); + }); + + it('uses web defaults', () => { + (isWeb as jest.MockedFunction).mockReturnValue(true); const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests'); setupTestClient({ enableStallTracking: false, @@ -76,7 +95,7 @@ describe('ReactNativeTracing', () => { expect(instrumentOutgoingRequests).toBeCalledWith( expect.anything(), expect.objectContaining({ - tracePropagationTargets: ['localhost', /^\/(?!\/)/], + tracePropagationTargets: undefined, }), ); });