From 1c9ed4ff4fd4c67f9018cfb129a88730ef5d5c85 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 15 Feb 2023 09:07:07 +0100 Subject: [PATCH] ref(replay): Improve logging for stopped replay (#7174) --- packages/replay/src/replay.ts | 17 +++++++++++++---- packages/replay/src/types.ts | 2 +- packages/replay/src/util/addEvent.ts | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index c162a26cd5da..413286af5e82 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -233,13 +233,22 @@ export class ReplayContainer implements ReplayContainerInterface { * Currently, this needs to be manually called (e.g. for tests). Sentry SDK * does not support a teardown */ - public stop(): void { + public stop(reason?: string): void { if (!this._isEnabled) { return; } try { - __DEBUG_BUILD__ && logger.log('[Replay] Stopping Replays'); + if (__DEBUG_BUILD__) { + const msg = `[Replay] Stopping Replay${reason ? ` triggered by ${reason}` : ''}`; + + // When `traceInternals` is enabled, we want to log this to the console + // Else, use the regular debug output + // eslint-disable-next-line + const log = this.getOptions()._experiments.traceInternals ? console.warn : logger.log; + log(msg); + } + this._isEnabled = false; this._removeListeners(); this.stopRecording(); @@ -426,7 +435,7 @@ export class ReplayContainer implements ReplayContainerInterface { this.session = session; if (!this.session.sampled) { - this.stop(); + this.stop('session unsampled'); return false; } @@ -810,7 +819,7 @@ export class ReplayContainer implements ReplayContainerInterface { // This means we retried 3 times and all of them failed, // or we ran into a problem we don't want to retry, like rate limiting. // In this case, we want to completely stop the replay - otherwise, we may get inconsistent segments - this.stop(); + this.stop('sendReplay'); const client = getCurrentHub().getClient(); diff --git a/packages/replay/src/types.ts b/packages/replay/src/types.ts index 27c878a3edba..174f1da240f8 100644 --- a/packages/replay/src/types.ts +++ b/packages/replay/src/types.ts @@ -293,7 +293,7 @@ export interface ReplayContainer { isPaused(): boolean; getContext(): InternalEventContext; start(): void; - stop(): void; + stop(reason?: string): void; pause(): void; resume(): void; startRecording(): void; diff --git a/packages/replay/src/util/addEvent.ts b/packages/replay/src/util/addEvent.ts index e243ce11b56b..5cf351fd6f9c 100644 --- a/packages/replay/src/util/addEvent.ts +++ b/packages/replay/src/util/addEvent.ts @@ -46,7 +46,7 @@ export async function addEvent( return await replay.eventBuffer.addEvent(event, isCheckout); } catch (error) { __DEBUG_BUILD__ && logger.error(error); - replay.stop(); + replay.stop('addEvent'); const client = getCurrentHub().getClient();