refactor: make sentry cloud agnostic
This commit is contained in:
@@ -5,8 +5,10 @@ import * as Tracing from '@sentry/tracing';
|
|||||||
|
|
||||||
import appConfig from '../config/app';
|
import appConfig from '../config/app';
|
||||||
|
|
||||||
|
const isSentryEnabled = !!appConfig.sentryDsn;
|
||||||
|
|
||||||
export function init(app?: Express) {
|
export function init(app?: Express) {
|
||||||
if (!appConfig.isCloud) return;
|
if (!isSentryEnabled) return;
|
||||||
|
|
||||||
return Sentry.init({
|
return Sentry.init({
|
||||||
enabled: !!appConfig.sentryDsn,
|
enabled: !!appConfig.sentryDsn,
|
||||||
@@ -22,19 +24,19 @@ export function init(app?: Express) {
|
|||||||
|
|
||||||
|
|
||||||
export function attachRequestHandler(app: Express) {
|
export function attachRequestHandler(app: Express) {
|
||||||
if (!appConfig.isCloud) return;
|
if (!isSentryEnabled) return;
|
||||||
|
|
||||||
app.use(Sentry.Handlers.requestHandler());
|
app.use(Sentry.Handlers.requestHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function attachTracingHandler(app: Express) {
|
export function attachTracingHandler(app: Express) {
|
||||||
if (!appConfig.isCloud) return;
|
if (!isSentryEnabled) return;
|
||||||
|
|
||||||
app.use(Sentry.Handlers.tracingHandler());
|
app.use(Sentry.Handlers.tracingHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function attachErrorHandler(app: Express) {
|
export function attachErrorHandler(app: Express) {
|
||||||
if (!appConfig.isCloud) return;
|
if (!isSentryEnabled) return;
|
||||||
|
|
||||||
app.use(Sentry.Handlers.errorHandler({
|
app.use(Sentry.Handlers.errorHandler({
|
||||||
shouldHandleError() {
|
shouldHandleError() {
|
||||||
@@ -45,7 +47,7 @@ export function attachErrorHandler(app: Express) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function captureException(exception: any, captureContext?: CaptureContext) {
|
export function captureException(exception: any, captureContext?: CaptureContext) {
|
||||||
if (!appConfig.isCloud) return;
|
if (!isSentryEnabled) return;
|
||||||
|
|
||||||
return Sentry.captureException(exception, captureContext);
|
return Sentry.captureException(exception, captureContext);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user