Skip to content

Commit

Permalink
fixup! feat(telemetry): capture client errors with Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Jan 15, 2025
1 parent a485704 commit 959ee2f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client/src/telemetry/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export function initSentry() {
return;
}

let onNextError: (() => void) | null = null;
let onSentryLoad: (() => void) | null = null;
const capturedMessages = new Set<string>();

const handleError = (event: ErrorEvent) => {
loadSentry().then((Sentry) => {
if (onNextError) {
onNextError();
onNextError = null;
if (onSentryLoad) {
onSentryLoad();
onSentryLoad = null;
}
if (!capturedMessages.has(event.message)) {
// Capture every error only once.
Expand All @@ -48,8 +48,8 @@ export function initSentry() {
});
};

// To avoid capturing too many events, we stop listening after the first error.
onNextError = () => window.removeEventListener("error", handleError);
// Avoid capturing too many events by stop listening when Sentry is loaded.
onSentryLoad = () => window.removeEventListener("error", handleError);

window.addEventListener("error", handleError);
}

0 comments on commit 959ee2f

Please sign in to comment.