From 65ef381603fcd6f3b8be0f7e703586cbcc14f846 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 7 Dec 2022 13:54:43 +0100 Subject: [PATCH 1/2] ref(replay): Avoid overwriting user `checkoutEveryNms` config --- packages/replay/src/replay.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index 87e6cfb2186d..1a109b6c7afd 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -158,8 +158,6 @@ export class ReplayContainer { // when an error will occur, so we need to keep a buffer of // replay events. if (this.session.sampled === 'error') { - // Checkout every minute, meaning we only get up-to one minute of events before the error happens - this.recordingOptions.checkoutEveryNms = 60000; this._waitForError = true; } @@ -187,6 +185,7 @@ export class ReplayContainer { try { this._stopRecording = record({ ...this.recordingOptions, + ...this._getRecordingOptionsOverwrites(), emit: this.handleRecordingEmit, }); } catch (err) { @@ -470,7 +469,6 @@ export class ReplayContainer { this._stopRecording(); // Reset all "capture on error" configuration before // starting a new recording - delete this.recordingOptions.checkoutEveryNms; this._waitForError = false; this.startRecording(); } @@ -1283,4 +1281,16 @@ export class ReplayContainer { client.recordDroppedEvent = this._originalRecordDroppedEvent; } + + /** Additional recordingOptions that should take precedence over user config */ + private _getRecordingOptionsOverwrites(): Partial { + return this._waitForError + ? { + // Checkout every minute, meaning we only get up-to one minute of events before the error happens + // Without this, it would record forever, until an error happens, which we don't want + // instead, we'll always keep the last 60 seconds of replay before an error happened + checkoutEveryNth: 60000, + } + : {}; + } } From 37a81d658ba096c092cfd955f6cc9c5104cf8e1d Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 7 Dec 2022 14:40:01 +0100 Subject: [PATCH 2/2] ref: PR feedback --- packages/replay/src/replay.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index 1a109b6c7afd..e5c0007752bf 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -185,7 +185,10 @@ export class ReplayContainer { try { this._stopRecording = record({ ...this.recordingOptions, - ...this._getRecordingOptionsOverwrites(), + // When running in error sampling mode, we need to overwrite `checkoutEveryNth` + // Without this, it would record forever, until an error happens, which we don't want + // instead, we'll always keep the last 60 seconds of replay before an error happened + ...(this._waitForError && { checkoutEveryNth: 60000 }), emit: this.handleRecordingEmit, }); } catch (err) { @@ -1281,16 +1284,4 @@ export class ReplayContainer { client.recordDroppedEvent = this._originalRecordDroppedEvent; } - - /** Additional recordingOptions that should take precedence over user config */ - private _getRecordingOptionsOverwrites(): Partial { - return this._waitForError - ? { - // Checkout every minute, meaning we only get up-to one minute of events before the error happens - // Without this, it would record forever, until an error happens, which we don't want - // instead, we'll always keep the last 60 seconds of replay before an error happened - checkoutEveryNth: 60000, - } - : {}; - } }