Skip to content

Commit 1c9ed4f

Browse files
authored
ref(replay): Improve logging for stopped replay (#7174)
1 parent 1921888 commit 1c9ed4f

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/replay/src/replay.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,22 @@ export class ReplayContainer implements ReplayContainerInterface {
233233
* Currently, this needs to be manually called (e.g. for tests). Sentry SDK
234234
* does not support a teardown
235235
*/
236-
public stop(): void {
236+
public stop(reason?: string): void {
237237
if (!this._isEnabled) {
238238
return;
239239
}
240240

241241
try {
242-
__DEBUG_BUILD__ && logger.log('[Replay] Stopping Replays');
242+
if (__DEBUG_BUILD__) {
243+
const msg = `[Replay] Stopping Replay${reason ? ` triggered by ${reason}` : ''}`;
244+
245+
// When `traceInternals` is enabled, we want to log this to the console
246+
// Else, use the regular debug output
247+
// eslint-disable-next-line
248+
const log = this.getOptions()._experiments.traceInternals ? console.warn : logger.log;
249+
log(msg);
250+
}
251+
243252
this._isEnabled = false;
244253
this._removeListeners();
245254
this.stopRecording();
@@ -426,7 +435,7 @@ export class ReplayContainer implements ReplayContainerInterface {
426435
this.session = session;
427436

428437
if (!this.session.sampled) {
429-
this.stop();
438+
this.stop('session unsampled');
430439
return false;
431440
}
432441

@@ -810,7 +819,7 @@ export class ReplayContainer implements ReplayContainerInterface {
810819
// This means we retried 3 times and all of them failed,
811820
// or we ran into a problem we don't want to retry, like rate limiting.
812821
// In this case, we want to completely stop the replay - otherwise, we may get inconsistent segments
813-
this.stop();
822+
this.stop('sendReplay');
814823

815824
const client = getCurrentHub().getClient();
816825

packages/replay/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export interface ReplayContainer {
293293
isPaused(): boolean;
294294
getContext(): InternalEventContext;
295295
start(): void;
296-
stop(): void;
296+
stop(reason?: string): void;
297297
pause(): void;
298298
resume(): void;
299299
startRecording(): void;

packages/replay/src/util/addEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function addEvent(
4646
return await replay.eventBuffer.addEvent(event, isCheckout);
4747
} catch (error) {
4848
__DEBUG_BUILD__ && logger.error(error);
49-
replay.stop();
49+
replay.stop('addEvent');
5050

5151
const client = getCurrentHub().getClient();
5252

0 commit comments

Comments
 (0)