Merge pull request #1695 from automatisch/sentry-enhancement
chore: Do not enable sentry for dev and test environments
This commit is contained in:
		| @@ -3,10 +3,13 @@ import * as Tracing from '@sentry/tracing'; | |||||||
|  |  | ||||||
| import appConfig from '../config/app.js'; | import appConfig from '../config/app.js'; | ||||||
|  |  | ||||||
| const isSentryEnabled = !!appConfig.sentryDsn; | const isSentryEnabled = () => { | ||||||
|  |   if (appConfig.isDev || appConfig.isTest) return false; | ||||||
|  |   return !!appConfig.sentryDsn; | ||||||
|  | }; | ||||||
|  |  | ||||||
| export function init(app) { | export function init(app) { | ||||||
|   if (!isSentryEnabled) return; |   if (!isSentryEnabled()) return; | ||||||
|  |  | ||||||
|   return Sentry.init({ |   return Sentry.init({ | ||||||
|     enabled: !!appConfig.sentryDsn, |     enabled: !!appConfig.sentryDsn, | ||||||
| @@ -21,19 +24,19 @@ export function init(app) { | |||||||
| } | } | ||||||
|  |  | ||||||
| export function attachRequestHandler(app) { | export function attachRequestHandler(app) { | ||||||
|   if (!isSentryEnabled) return; |   if (!isSentryEnabled()) return; | ||||||
|  |  | ||||||
|   app.use(Sentry.Handlers.requestHandler()); |   app.use(Sentry.Handlers.requestHandler()); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function attachTracingHandler(app) { | export function attachTracingHandler(app) { | ||||||
|   if (!isSentryEnabled) return; |   if (!isSentryEnabled()) return; | ||||||
|  |  | ||||||
|   app.use(Sentry.Handlers.tracingHandler()); |   app.use(Sentry.Handlers.tracingHandler()); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function attachErrorHandler(app) { | export function attachErrorHandler(app) { | ||||||
|   if (!isSentryEnabled) return; |   if (!isSentryEnabled()) return; | ||||||
|  |  | ||||||
|   app.use( |   app.use( | ||||||
|     Sentry.Handlers.errorHandler({ |     Sentry.Handlers.errorHandler({ | ||||||
| @@ -46,7 +49,7 @@ export function attachErrorHandler(app) { | |||||||
| } | } | ||||||
|  |  | ||||||
| export function captureException(exception, captureContext) { | export function captureException(exception, captureContext) { | ||||||
|   if (!isSentryEnabled) return; |   if (!isSentryEnabled()) return; | ||||||
|  |  | ||||||
|   return Sentry.captureException(exception, captureContext); |   return Sentry.captureException(exception, captureContext); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ömer Faruk Aydın
					Ömer Faruk Aydın