diff --git a/src/analytics.ts b/src/analytics.ts index 0fdf838..073a014 100644 --- a/src/analytics.ts +++ b/src/analytics.ts @@ -5,13 +5,36 @@ import { IN_PRODUCTION_MODE, VERSION } from 'env' const PUBLIC_KEY = 'd22ec5c9cc874539a51c78388c12e3b0' const PROJECT_ID = '1406497' +const errorSet = new Set([ + 'inThisSearch is null', // weird bug in Firefox + 'The quota has been exceeded.', // caused by other addons in Firefox + 'NetworkError when attempting to fetch resource.', // network fail in Firefox + 'Failed to fetch', // network fail in Chrome +]) + const sentryOptions: Sentry.BrowserOptions = { dsn: `https://${PUBLIC_KEY}@sentry.io/${PROJECT_ID}`, release: VERSION, environment: IN_PRODUCTION_MODE ? 'production' : 'development', // Not safe to activate all integrations in non-Chrome environments where Gitako may not run in top context // https://docs.sentry.io/platforms/javascript/#sdk-integrations - integrations: ints => ints.filter(({ name }) => name !== 'TryCatch'), + integrations: integrations => integrations.filter(({ name }) => name !== 'TryCatch'), + beforeSend(event) { + if (event.message) { + if (errorSet.has(event.message)) return null + errorSet.add(event.message) // prevent reporting duplicated error + } + return event + }, + beforeBreadcrumb(breadcrumb, hint) { + if (breadcrumb.category === 'ui.click') { + const ariaLabel = hint?.event?.target?.ariaLabel + if (ariaLabel) { + breadcrumb.message = ariaLabel + } + } + return breadcrumb + }, } Sentry.init(sentryOptions)