Skip to content

Commit

Permalink
refactor: make sentry cloud agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
barinali committed May 9, 2023
1 parent 8c164a3 commit 1f1b3a3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/backend/src/helpers/sentry.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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);
}

0 comments on commit 1f1b3a3

Please sign in to comment.