Skip to content

Commit

Permalink
Merge pull request #1103 from roberto0arruda/fix/sentry-auto-instrume…
Browse files Browse the repository at this point in the history
…nt-express

chore: improve instrumentSentry.ts import before another import
  • Loading branch information
DavidsonGomes authored Dec 11, 2024
2 parents 682eaa9 + cdab5e2 commit d5c2cfb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Import this first from sentry instrument!
import '@utils/instrumentSentry';

// Now import other modules
import { ProviderFiles } from '@api/provider/sessions';
import { PrismaRepository } from '@api/repository/repository.service';
import { HttpStatus, router } from '@api/routes/index.router';
Expand All @@ -21,19 +25,6 @@ function initWA() {
async function bootstrap() {
const logger = new Logger('SERVER');
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;
if (configService.get<ProviderSession>('PROVIDER').ENABLED) {
Expand Down Expand Up @@ -141,6 +132,14 @@ async function bootstrap() {

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

initWA();
Expand Down
12 changes: 12 additions & 0 deletions src/utils/instrumentSentry.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}

0 comments on commit d5c2cfb

Please sign in to comment.