Skip to content

ref(replay): Log warning if sample rates are all undefined #6959

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

Merged
merged 5 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions packages/replay/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
// Client is not available in constructor, so we need to wait until setupOnce
this._loadReplayOptionsFromClient();

if (!this._options.sessionSampleRate && !this._options.errorSampleRate) {
// eslint-disable-next-line no-console
console.warn('Replay is disabled because both `replaysSessionSampleRate` and `replaysOnErrorSampleRate` are 0');
}

this._replay = new ReplayContainer({
options: this._options,
recordingOptions: this._recordingOptions,
Expand Down
12 changes: 6 additions & 6 deletions packages/replay/test/integration/integrationSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ describe('Integration | integrationSettings', () => {
expect(mockConsole).toBeCalledTimes(1);
});

it('works with defining 0 in integration', async () => {
it('works with defining 0 in integration but logs warnings', async () => {
const { replay } = await mockSdk({
replayOptions: { sessionSampleRate: 0 },
sentryOptions: { replaysSessionSampleRate: undefined },
});

expect(replay.getOptions().sessionSampleRate).toBe(0);
expect(mockConsole).toBeCalledTimes(1);
expect(mockConsole).toBeCalledTimes(2);
});

it('works with defining settings in SDK', async () => {
Expand All @@ -70,11 +70,11 @@ describe('Integration | integrationSettings', () => {
expect(mockConsole).toBeCalledTimes(0);
});

it('works with defining 0 in SDK', async () => {
it('works with defining 0 in SDK but a warning is logged', async () => {
const { replay } = await mockSdk({ sentryOptions: { replaysSessionSampleRate: 0 }, replayOptions: {} });

expect(replay.getOptions().sessionSampleRate).toBe(0);
expect(mockConsole).toBeCalledTimes(0);
expect(mockConsole).toBeCalledTimes(1);
});

it('SDK option takes precedence', async () => {
Expand All @@ -87,14 +87,14 @@ describe('Integration | integrationSettings', () => {
expect(mockConsole).toBeCalledTimes(1);
});

it('SDK option takes precedence even when 0', async () => {
it('SDK option takes precedence even when 0 but warnings are logged', async () => {
const { replay } = await mockSdk({
sentryOptions: { replaysSessionSampleRate: 0 },
replayOptions: { sessionSampleRate: 0.1 },
});

expect(replay.getOptions().sessionSampleRate).toBe(0);
expect(mockConsole).toBeCalledTimes(1);
expect(mockConsole).toBeCalledTimes(2);
});
});

Expand Down
2 changes: 2 additions & 0 deletions packages/replay/test/integration/sampling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ useFakeTimers();

describe('Integration | sampling', () => {
it('does nothing if not sampled', async () => {
const mockConsole = jest.spyOn(console, 'warn').mockImplementation(jest.fn());
const { record: mockRecord } = mockRrweb();
const { replay } = await mockSdk({
replayOptions: {
Expand All @@ -29,5 +30,6 @@ describe('Integration | sampling', () => {
);
expect(mockRecord).not.toHaveBeenCalled();
expect(spyAddListeners).not.toHaveBeenCalled();
expect(mockConsole).toBeCalledTimes(1);
});
});
2 changes: 1 addition & 1 deletion packages/replay/test/mocks/mockSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function mockSdk({ replayOptions, sentryOptions, autoStart = true }
integrations: [replayIntegration],
});

// Instead of `setupOnce`, which is tricky to test, we call this manually here
// Instead of `setupOnce`, which is tricky to test, we call this manually here)
replayIntegration['_setup']();

if (autoStart) {
Expand Down