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(replay): browserReplayIntegration should not be included by default #4270

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -41,6 +41,7 @@
- Remove duplicate HTTP Client Errors on iOS ([#4250](https://github.com/getsentry/sentry-react-native/pull/4250))
- Replay `maskAll*` set to `false` on iOS kept all masked ([#4257](https://github.com/getsentry/sentry-react-native/pull/4257))
- Add missing `getRootSpan`, `withActiveSpan` and `suppressTracing` exports from `@sentry/core`, and `SeverityLevel` export from `@sentry/types` ([#4254](https://github.com/getsentry/sentry-react-native/pull/4254), [#4260](https://github.com/getsentry/sentry-react-native/pull/4260))
- `browserReplayIntegration` should not be included by default ([#4270](https://github.com/getsentry/sentry-react-native/pull/4270))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i: Just a small detail to point that this change only reflects on web projects.

Suggested change
- `browserReplayIntegration` should not be included by default ([#4270](https://github.com/getsentry/sentry-react-native/pull/4270))
- `browserReplayIntegration` is no longer included by default on React Native Web ([#4270](https://github.com/getsentry/sentry-react-native/pull/4270))


### Dependencies

Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import type { Integration } from '@sentry/types';

import type { ReactNativeClientOptions } from '../options';
import { reactNativeTracingIntegration } from '../tracing';
import { isExpoGo, notWeb } from '../utils/environment';
import { isExpoGo, isWeb, notWeb } from '../utils/environment';
import {
appStartIntegration,
breadcrumbsIntegration,
browserApiErrorsIntegration,
browserGlobalHandlersIntegration,
browserLinkedErrorsIntegration,
browserReplayIntegration,
createNativeFramesIntegrations,
createReactNativeRewriteFrames,
debugSymbolicatorIntegration,
Expand Down Expand Up @@ -136,10 +135,13 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
(options._experiments && typeof options._experiments.replaysOnErrorSampleRate === 'number') ||
(options._experiments && typeof options._experiments.replaysSessionSampleRate === 'number')
) {
integrations.push(notWeb() ? mobileReplayIntegration() : browserReplayIntegration());
if (!notWeb()) {
if (isWeb()) {
// We can't create and add browserReplayIntegration as it overrides the users supplied one
// The browser replay integration works differently than the rest of default integrations
(options as BrowserOptions).replaysOnErrorSampleRate = options._experiments.replaysOnErrorSampleRate;
(options as BrowserOptions).replaysSessionSampleRate = options._experiments.replaysSessionSampleRate;
} else {
integrations.push(mobileReplayIntegration());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offtopic to this PR: Should we to filter out browserReplayIntegration by default on mobile projects if users adds this integration?

}
}

Expand Down
80 changes: 79 additions & 1 deletion packages/core/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { init, withScope } from '../src/js/sdk';
import type { ReactNativeTracingIntegration } from '../src/js/tracing';
import { REACT_NATIVE_TRACING_INTEGRATION_NAME, reactNativeTracingIntegration } from '../src/js/tracing';
import { makeNativeTransport } from '../src/js/transports/native';
import { getDefaultEnvironment, isExpoGo, notWeb } from '../src/js/utils/environment';
import { getDefaultEnvironment, isExpoGo, isWeb, notWeb } from '../src/js/utils/environment';
import { NATIVE } from './mockWrapper';
import { firstArg, secondArg } from './testutils';

Expand Down Expand Up @@ -663,6 +663,84 @@ describe('Tests the SDK functionality', () => {

expectIntegration('ExpoContext');
});

it('adds mobile replay integration when _experiments.replaysOnErrorSampleRate is set', () => {
init({
_experiments: {
replaysOnErrorSampleRate: 1.0,
},
});

expectIntegration('MobileReplay');
});

it('adds mobile replay integration when _experiments.replaysSessionSampleRate is set', () => {
init({
_experiments: {
replaysSessionSampleRate: 1.0,
},
});

expectIntegration('MobileReplay');
});

it('does not add mobile replay integration when no replay sample rates are set', () => {
init({
_experiments: {},
});

expectNotIntegration('MobileReplay');
});

it('does not add any replay integration when on web even with on error sample rate', () => {
(isWeb as jest.Mock).mockImplementation(() => true);
init({
_experiments: {
replaysOnErrorSampleRate: 1.0,
},
});

expectNotIntegration('Replay');
expectNotIntegration('MobileReplay');
});

it('does not add any replay integration when on web even with session sample rate', () => {
(isWeb as jest.Mock).mockImplementation(() => true);
init({
_experiments: {
replaysSessionSampleRate: 1.0,
},
});

expectNotIntegration('Replay');
expectNotIntegration('MobileReplay');
});

it('does not add any replay integration when on web', () => {
(isWeb as jest.Mock).mockImplementation(() => true);
init({});

expectNotIntegration('Replay');
expectNotIntegration('MobileReplay');
});

it('converts experimental replay options to standard web options when on web', () => {
(isWeb as jest.Mock).mockImplementation(() => true);
init({
_experiments: {
replaysOnErrorSampleRate: 0.5,
replaysSessionSampleRate: 0.1,
},
});

const actualOptions = usedOptions();
expect(actualOptions).toEqual(
expect.objectContaining({
replaysOnErrorSampleRate: 0.5,
replaysSessionSampleRate: 0.1,
}),
);
});
});

function expectIntegration(name: string): void {
Expand Down
Loading