From d92b9328febf796c480c93c6da9da44b1aac0e3e Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Thu, 7 Mar 2024 15:02:26 -0500 Subject: [PATCH] Clean up area that inits Sentry, we want it running on all deployed sites --- src/helpers/errorLogging.ts | 80 ++++++++++--------------------------- 1 file changed, 20 insertions(+), 60 deletions(-) diff --git a/src/helpers/errorLogging.ts b/src/helpers/errorLogging.ts index 1c59058c1f..0ade8689bd 100644 --- a/src/helpers/errorLogging.ts +++ b/src/helpers/errorLogging.ts @@ -1,70 +1,30 @@ import * as Sentry from '@sentry/react'; -import { BrowserTracing } from '@sentry/tracing'; -import { isProd } from '../utils/dev'; /** - * Sentry key which allows pushing error events. Since this only allows submission of new events, - * but not reading them, this is fine to have public. - * - * https://docs.sentry.io/product/sentry-basics/dsn-explainer/ - */ -const SENTRY_DSN_DEV = - 'https://23bdd0d2ce384e51a6b9d8c478767327@o4505173268365312.ingest.sentry.io/4505195485265920'; - -/** - * Initializes error logging. We do not log Sentry data in production. + * Initializes error logging. */ export function initErrorLogging() { - if (!isProd()) { - Sentry.init({ - dsn: SENTRY_DSN_DEV, - integrations: [new BrowserTracing()], - - // Setting tracesSampleRate to 1.0 captures 100% - // of sentry transactions for performance monitoring. - tracesSampleRate: 1.0, - - debug: true, - }); + if ( + process.env.NODE_ENV === 'development' || + process.env.NEXT_PUBLIC_SENTRY_DSN_URL === undefined + ) { + return; } -} -/** - * Sets the wallet address of the currently connected wallet, - * in order to add more context to Sentry events. - * Pass `null` to unset the current wallet. - * @param walletAddress the wallet address of the currently connected wallet - */ -export function setLoggedWallet(walletAddress: string | null) { - if (isProd()) return; - if (!walletAddress) { - Sentry.setUser(null); - } else { - Sentry.setUser({ - id: walletAddress, - }); - } -} + Sentry.init({ + dsn: process.env.NEXT_PUBLIC_SENTRY_DSN_URL, + integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()], -/** - * Adds arbitrary context parameters, which are indexed/searchable - * on Sentry event logging. - * @param key the context key - * @param value the context value - */ -export function setErrorContext(key: string, value: string) { - if (isProd()) return; - Sentry.setTag(key, value); -} + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0, -/** - * Clears any additional context that has been added to currently logging - * Sentry events. - */ -export function clearErrorContext() { - if (isProd()) return; - Sentry.setTags({}); - setLoggedWallet(null); + // Capture Replay for 10% of all sessions, + // plus for 100% of sessions with an error + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + }); } /** @@ -74,7 +34,7 @@ export function clearErrorContext() { */ export function logError(error: any, ...optionalParams: any[]) { console.error(error, optionalParams); - if (isProd()) return; + if (process.env.NODE_ENV === 'development') return; if (typeof error === 'string' || error instanceof String) { Sentry.captureMessage(error + ': ' + optionalParams); } else { @@ -94,7 +54,7 @@ export class FractalErrorBoundary extends Sentry.ErrorBoundary { errorInfo: React.ErrorInfo ) { logError(error, errorInfo); - if (isProd()) return; + if (process.env.NODE_ENV === 'development') return; super.componentDidCatch(error, errorInfo); } }