Session Replay: introduce ScheduledStreamCapture (streaming leading chunks + precise end-of-window export) to survive multiple rrweb checkouts#1371
Conversation
some renames wat rename abort to discard dont remove import
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a streaming capture strategy for session replay to replace single-shot leading capture. The new approach exports and sends replay data in sequential chunks during the postDuration window to prevent event loss when rrweb performs periodic checkouts that could overwrite early events.
- Implements
ScheduledStreamCaptureclass for streaming chunk captures at safe intervals - Replaces
ScheduledCapturewithScheduledStreamCapturein the replay manager - Updates tests to accommodate the new streaming behavior with multiple chunk exports instead of single exports
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/browser/replay/scheduledStreamCapture.js |
New streaming controller that exports chunks periodically and manages sequential sending |
src/browser/replay/replayManager.js |
Integrates the new streaming capture controller and adjusts error logging |
test/replay/integration/replayManager.bufferIndex.test.js |
Adds assertion to verify trigger existence |
test/replay/integration/replayManager.bufferIndex.checkoutResilience.test.js |
Updates tests to handle multiple chunk exports and adds new deterministic test case |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| schedule(replayId, occurrenceUuid, postDuration) { | ||
| const startTime = Date.now(); | ||
| const endAt = startTime + postDuration * 1000; | ||
| const chunkMs = this._recorder.checkoutEveryNms(); |
There was a problem hiding this comment.
For now, I'm running this at exactly checkoutEveryNms and it seems to work fine, I did some testing with a multiplier k ≈ 0.6...0.8, but it resulted in more chunks, ergo more post calls.
Streaming leading chunks + precise end-of-window export
* Add _pendingContextIfReady and rename cursor in context (#1364) * Remove index.js from tests (#1366) * Init logger on replay integration tests to log errors (#1367) * Rethrow span export errors to prevent unnecessary sendIfReady calls (#1368) * Call _onComplete on all leading replay discard paths (#1369) * `ScheduledStreamCapture` to survive multiple rrweb checkouts (#1371)
Note
PR Title/Description mostly generated by AI, guided by me and diff
Description of the change
This PR replaces the single-shot leading capture with a streaming capture strategy that exports and sends leading replay data in small, sequential chunks during the postDuration window—eliminating event loss across multiple rrweb checkouts.
Why
What changed
chunkMs, queues payloads, and opportunistically sends if trailing is SENT and nothing is in flight.Behavior summary
Files
Tests
Updated/added integration tests to verify invariants (not implementation-specific call counts):
Type of change
Related issues
CAT-485/extended-post-trigger-replay-duration