Skip to content

Commit

Permalink
ref(replay): Improve logging for stopped replay (#7174)
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea authored Feb 15, 2023
1 parent 1921888 commit 1c9ed4f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -426,7 +435,7 @@ export class ReplayContainer implements ReplayContainerInterface {
this.session = session;

if (!this.session.sampled) {
this.stop();
this.stop('session unsampled');
return false;
}

Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/util/addEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 1c9ed4f

Please sign in to comment.