Skip to content

Commit

Permalink
Clean up area that inits Sentry, we want it running on all deployed s…
Browse files Browse the repository at this point in the history
…ites
  • Loading branch information
adamgall committed Mar 7, 2024
1 parent e629f27 commit d92b932
Showing 1 changed file with 20 additions and 60 deletions.
80 changes: 20 additions & 60 deletions src/helpers/errorLogging.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}

/**
Expand All @@ -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 {
Expand All @@ -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);
}
}

0 comments on commit d92b932

Please sign in to comment.