Skip to content

Commit 117d38b

Browse files
fix(replay): browserReplayIntegration should not be included by default (#4270)
1 parent 86bf3b5 commit 117d38b

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-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

+96
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,102 @@ 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(
698+
expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]),
699+
);
700+
});
701+
702+
it('does not add any replay integration when on web even with session sample rate', () => {
703+
(notWeb as jest.Mock).mockImplementation(() => false);
704+
init({
705+
_experiments: {
706+
replaysSessionSampleRate: 1.0,
707+
},
708+
});
709+
710+
const actualOptions = usedOptions();
711+
const actualIntegrations = actualOptions?.integrations;
712+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'Replay' })]));
713+
expect(actualIntegrations).toEqual(
714+
expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]),
715+
);
716+
});
717+
718+
it('does not add any replay integration when on web', () => {
719+
(notWeb as jest.Mock).mockImplementation(() => false);
720+
init({});
721+
722+
const actualOptions = usedOptions();
723+
const actualIntegrations = actualOptions?.integrations;
724+
expect(actualIntegrations).toEqual(expect.not.arrayContaining([expect.objectContaining({ name: 'Replay' })]));
725+
expect(actualIntegrations).toEqual(
726+
expect.not.arrayContaining([expect.objectContaining({ name: 'MobileReplay' })]),
727+
);
728+
});
729+
730+
it('converts experimental replay options to standard web options when on web', () => {
731+
(notWeb as jest.Mock).mockImplementation(() => false);
732+
init({
733+
_experiments: {
734+
replaysOnErrorSampleRate: 0.5,
735+
replaysSessionSampleRate: 0.1,
736+
},
737+
});
738+
739+
const actualOptions = usedOptions();
740+
expect(actualOptions).toEqual(
741+
expect.objectContaining({
742+
replaysOnErrorSampleRate: 0.5,
743+
replaysSessionSampleRate: 0.1,
744+
}),
745+
);
746+
});
651747
});
652748

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

0 commit comments

Comments
 (0)