Skip to content

Commit 37ab937

Browse files
fix(replay): browserReplayIntegration should not be included by default (#4270)
1 parent 3b989fa commit 37ab937

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- Skips development server spans ([#4271](https://github.com/getsentry/sentry-react-native/pull/4271))
4545
- Execute `DebugSymbolicator` after `RewriteFrames` to avoid overwrites by default ([#4285](https://github.com/getsentry/sentry-react-native/pull/4285))
4646
- If custom `RewriteFrames` is provided the order changes
47+
- `browserReplayIntegration` is no longer included by default on React Native Web ([#4270](https://github.com/getsentry/sentry-react-native/pull/4270))
4748

4849
### Dependencies
4950

packages/core/src/js/integrations/default.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import type { Integration } from '@sentry/types';
44

55
import type { ReactNativeClientOptions } from '../options';
66
import { reactNativeTracingIntegration } from '../tracing';
7-
import { isExpoGo, notWeb } from '../utils/environment';
7+
import { isExpoGo, isWeb, notWeb } from '../utils/environment';
88
import {
99
appStartIntegration,
1010
breadcrumbsIntegration,
1111
browserApiErrorsIntegration,
1212
browserGlobalHandlersIntegration,
1313
browserLinkedErrorsIntegration,
14-
browserReplayIntegration,
1514
createNativeFramesIntegrations,
1615
createReactNativeRewriteFrames,
1716
debugSymbolicatorIntegration,
@@ -132,10 +131,13 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
132131
(options._experiments && typeof options._experiments.replaysOnErrorSampleRate === 'number') ||
133132
(options._experiments && typeof options._experiments.replaysSessionSampleRate === 'number')
134133
) {
135-
integrations.push(notWeb() ? mobileReplayIntegration() : browserReplayIntegration());
136-
if (!notWeb()) {
134+
if (isWeb()) {
135+
// We can't create and add browserReplayIntegration as it overrides the users supplied one
136+
// The browser replay integration works differently than the rest of default integrations
137137
(options as BrowserOptions).replaysOnErrorSampleRate = options._experiments.replaysOnErrorSampleRate;
138138
(options as BrowserOptions).replaysSessionSampleRate = options._experiments.replaysSessionSampleRate;
139+
} else {
140+
integrations.push(mobileReplayIntegration());
139141
}
140142
}
141143

packages/core/test/sdk.test.ts

+79-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { init, withScope } from '../src/js/sdk';
1515
import type { ReactNativeTracingIntegration } from '../src/js/tracing';
1616
import { REACT_NATIVE_TRACING_INTEGRATION_NAME, reactNativeTracingIntegration } from '../src/js/tracing';
1717
import { makeNativeTransport } from '../src/js/transports/native';
18-
import { getDefaultEnvironment, isExpoGo, notWeb } from '../src/js/utils/environment';
18+
import { getDefaultEnvironment, isExpoGo, isWeb, notWeb } from '../src/js/utils/environment';
1919
import { NATIVE } from './mockWrapper';
2020
import { firstArg, secondArg } from './testutils';
2121

@@ -854,6 +854,84 @@ describe('Tests the SDK functionality', () => {
854854

855855
expectIntegration('ExpoContext');
856856
});
857+
858+
it('adds mobile replay integration when _experiments.replaysOnErrorSampleRate is set', () => {
859+
init({
860+
_experiments: {
861+
replaysOnErrorSampleRate: 1.0,
862+
},
863+
});
864+
865+
expectIntegration('MobileReplay');
866+
});
867+
868+
it('adds mobile replay integration when _experiments.replaysSessionSampleRate is set', () => {
869+
init({
870+
_experiments: {
871+
replaysSessionSampleRate: 1.0,
872+
},
873+
});
874+
875+
expectIntegration('MobileReplay');
876+
});
877+
878+
it('does not add mobile replay integration when no replay sample rates are set', () => {
879+
init({
880+
_experiments: {},
881+
});
882+
883+
expectNotIntegration('MobileReplay');
884+
});
885+
886+
it('does not add any replay integration when on web even with on error sample rate', () => {
887+
(isWeb as jest.Mock).mockImplementation(() => true);
888+
init({
889+
_experiments: {
890+
replaysOnErrorSampleRate: 1.0,
891+
},
892+
});
893+
894+
expectNotIntegration('Replay');
895+
expectNotIntegration('MobileReplay');
896+
});
897+
898+
it('does not add any replay integration when on web even with session sample rate', () => {
899+
(isWeb as jest.Mock).mockImplementation(() => true);
900+
init({
901+
_experiments: {
902+
replaysSessionSampleRate: 1.0,
903+
},
904+
});
905+
906+
expectNotIntegration('Replay');
907+
expectNotIntegration('MobileReplay');
908+
});
909+
910+
it('does not add any replay integration when on web', () => {
911+
(isWeb as jest.Mock).mockImplementation(() => true);
912+
init({});
913+
914+
expectNotIntegration('Replay');
915+
expectNotIntegration('MobileReplay');
916+
});
917+
918+
it('converts experimental replay options to standard web options when on web', () => {
919+
(isWeb as jest.Mock).mockImplementation(() => true);
920+
init({
921+
_experiments: {
922+
replaysOnErrorSampleRate: 0.5,
923+
replaysSessionSampleRate: 0.1,
924+
},
925+
});
926+
927+
const actualOptions = usedOptions();
928+
expect(actualOptions).toEqual(
929+
expect.objectContaining({
930+
replaysOnErrorSampleRate: 0.5,
931+
replaysSessionSampleRate: 0.1,
932+
}),
933+
);
934+
});
857935
});
858936

859937
function expectIntegration(name: string): void {

0 commit comments

Comments
 (0)