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

feat: tracePropagationTargets to all targets on mobile and same origin on the web #4083

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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))
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/js/tracing/reactnativetracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
});
};

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/js/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
41 changes: 30 additions & 11 deletions packages/core/test/tracing/reactnativetracing.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';

Expand Down Expand Up @@ -66,7 +68,24 @@ describe('ReactNativeTracing', () => {
);
});

it('uses defaults', () => {
it('uses mobile defaults', () => {
(isWeb as jest.MockedFunction<typeof isWeb>).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<typeof isWeb>).mockReturnValue(true);
const instrumentOutgoingRequests = jest.spyOn(SentryBrowser, 'instrumentOutgoingRequests');
setupTestClient({
enableStallTracking: false,
Expand All @@ -76,7 +95,7 @@ describe('ReactNativeTracing', () => {
expect(instrumentOutgoingRequests).toBeCalledWith(
expect.anything(),
expect.objectContaining({
tracePropagationTargets: ['localhost', /^\/(?!\/)/],
tracePropagationTargets: undefined,
}),
);
});
Expand Down
Loading