Skip to content
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 @@ -44,6 +44,7 @@
- Skips development server spans ([#4271](https://github.com/getsentry/sentry-react-native/pull/4271))
- Execute `DebugSymbolicator` after `RewriteFrames` to avoid overwrites by default ([#4285](https://github.com/getsentry/sentry-react-native/pull/4285))
- If custom `RewriteFrames` is provided the order changes
- `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 @@ -132,10 +131,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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's unpredictable behavior we should avoid, if they added it we should respect it.

Sidenote: The integration check if it can run, it not it will gracefully disables itself.

}
}

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 @@ -15,7 +15,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 @@ -854,6 +854,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