Skip to content

Capture leading replay#1334

Merged
matux merged 2 commits into
matux/leading-replayfrom
matux/capture-leading-replay
Oct 1, 2025
Merged

Capture leading replay#1334
matux merged 2 commits into
matux/leading-replayfrom
matux/capture-leading-replay

Conversation

@matux

@matux matux commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Description of the change

Note

PR Description by Copilot.

This pull request introduces support for "leading replay" capture in addition to the existing "trailing replay" functionality. Leading replay allows capturing and sending a short window of user events that occur after an error is triggered, improving the context available for debugging. The changes include new configuration options, enhancements to the replay recording and management logic, and additional state tracking for coordinating leading and trailing replay sends.

Leading replay capture and coordination:

  • Added a new postDuration option to defaults.js to specify the number of seconds of events to capture after an error is triggered.
  • Updated ReplayManager (replayManager.js) to schedule and export leading replay events after the trailing replay is sent, including logic for managing pending leading captures and coordinating their sending/discarding based on trailing replay status. [1] [2] [3]
  • Introduced a TrailingStatus enum and state tracking in ReplayManager to manage the status of trailing and leading replay sends. [1] [2] [3]

Recorder improvements:

  • Enhanced Recorder (recorder.js) to support exporting only events after a specific point for leading replay, added a method to get the current event count, and adjusted validity checks for exported recordings. [1] [2] [3]

Test updates:

  • Updated and skipped tests in recorder.test.js to reflect new validity checks for replay recordings.
  • Refactored tests in replayManager.test.js for clarity and to accommodate new method signatures. [1] [2] [3]

@matux matux requested a review from Copilot September 30, 2025 15:56
@matux matux self-assigned this Sep 30, 2025
@matux matux force-pushed the matux/capture-leading-replay branch from 25314bc to 056833e Compare September 30, 2025 16:07
@matux matux force-pushed the matux/capture-leading-replay branch from 056833e to f118acd Compare September 30, 2025 16:22
Comment on lines +200 to +208
/**
* Gets the current count of events in the buffers.
* This represents a marker for where trailing events end.
*
* @returns {number} The total number of events currently stored
*/
getCurrentEventCount() {
return this._events.previous.length + this._events.current.length;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the event count as a boundary marker rather than tracking the specific event. This has a fatal flaw, though: If during those N post-seconds we get a checkout from rrweb, we rotate the buffer and this number becomes invalid (out of bounds).

I have a fix for this, but I'll send it in a subsequent PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looking forward to the fix. We had talked about tracking both the buffer and the index in the buffer.

Comment thread src/browser/replay/recorder.js
exportRecordingSpan(tracing, attributes = {}) {
const events = this._collectEvents();
exportRecordingSpan(tracing, attributes = {}, afterCount = 0) {
const events = this._collectEvents(afterCount);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe startIndex or startPosition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is changing completely, can we leave it like this? So I can merge this and move on to the next PRs!

Then we circle back.

This comment was marked as resolved.

@matux matux requested a review from Copilot October 1, 2025 06:13
@matux matux marked this pull request as ready for review October 1, 2025 06:13
@matux matux requested a review from waltjones October 1, 2025 06:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/browser/replay/recorder.js
Comment thread src/browser/replay/replayManager.js Outdated
@matux matux requested a review from Copilot October 1, 2025 06:23

This comment was marked as duplicate.

@matux matux merged commit 6c9b0c4 into matux/leading-replay Oct 1, 2025
4 checks passed
@matux matux deleted the matux/capture-leading-replay branch October 1, 2025 12:38
matux added a commit that referenced this pull request Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants