1+ // Import this first from sentry instrument!
2+ import '@utils/instrumentSentry' ;
3+
4+ // Now import other modules
15import { ProviderFiles } from '@api/provider/sessions' ;
26import { PrismaRepository } from '@api/repository/repository.service' ;
37import { HttpStatus , router } from '@api/routes/index.router' ;
@@ -21,19 +25,6 @@ function initWA() {
2125async function bootstrap ( ) {
2226 const logger = new Logger ( 'SERVER' ) ;
2327 const app = express ( ) ;
24- const dsn = process . env . SENTRY_DSN ;
25-
26- if ( dsn ) {
27- logger . info ( 'Sentry - ON' ) ;
28- Sentry . init ( {
29- dsn : dsn ,
30- environment : process . env . NODE_ENV || 'development' ,
31- tracesSampleRate : 1.0 ,
32- profilesSampleRate : 1.0 ,
33- } ) ;
34-
35- Sentry . setupExpressErrorHandler ( app ) ;
36- }
3728
3829 let providerFiles : ProviderFiles = null ;
3930 if ( configService . get < ProviderSession > ( 'PROVIDER' ) . ENABLED ) {
@@ -141,6 +132,14 @@ async function bootstrap() {
141132
142133 eventManager . init ( server ) ;
143134
135+ if ( process . env . SENTRY_DSN ) {
136+ logger . info ( 'Sentry - ON' ) ;
137+
138+ // Add this after all routes,
139+ // but before any and other error-handling middlewares are defined
140+ Sentry . setupExpressErrorHandler ( app ) ;
141+ }
142+
144143 server . listen ( httpServer . PORT , ( ) => logger . log ( httpServer . TYPE . toUpperCase ( ) + ' - ON: ' + httpServer . PORT ) ) ;
145144
146145 initWA ( ) ;
0 commit comments