Skip to content

Commit b5f55a3

Browse files
authored
fix(replay): Ensure we debounce flush if replay too short (#8716)
This fix ensures that if we try to flush a replay that is too short, we will debounce flush it again after the min. duration is reached.
1 parent e586397 commit b5f55a3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/replay/src/replay.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1132,11 +1132,18 @@ export class ReplayContainer implements ReplayContainerInterface {
11321132

11331133
// If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
11341134
// This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
1135-
if (duration < this._options.minReplayDuration || duration > this.timeouts.maxSessionLife + 5_000) {
1135+
const tooShort = duration < this._options.minReplayDuration;
1136+
const tooLong = duration > this.timeouts.maxSessionLife + 5_000;
1137+
if (tooShort || tooLong) {
11361138
logInfo(
1137-
`[Replay] Session duration (${Math.floor(duration / 1000)}s) is too short or too long, not sending replay.`,
1138-
this._options._experiments.traceInternals,
1139+
`[Replay] Session duration (${Math.floor(duration / 1000)}s) is too ${
1140+
tooShort ? 'short' : 'long'
1141+
}, not sending replay.`,
11391142
);
1143+
1144+
if (tooShort) {
1145+
this._debouncedFlush();
1146+
}
11401147
return;
11411148
}
11421149

packages/replay/test/integration/flush.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ describe('Integration | flush', () => {
280280

281281
expect(mockFlush).toHaveBeenCalledTimes(1);
282282
expect(mockSendReplay).toHaveBeenCalledTimes(0);
283+
284+
// it should re-schedule the flush, so once the min. duration is reached it should automatically send it
285+
await advanceTimers(100_000 - DEFAULT_FLUSH_MIN_DELAY);
286+
287+
expect(mockFlush).toHaveBeenCalledTimes(20);
288+
expect(mockSendReplay).toHaveBeenCalledTimes(1);
283289
});
284290

285291
it('does not flush if session is too long', async () => {

0 commit comments

Comments
 (0)