From 1f1b3a341c205a473a8402f93665598cb5a0fb0e Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Tue, 9 May 2023 11:11:36 +0000 Subject: [PATCH] refactor: make sentry cloud agnostic --- packages/backend/src/helpers/sentry.ee.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/helpers/sentry.ee.ts b/packages/backend/src/helpers/sentry.ee.ts index 8369110e..0810bad0 100644 --- a/packages/backend/src/helpers/sentry.ee.ts +++ b/packages/backend/src/helpers/sentry.ee.ts @@ -5,8 +5,10 @@ import * as Tracing from '@sentry/tracing'; import appConfig from '../config/app'; +const isSentryEnabled = !!appConfig.sentryDsn; + export function init(app?: Express) { - if (!appConfig.isCloud) return; + if (!isSentryEnabled) return; return Sentry.init({ enabled: !!appConfig.sentryDsn, @@ -22,19 +24,19 @@ export function init(app?: Express) { export function attachRequestHandler(app: Express) { - if (!appConfig.isCloud) return; + if (!isSentryEnabled) return; app.use(Sentry.Handlers.requestHandler()); } export function attachTracingHandler(app: Express) { - if (!appConfig.isCloud) return; + if (!isSentryEnabled) return; app.use(Sentry.Handlers.tracingHandler()); } export function attachErrorHandler(app: Express) { - if (!appConfig.isCloud) return; + if (!isSentryEnabled) return; app.use(Sentry.Handlers.errorHandler({ shouldHandleError() { @@ -45,7 +47,7 @@ export function attachErrorHandler(app: Express) { } export function captureException(exception: any, captureContext?: CaptureContext) { - if (!appConfig.isCloud) return; + if (!isSentryEnabled) return; return Sentry.captureException(exception, captureContext); }