chore: improve instrumentSentry.ts import before another import

Signed-off-by: Roberto Arruda <roberto0arruda@hotmail.com>
This commit is contained in:
Roberto Arruda 2024-12-10 12:13:42 -04:00
parent 682eaa995f
commit cdab5e2ae8
2 changed files with 24 additions and 13 deletions

View File

@ -1,3 +1,7 @@
// Import this first from sentry instrument!
import '@utils/instrumentSentry';
// Now import other modules
import { ProviderFiles } from '@api/provider/sessions'; import { ProviderFiles } from '@api/provider/sessions';
import { PrismaRepository } from '@api/repository/repository.service'; import { PrismaRepository } from '@api/repository/repository.service';
import { HttpStatus, router } from '@api/routes/index.router'; import { HttpStatus, router } from '@api/routes/index.router';
@ -21,19 +25,6 @@ function initWA() {
async function bootstrap() { async function bootstrap() {
const logger = new Logger('SERVER'); const logger = new Logger('SERVER');
const app = express(); const app = express();
const dsn = process.env.SENTRY_DSN;
if (dsn) {
logger.info('Sentry - ON');
Sentry.init({
dsn: dsn,
environment: process.env.NODE_ENV || 'development',
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
});
Sentry.setupExpressErrorHandler(app);
}
let providerFiles: ProviderFiles = null; let providerFiles: ProviderFiles = null;
if (configService.get<ProviderSession>('PROVIDER').ENABLED) { if (configService.get<ProviderSession>('PROVIDER').ENABLED) {
@ -141,6 +132,14 @@ async function bootstrap() {
eventManager.init(server); eventManager.init(server);
if (process.env.SENTRY_DSN) {
logger.info('Sentry - ON');
// Add this after all routes,
// but before any and other error-handling middlewares are defined
Sentry.setupExpressErrorHandler(app);
}
server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT)); server.listen(httpServer.PORT, () => logger.log(httpServer.TYPE.toUpperCase() + ' - ON: ' + httpServer.PORT));
initWA(); initWA();

View File

@ -0,0 +1,12 @@
import * as Sentry from "@sentry/node";
const dsn = process.env.SENTRY_DSN;
if (dsn) {
Sentry.init({
dsn: dsn,
environment: process.env.NODE_ENV || 'development',
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
});
}