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..cfa800bde 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,23 @@ 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', + // Useful for try/catch, useless as a Sentry error. + 'AbortError', + ], + 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 +37,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); };