Skip to content

Commit 5354ee5

Browse files
authored
feat(replay): Allow to configure maxReplayDuration (#8769)
This defaults to 60min, and is capped at max. 60min (=you cannot specify a longer max duration than 60min). Closes #8758
1 parent 1d64a06 commit 5354ee5

File tree

25 files changed

+157
-154
lines changed

25 files changed

+157
-154
lines changed

packages/browser-integration-tests/suites/replay/errors/errorsInSession/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ Sentry.init({
1919
return event;
2020
},
2121
integrations: [window.Replay],
22-
debug: true,
2322
});

packages/browser-integration-tests/suites/replay/largeMutations/mutationLimit/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Sentry.init({
1313
sampleRate: 0,
1414
replaysSessionSampleRate: 1.0,
1515
replaysOnErrorSampleRate: 0.0,
16-
debug: true,
1716

1817
integrations: [window.Replay],
1918
});

packages/browser-integration-tests/suites/replay/maxReplayDuration/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ window.Replay = new Sentry.Replay({
55
flushMinDelay: 200,
66
flushMaxDelay: 200,
77
minReplayDuration: 0,
8+
maxReplayDuration: 2000,
89
});
910

1011
Sentry.init({
@@ -19,5 +20,4 @@ Sentry.init({
1920
window.Replay._replay.timeouts = {
2021
sessionIdlePause: 1000, // this is usually 5min, but we want to test this with shorter times
2122
sessionIdleExpire: 2000, // this is usually 15min, but we want to test this with shorter times
22-
maxSessionLife: 2000, // default: 60min
2323
};

packages/browser-integration-tests/suites/replay/maxReplayDuration/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../utils/fixtures';
44
import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates';
55
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';
66

7-
const SESSION_MAX_AGE = 2000;
7+
const MAX_REPLAY_DURATION = 2000;
88

99
sentryTest('keeps track of max duration across reloads', async ({ getLocalTestPath, page }) => {
1010
if (shouldSkipReplayTest()) {
@@ -26,15 +26,15 @@ sentryTest('keeps track of max duration across reloads', async ({ getLocalTestPa
2626

2727
await page.goto(url);
2828

29-
await new Promise(resolve => setTimeout(resolve, SESSION_MAX_AGE / 2));
29+
await new Promise(resolve => setTimeout(resolve, MAX_REPLAY_DURATION / 2));
3030

3131
await page.reload();
3232
await page.click('#button1');
3333

3434
// After the second reload, we should have a new session (because we exceeded max age)
3535
const reqPromise3 = waitForReplayRequest(page, 0);
3636

37-
await new Promise(resolve => setTimeout(resolve, SESSION_MAX_AGE / 2 + 100));
37+
await new Promise(resolve => setTimeout(resolve, MAX_REPLAY_DURATION / 2 + 100));
3838

3939
void page.click('#button1');
4040
await page.evaluate(`Object.defineProperty(document, 'visibilityState', {

packages/browser-integration-tests/suites/replay/minReplayDuration/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Sentry.init({
1212
sampleRate: 0,
1313
replaysSessionSampleRate: 1.0,
1414
replaysOnErrorSampleRate: 0.0,
15-
debug: true,
1615

1716
integrations: [window.Replay],
1817
});

packages/browser-integration-tests/suites/replay/sessionExpiry/init.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ Sentry.init({
1212
sampleRate: 0,
1313
replaysSessionSampleRate: 1.0,
1414
replaysOnErrorSampleRate: 0.0,
15-
debug: true,
1615

1716
integrations: [window.Replay],
1817
});
1918

2019
window.Replay._replay.timeouts = {
2120
sessionIdlePause: 1000, // this is usually 5min, but we want to test this with shorter times
2221
sessionIdleExpire: 2000, // this is usually 15min, but we want to test this with shorter times
23-
maxSessionLife: 3600000, // default: 60min
2422
};

packages/browser-integration-tests/suites/replay/sessionInactive/init.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ Sentry.init({
1212
sampleRate: 0,
1313
replaysSessionSampleRate: 1.0,
1414
replaysOnErrorSampleRate: 0.0,
15-
debug: true,
1615

1716
integrations: [window.Replay],
1817
});
1918

2019
window.Replay._replay.timeouts = {
2120
sessionIdlePause: 1000, // this is usually 5min, but we want to test this with shorter times
2221
sessionIdleExpire: 900000, // defayult: 15min
23-
maxSessionLife: 3600000, // default: 60min
2422
};

packages/browser-integration-tests/suites/replay/sessionMaxAge/init.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ window.Replay = new Sentry.Replay({
55
flushMinDelay: 200,
66
flushMaxDelay: 200,
77
minReplayDuration: 0,
8+
maxReplayDuration: 4000,
89
});
910

1011
Sentry.init({
1112
dsn: 'https://[email protected]/1337',
1213
sampleRate: 0,
1314
replaysSessionSampleRate: 1.0,
1415
replaysOnErrorSampleRate: 0.0,
15-
debug: true,
1616

1717
integrations: [window.Replay],
1818
});
1919

2020
window.Replay._replay.timeouts = {
2121
sessionIdlePause: 300000, // default: 5min
2222
sessionIdleExpire: 900000, // default: 15min
23-
maxSessionLife: 4000, // this is usually 60min, but we want to test this with shorter times
2423
};

packages/browser-integration-tests/suites/replay/sessionMaxAge/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '../../../utils/replayHelpers';
1313

1414
// Session should be max. 4s long
15-
const SESSION_MAX_AGE = 4000;
15+
const MAX_REPLAY_DURATION = 4000;
1616

1717
/*
1818
The main difference between this and sessionExpiry test, is that here we wait for the overall time (4s)
@@ -58,7 +58,7 @@ sentryTest('handles session that exceeds max age', async ({ getLocalTestPath, pa
5858
// Wait for an incremental snapshot
5959
// Wait half of the session max age (after initial flush), but account for potentially slow runners
6060
const timePassed1 = Date.now() - startTimestamp;
61-
await new Promise(resolve => setTimeout(resolve, Math.max(SESSION_MAX_AGE / 2 - timePassed1, 0)));
61+
await new Promise(resolve => setTimeout(resolve, Math.max(MAX_REPLAY_DURATION / 2 - timePassed1, 0)));
6262
await page.click('#button1');
6363

6464
const req1 = await reqPromise1;
@@ -71,7 +71,7 @@ sentryTest('handles session that exceeds max age', async ({ getLocalTestPath, pa
7171

7272
// Wait for session to expire
7373
const timePassed2 = Date.now() - startTimestamp;
74-
await new Promise(resolve => setTimeout(resolve, Math.max(SESSION_MAX_AGE - timePassed2, 0)));
74+
await new Promise(resolve => setTimeout(resolve, Math.max(MAX_REPLAY_DURATION - timePassed2, 0)));
7575
await page.click('#button2');
7676

7777
const req2 = await reqPromise2;

packages/replay/src/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ export const SESSION_IDLE_PAUSE_DURATION = 300_000; // 5 minutes in ms
1717
// The idle limit for a session after which the session expires.
1818
export const SESSION_IDLE_EXPIRE_DURATION = 900_000; // 15 minutes in ms
1919

20-
// The maximum length of a session
21-
export const MAX_SESSION_LIFE = 3_600_000; // 60 minutes in ms
22-
2320
/** Default flush delays */
2421
export const DEFAULT_FLUSH_MIN_DELAY = 5_000;
2522
// XXX: Temp fix for our debounce logic where `maxWait` would never occur if it
@@ -50,3 +47,6 @@ export const REPLAY_MAX_EVENT_BUFFER_SIZE = 20_000_000; // ~20MB
5047
export const MIN_REPLAY_DURATION = 4_999;
5148
/* The max. allowed value that the minReplayDuration can be set to. */
5249
export const MIN_REPLAY_DURATION_LIMIT = 15_000;
50+
51+
/** The max. length of a replay. */
52+
export const MAX_REPLAY_DURATION = 3_600_000; // 60 minutes in ms;

0 commit comments

Comments
 (0)