Skip to content

Commit f82ac81

Browse files
authored
feat(replay): Deprecate old replay sample rate configs (#6414)
1 parent 21f1e3d commit f82ac81

10 files changed

+249
-151
lines changed

packages/replay/src/index.ts

+30-6
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ export class Replay implements Integration {
146146
initialFlushDelay = 5000,
147147
stickySession = true,
148148
useCompression = true,
149-
sessionSampleRate = DEFAULT_SESSION_SAMPLE_RATE,
150-
errorSampleRate = DEFAULT_ERROR_SAMPLE_RATE,
149+
sessionSampleRate,
150+
errorSampleRate,
151151
maskAllText = true,
152152
maskAllInputs = true,
153153
blockAllMedia = true,
@@ -171,13 +171,37 @@ export class Replay implements Integration {
171171
flushMaxDelay,
172172
stickySession,
173173
initialFlushDelay,
174-
sessionSampleRate,
175-
errorSampleRate,
174+
sessionSampleRate: DEFAULT_SESSION_SAMPLE_RATE,
175+
errorSampleRate: DEFAULT_ERROR_SAMPLE_RATE,
176176
useCompression,
177177
maskAllText,
178178
blockAllMedia,
179179
};
180180

181+
if (typeof sessionSampleRate === 'number') {
182+
// eslint-disable-next-line
183+
console.warn(
184+
`[Replay] You are passing \`sessionSampleRate\` to the Replay integration.
185+
This option is deprecated and will be removed soon.
186+
Instead, configure \`replaysSessionSampleRate\` directly in the SDK init options, e.g.:
187+
Sentry.init({ replaysSessionSampleRate: ${sessionSampleRate} })`,
188+
);
189+
190+
this.options.sessionSampleRate = sessionSampleRate;
191+
}
192+
193+
if (typeof errorSampleRate === 'number') {
194+
// eslint-disable-next-line
195+
console.warn(
196+
`[Replay] You are passing \`errorSampleRate\` to the Replay integration.
197+
This option is deprecated and will be removed soon.
198+
Instead, configure \`replaysOnErrorSampleRate\` directly in the SDK init options, e.g.:
199+
Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
200+
);
201+
202+
this.options.errorSampleRate = errorSampleRate;
203+
}
204+
181205
if (this.options.maskAllText) {
182206
// `maskAllText` is a more user friendly option to configure
183207
// `maskTextSelector`. This means that all nodes will have their text
@@ -1354,11 +1378,11 @@ export class Replay implements Integration {
13541378
const client = getCurrentHub().getClient() as BrowserClient | undefined;
13551379
const opt = client && (client.getOptions() as BrowserOptions | undefined);
13561380

1357-
if (opt && opt.replaysSessionSampleRate) {
1381+
if (opt && typeof opt.replaysSessionSampleRate === 'number') {
13581382
this.options.sessionSampleRate = opt.replaysSessionSampleRate;
13591383
}
13601384

1361-
if (opt && opt.replaysOnErrorSampleRate) {
1385+
if (opt && typeof opt.replaysOnErrorSampleRate === 'number') {
13621386
this.options.errorSampleRate = opt.replaysOnErrorSampleRate;
13631387
}
13641388
}

packages/replay/src/types.ts

-16
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,6 @@ export interface ReplayPluginOptions extends SessionOptions {
103103
*/
104104
useCompression: boolean;
105105

106-
/**
107-
* Only capture replays when an error happens
108-
*
109-
* @deprecated
110-
* @see errorSampleRate
111-
*/
112-
captureOnlyOnError?: boolean;
113-
114-
/**
115-
* The sample rate for replays. 1.0 will record all replays, 0 will record none.
116-
*
117-
* @deprecated
118-
* @see sessionSampleRate
119-
*/
120-
replaysSamplingRate?: number;
121-
122106
/**
123107
* Mask all text in recordings. All text will be replaced with asterisks by default.
124108
*/

packages/replay/test/mocks/index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { getCurrentHub } from '@sentry/core';
22

3-
import { ReplayConfiguration } from '../../src/types';
43
import { Replay } from './../../src';
54
import { BASE_TIMESTAMP, RecordMock } from './../index';
65
import { DomHandler, MockTransportSend } from './../types';
6+
import { MockSdkParams } from './mockSdk';
77

8-
export async function resetSdkMock(options?: ReplayConfiguration): Promise<{
8+
export async function resetSdkMock({ replayOptions, sentryOptions }: MockSdkParams): Promise<{
99
domHandler: DomHandler;
1010
mockRecord: RecordMock;
1111
mockTransportSend: MockTransportSend;
@@ -38,9 +38,8 @@ export async function resetSdkMock(options?: ReplayConfiguration): Promise<{
3838

3939
const { mockSdk } = await import('./mockSdk');
4040
const { replay } = await mockSdk({
41-
replayOptions: {
42-
...options,
43-
},
41+
replayOptions,
42+
sentryOptions,
4443
});
4544

4645
const mockTransportSend = getCurrentHub()?.getClient()?.getTransport()?.send as MockTransportSend;

packages/replay/test/mocks/mockSdk.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Envelope, Transport } from '@sentry/types';
44
import { Replay as ReplayClass } from '../../src';
55
import { ReplayConfiguration } from '../../src/types';
66

7-
interface MockSdkParams {
7+
export interface MockSdkParams {
88
replayOptions?: ReplayConfiguration;
99
sentryOptions?: BrowserOptions;
1010
}
@@ -34,25 +34,25 @@ class MockTransport implements Transport {
3434
}
3535
}
3636

37-
export async function mockSdk({
38-
replayOptions = {
37+
export async function mockSdk({ replayOptions, sentryOptions }: MockSdkParams = {}): Promise<{ replay: ReplayClass }> {
38+
const { init } = jest.requireActual('@sentry/browser');
39+
40+
const { Replay } = await import('../../src');
41+
const replay = new Replay({
3942
stickySession: false,
40-
sessionSampleRate: 1.0,
41-
errorSampleRate: 0.0,
42-
},
43-
sentryOptions = {
43+
...replayOptions,
44+
});
45+
46+
init({
4447
dsn: 'https://[email protected]/1',
4548
autoSessionTracking: false,
4649
sendClientReports: false,
4750
transport: () => new MockTransport(),
48-
},
49-
}: MockSdkParams = {}): Promise<{ replay: ReplayClass }> {
50-
const { init } = jest.requireActual('@sentry/browser');
51-
52-
const { Replay } = await import('../../src');
53-
const replay = new Replay(replayOptions);
54-
55-
init({ ...sentryOptions, integrations: [replay] });
51+
replaysSessionSampleRate: 1.0,
52+
replaysOnErrorSampleRate: 0.0,
53+
...sentryOptions,
54+
integrations: [replay],
55+
});
5656

5757
// setupOnce is only called the first time, so we ensure to re-parse the options every time
5858
replay['_loadReplayOptionsFromClient']();

packages/replay/test/unit/index-errorSampleRate.test.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ describe('Replay (errorSampleRate)', () => {
2525

2626
beforeEach(async () => {
2727
({ mockRecord, mockTransportSend, domHandler, replay } = await resetSdkMock({
28-
errorSampleRate: 1.0,
29-
sessionSampleRate: 0.0,
30-
stickySession: true,
28+
replayOptions: {
29+
stickySession: true,
30+
},
31+
sentryOptions: {
32+
replaysSessionSampleRate: 0.0,
33+
replaysOnErrorSampleRate: 1.0,
34+
},
3135
}));
32-
// jest.advanceTimersToNextTimer();
3336
});
3437

3538
afterEach(async () => {
@@ -322,7 +325,9 @@ describe('Replay (errorSampleRate)', () => {
322325
`{"segmentId":0,"id":"fd09adfc4117477abc8de643e5a5798a","sampled":"error","started":${BASE_TIMESTAMP},"lastActivity":${BASE_TIMESTAMP}}`,
323326
);
324327
({ mockRecord, mockTransportSend, replay } = await resetSdkMock({
325-
stickySession: true,
328+
replayOptions: {
329+
stickySession: true,
330+
},
326331
}));
327332
replay.start();
328333

packages/replay/test/unit/index-handleGlobalEvent.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ let replay: Replay;
1212

1313
beforeEach(async () => {
1414
({ replay } = await resetSdkMock({
15-
errorSampleRate: 1.0,
16-
sessionSampleRate: 0.0,
17-
stickySession: false,
15+
replayOptions: {
16+
stickySession: false,
17+
},
18+
sentryOptions: {
19+
replaysSessionSampleRate: 0.0,
20+
replaysOnErrorSampleRate: 1.0,
21+
},
1822
}));
1923
});
2024

@@ -106,10 +110,7 @@ it('strips out dropped events from errorIds', async () => {
106110
});
107111

108112
it('tags errors and transactions with replay id for session samples', async () => {
109-
({ replay } = await resetSdkMock({
110-
sessionSampleRate: 1.0,
111-
errorSampleRate: 0,
112-
}));
113+
({ replay } = await resetSdkMock({}));
113114
replay.start();
114115
const transaction = Transaction();
115116
const error = Error();

0 commit comments

Comments
 (0)