refactor: make sentry cloud agnostic

This commit is contained in:
Ali BARIN
2023-05-09 11:11:36 +00:00
parent 8c164a3852
commit 1f1b3a341c

View File

@@ -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);
}