Skip to content

Commit

Permalink
feat(replay): Capture exception when internal_sdk_error client repo…
Browse files Browse the repository at this point in the history
…rt happens

We currently have no visibility when this client report happens. Lets capture the exception if our experimental flag is on.

Also refactors `_handleException()` to be a public method instead of private.
  • Loading branch information
billyvg committed Jul 29, 2024
1 parent f61e729 commit 5b951c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/replay-internal/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ export class ReplayContainer implements ReplayContainerInterface {
return this._options;
}

/** A wrapper to conditionally capture exceptions. */
public handleException(error: unknown): void {
DEBUG_BUILD && logger.error('[Replay]', error);

if (DEBUG_BUILD && this._options._experiments && this._options._experiments.captureExceptions) {
captureException(error);
}
}

/**
* Initializes the plugin based on sampling configuration. Should not be
* called outside of constructor.
Expand All @@ -264,7 +273,7 @@ export class ReplayContainer implements ReplayContainerInterface {

if (!this.session) {
// This should not happen, something wrong has occurred
this._handleException(new Error('Unable to initialize and create session'));
this.handleException(new Error('Unable to initialize and create session'));
return;
}

Expand Down Expand Up @@ -389,7 +398,7 @@ export class ReplayContainer implements ReplayContainerInterface {
: {}),
});
} catch (err) {
this._handleException(err);
this.handleException(err);
}
}

Expand All @@ -408,7 +417,7 @@ export class ReplayContainer implements ReplayContainerInterface {

return true;
} catch (err) {
this._handleException(err);
this.handleException(err);
return false;
}
}
Expand Down Expand Up @@ -450,7 +459,7 @@ export class ReplayContainer implements ReplayContainerInterface {
// is started after, it will not have `previousSessionId`
clearSession(this);
} catch (err) {
this._handleException(err);
this.handleException(err);
}
}

Expand Down Expand Up @@ -777,15 +786,6 @@ export class ReplayContainer implements ReplayContainerInterface {
this.startRecording();
}

/** A wrapper to conditionally capture exceptions. */
private _handleException(error: unknown): void {
DEBUG_BUILD && logger.error('[Replay]', error);

if (DEBUG_BUILD && this._options._experiments && this._options._experiments.captureExceptions) {
captureException(error);
}
}

/**
* Loads (or refreshes) the current session.
*/
Expand Down Expand Up @@ -873,7 +873,7 @@ export class ReplayContainer implements ReplayContainerInterface {
this._hasInitializedCoreListeners = true;
}
} catch (err) {
this._handleException(err);
this.handleException(err);
}

this._performanceCleanupCallback = setupPerformanceObserver(this);
Expand All @@ -898,7 +898,7 @@ export class ReplayContainer implements ReplayContainerInterface {
this._performanceCleanupCallback();
}
} catch (err) {
this._handleException(err);
this.handleException(err);
}
}

Expand Down Expand Up @@ -1161,7 +1161,7 @@ export class ReplayContainer implements ReplayContainerInterface {
timestamp,
});
} catch (err) {
this._handleException(err);
this.handleException(err);

// 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.
Expand Down
2 changes: 2 additions & 0 deletions packages/replay-internal/src/util/addEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ async function _addEvent(
DEBUG_BUILD && logger.error(error);
await replay.stop({ reason });

replay.handleException(error);

const client = getClient();

if (client) {
Expand Down

0 comments on commit 5b951c6

Please sign in to comment.