Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member

Choose a reason for hiding this comment

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

This should never show up right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this can happen when an error session ends - it will then be set to unsampled for the "follow up" session. Something to look into a bit more, maybe...!

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