From f8f8b4f2b94dcfe2118cd48aa31d7c9984fe48da Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 25 Aug 2022 13:49:08 -0500 Subject: [PATCH] Sentry: filter out useless events, tag ErrorBoundary page crashes --- app/soapbox/components/error_boundary.tsx | 7 ++++++- app/soapbox/monitoring.ts | 24 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/soapbox/components/error_boundary.tsx b/app/soapbox/components/error_boundary.tsx index ddca29d21..436b40134 100644 --- a/app/soapbox/components/error_boundary.tsx +++ b/app/soapbox/components/error_boundary.tsx @@ -56,7 +56,12 @@ class ErrorBoundary extends React.PureComponent { textarea: HTMLTextAreaElement | null = null; componentDidCatch(error: any, info: any): void { - captureException(error); + captureException(error, { + tags: { + // Allow page crashes to be easily searched in Sentry. + ErrorBoundary: 'yes', + }, + }); this.setState({ hasError: true, diff --git a/app/soapbox/monitoring.ts b/app/soapbox/monitoring.ts index 51e040b12..33c03244d 100644 --- a/app/soapbox/monitoring.ts +++ b/app/soapbox/monitoring.ts @@ -1,5 +1,7 @@ import * as BuildConfig from 'soapbox/build_config'; +import type { CaptureContext } from '@sentry/types'; + export const start = (): void => { Promise.all([ import(/* webpackChunkName: "error" */'@sentry/react'), @@ -11,6 +13,24 @@ export const start = (): void => { debug: false, integrations: [new Integrations.BrowserTracing()], + // Filter events. + // https://docs.sentry.io/platforms/javascript/configuration/filtering/ + ignoreErrors: [ + // Network errors. + 'AxiosError', + // sw.js couldn't be downloaded. + 'Failed to update a ServiceWorker for scope', + // The user decided not to share (eg `navigator.share()`). + // This exception is useful for a try/catch flow, but not for error monitoring. + 'AbortError: Share canceled', + ], + denyUrls: [ + // Browser extensions. + /extensions\//i, + /^chrome:\/\//i, + /^moz-extension:\/\//i, + ], + // We recommend adjusting this value in production, or using tracesSampler // for finer control tracesSampleRate: 1.0, @@ -18,10 +38,10 @@ export const start = (): void => { }).catch(console.error); }; -export const captureException = (error: Error): void => { +export const captureException = (exception: any, captureContext?: CaptureContext | undefined): void => { import(/* webpackChunkName: "error" */'@sentry/react') .then(Sentry => { - Sentry.captureException(error); + Sentry.captureException(exception, captureContext); }) .catch(console.error); };