Skip to content

Commit 5f56c92

Browse files
fix(replay): browserReplayIntegration should not be included by default (#4308)
1 parent 8ecf121 commit 5f56c92

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- `browserReplayIntegration` is no longer included by default on React Native Web ([#4270](https://github.com/getsentry/sentry-react-native/pull/4270), [#4308](https://github.com/getsentry/sentry-react-native/pull/4308))
8+
39
## 5.35.0
410

511
### Fixes

src/js/integrations/default.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
browserApiErrorsIntegration,
1111
browserGlobalHandlersIntegration,
1212
browserLinkedErrorsIntegration,
13-
browserReplayIntegration,
1413
debugSymbolicatorIntegration,
1514
dedupeIntegration,
1615
deviceContextIntegration,
@@ -120,10 +119,13 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
120119
(options._experiments && typeof options._experiments.replaysOnErrorSampleRate === 'number') ||
121120
(options._experiments && typeof options._experiments.replaysSessionSampleRate === 'number')
122121
) {
123-
integrations.push(notWeb() ? mobileReplayIntegration() : browserReplayIntegration());
124122
if (!notWeb()) {
123+
// We can't create and add browserReplayIntegration as it overrides the users supplied one
124+
// The browser replay integration works differently than the rest of default integrations
125125
(options as BrowserOptions).replaysOnErrorSampleRate = options._experiments.replaysOnErrorSampleRate;
126126
(options as BrowserOptions).replaysSessionSampleRate = options._experiments.replaysSessionSampleRate;
127+
} else {
128+
integrations.push(mobileReplayIntegration());
127129
}
128130
}
129131

test/sdk.test.ts

+90
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,96 @@ describe('Tests the SDK functionality', () => {
648648

649649
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'ExpoContext' })]));
650650
});
651+
652+
it('adds mobile replay integration when _experiments.replaysOnErrorSampleRate is set', () => {
653+
init({
654+
_experiments: {
655+
replaysOnErrorSampleRate: 1.0,
656+
},
657+
});
658+
659+
const actualOptions = usedOptions();
660+
const actualIntegrations = actualOptions?.integrations;
661+
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]));
662+
});
663+
664+
it('adds mobile replay integration when _experiments.replaysSessionSampleRate is set', () => {
665+
init({
666+
_experiments: {
667+
replaysSessionSampleRate: 1.0,
668+
},
669+
});
670+
671+
const actualOptions = usedOptions();
672+
const actualIntegrations = actualOptions?.integrations;
673+
expect(actualIntegrations).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]));
674+
});
675+
676+
it('does not add mobile replay integration when no replay sample rates are set', () => {
677+
init({
678+
_experiments: {},
679+
});
680+
681+
const actualOptions = usedOptions();
682+
const actualIntegrations = actualOptions?.integrations;
683+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]));
684+
});
685+
686+
it('does not add any replay integration when on web even with on error sample rate', () => {
687+
(notWeb as jest.Mock).mockImplementation(() => false);
688+
init({
689+
_experiments: {
690+
replaysOnErrorSampleRate: 1.0,
691+
},
692+
});
693+
694+
const actualOptions = usedOptions();
695+
const actualIntegrations = actualOptions?.integrations;
696+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'Replay' })]));
697+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]));
698+
});
699+
700+
it('does not add any replay integration when on web even with session sample rate', () => {
701+
(notWeb as jest.Mock).mockImplementation(() => false);
702+
init({
703+
_experiments: {
704+
replaysSessionSampleRate: 1.0,
705+
},
706+
});
707+
708+
const actualOptions = usedOptions();
709+
const actualIntegrations = actualOptions?.integrations;
710+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'Replay' })]));
711+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]));
712+
});
713+
714+
it('does not add any replay integration when on web', () => {
715+
(notWeb as jest.Mock).mockImplementation(() => false);
716+
init({});
717+
718+
const actualOptions = usedOptions();
719+
const actualIntegrations = actualOptions?.integrations;
720+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'Replay' })]));
721+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]));
722+
});
723+
724+
it('converts experimental replay options to standard web options when on web', () => {
725+
(notWeb as jest.Mock).mockImplementation(() => false);
726+
init({
727+
_experiments: {
728+
replaysOnErrorSampleRate: 0.5,
729+
replaysSessionSampleRate: 0.1,
730+
},
731+
});
732+
733+
const actualOptions = usedOptions();
734+
expect(actualOptions).toEqual(
735+
expect.objectContaining({
736+
replaysOnErrorSampleRate: 0.5,
737+
replaysSessionSampleRate: 0.1,
738+
}),
739+
);
740+
});
651741
});
652742

653743
function createMockedIntegration({ name }: { name?: string } = {}): Integration {

0 commit comments

Comments
 (0)