Skip to content

fix(replay): Ensure we debounce flush if replay too short #8716

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 1 commit into from
Aug 3, 2023
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
13 changes: 10 additions & 3 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,11 +1132,18 @@ export class ReplayContainer implements ReplayContainerInterface {

// If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
// This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
if (duration < this._options.minReplayDuration || duration > this.timeouts.maxSessionLife + 5_000) {
const tooShort = duration < this._options.minReplayDuration;
const tooLong = duration > this.timeouts.maxSessionLife + 5_000;
if (tooShort || tooLong) {
logInfo(
`[Replay] Session duration (${Math.floor(duration / 1000)}s) is too short or too long, not sending replay.`,
this._options._experiments.traceInternals,
`[Replay] Session duration (${Math.floor(duration / 1000)}s) is too ${
tooShort ? 'short' : 'long'
}, not sending replay.`,
);

if (tooShort) {
this._debouncedFlush();
}
return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/replay/test/integration/flush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ describe('Integration | flush', () => {

expect(mockFlush).toHaveBeenCalledTimes(1);
expect(mockSendReplay).toHaveBeenCalledTimes(0);

// it should re-schedule the flush, so once the min. duration is reached it should automatically send it
await advanceTimers(100_000 - DEFAULT_FLUSH_MIN_DELAY);

expect(mockFlush).toHaveBeenCalledTimes(20);
expect(mockSendReplay).toHaveBeenCalledTimes(1);
});

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