diff --git a/package-lock.json b/package-lock.json index a9e2b084d..98cbe6182 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "@octokit/request": "^6.2.1", "@octokit/rest": "^19.0.4", "@sentry/integrations": "^7.17.4", - "@sentry/node": "^7.17.4", + "@sentry/node": "^7.93.0", + "@sentry/tracing": "^7.93.0", "@types/react": "^18.2.0", "@types/react-dom": "^18.0.11", "airtable": "^0.12.1", @@ -1532,14 +1533,64 @@ "node": ">=14" } }, + "node_modules/@sentry-internal/tracing": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.93.0.tgz", + "integrity": "sha512-DjuhmQNywPp+8fxC9dvhGrqgsUb6wI/HQp25lS2Re7VxL1swCasvpkg8EOYP4iBniVQ86QK0uITkOIRc5tdY1w==", + "dependencies": { + "@sentry/core": "7.93.0", + "@sentry/types": "7.93.0", + "@sentry/utils": "7.93.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry-internal/tracing/node_modules/@sentry/types": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.93.0.tgz", + "integrity": "sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==", + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry-internal/tracing/node_modules/@sentry/utils": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.93.0.tgz", + "integrity": "sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==", + "dependencies": { + "@sentry/types": "7.93.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/@sentry/core": { - "version": "7.17.4", - "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.17.4.tgz", - "integrity": "sha512-U3ABSJBKGK8dJ01nEG2+qNOb6Wv7U3VqoajiZxfV4lpPWNFGCoEhiTytxBlFTOCmdUH8209zSZiWJZaDLy+TSA==", + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.93.0.tgz", + "integrity": "sha512-vZQSUiDn73n+yu2fEcH+Wpm4GbRmtxmnXnYCPgM6IjnXqkVm3awWAkzrheADblx3kmxrRiOlTXYHw9NTWs56fg==", "dependencies": { - "@sentry/types": "7.17.4", - "@sentry/utils": "7.17.4", - "tslib": "^1.9.3" + "@sentry/types": "7.93.0", + "@sentry/utils": "7.93.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry/core/node_modules/@sentry/types": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.93.0.tgz", + "integrity": "sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==", + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry/core/node_modules/@sentry/utils": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.93.0.tgz", + "integrity": "sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==", + "dependencies": { + "@sentry/types": "7.93.0" }, "engines": { "node": ">=8" @@ -1560,17 +1611,45 @@ } }, "node_modules/@sentry/node": { - "version": "7.17.4", - "resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.17.4.tgz", - "integrity": "sha512-cR+Gsir9c/tzFWxvk4zXkMQy6tNRHEYixHrb88XIjZVYDqDS9l2/bKs5nJusdmaUeLtmPp5Et2o7RJyS7gvKTQ==", + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.93.0.tgz", + "integrity": "sha512-nUXPCZQm5Y9Ipv7iWXLNp5dbuyi1VvbJ3RtlwD7utgsNkRYB4ixtKE9w2QU8DZZAjaEF6w2X94OkYH6C932FWw==", "dependencies": { - "@sentry/core": "7.17.4", - "@sentry/types": "7.17.4", - "@sentry/utils": "7.17.4", - "cookie": "^0.4.1", - "https-proxy-agent": "^5.0.0", - "lru_map": "^0.3.3", - "tslib": "^1.9.3" + "@sentry-internal/tracing": "7.93.0", + "@sentry/core": "7.93.0", + "@sentry/types": "7.93.0", + "@sentry/utils": "7.93.0", + "https-proxy-agent": "^5.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry/node/node_modules/@sentry/types": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.93.0.tgz", + "integrity": "sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==", + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry/node/node_modules/@sentry/utils": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.93.0.tgz", + "integrity": "sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==", + "dependencies": { + "@sentry/types": "7.93.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@sentry/tracing": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.93.0.tgz", + "integrity": "sha512-n4XbAQ7e098Jzv4ZvpXAsFgM+XFfjhKci18r7s3UfDMnrB4FTCwhHZoeiygO8PZhB944mEFbNXNFhHkb8nTDbA==", + "dependencies": { + "@sentry-internal/tracing": "7.93.0" }, "engines": { "node": ">=8" @@ -8138,11 +8217,6 @@ "get-func-name": "^2.0.0" } }, - "node_modules/lru_map": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz", - "integrity": "sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ==" - }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -13716,14 +13790,53 @@ "yallist": "4.0.0" } }, + "@sentry-internal/tracing": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.93.0.tgz", + "integrity": "sha512-DjuhmQNywPp+8fxC9dvhGrqgsUb6wI/HQp25lS2Re7VxL1swCasvpkg8EOYP4iBniVQ86QK0uITkOIRc5tdY1w==", + "requires": { + "@sentry/core": "7.93.0", + "@sentry/types": "7.93.0", + "@sentry/utils": "7.93.0" + }, + "dependencies": { + "@sentry/types": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.93.0.tgz", + "integrity": "sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==" + }, + "@sentry/utils": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.93.0.tgz", + "integrity": "sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==", + "requires": { + "@sentry/types": "7.93.0" + } + } + } + }, "@sentry/core": { - "version": "7.17.4", - "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.17.4.tgz", - "integrity": "sha512-U3ABSJBKGK8dJ01nEG2+qNOb6Wv7U3VqoajiZxfV4lpPWNFGCoEhiTytxBlFTOCmdUH8209zSZiWJZaDLy+TSA==", + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.93.0.tgz", + "integrity": "sha512-vZQSUiDn73n+yu2fEcH+Wpm4GbRmtxmnXnYCPgM6IjnXqkVm3awWAkzrheADblx3kmxrRiOlTXYHw9NTWs56fg==", "requires": { - "@sentry/types": "7.17.4", - "@sentry/utils": "7.17.4", - "tslib": "^1.9.3" + "@sentry/types": "7.93.0", + "@sentry/utils": "7.93.0" + }, + "dependencies": { + "@sentry/types": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.93.0.tgz", + "integrity": "sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==" + }, + "@sentry/utils": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.93.0.tgz", + "integrity": "sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==", + "requires": { + "@sentry/types": "7.93.0" + } + } } }, "@sentry/integrations": { @@ -13738,17 +13851,38 @@ } }, "@sentry/node": { - "version": "7.17.4", - "resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.17.4.tgz", - "integrity": "sha512-cR+Gsir9c/tzFWxvk4zXkMQy6tNRHEYixHrb88XIjZVYDqDS9l2/bKs5nJusdmaUeLtmPp5Et2o7RJyS7gvKTQ==", + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.93.0.tgz", + "integrity": "sha512-nUXPCZQm5Y9Ipv7iWXLNp5dbuyi1VvbJ3RtlwD7utgsNkRYB4ixtKE9w2QU8DZZAjaEF6w2X94OkYH6C932FWw==", "requires": { - "@sentry/core": "7.17.4", - "@sentry/types": "7.17.4", - "@sentry/utils": "7.17.4", - "cookie": "^0.4.1", - "https-proxy-agent": "^5.0.0", - "lru_map": "^0.3.3", - "tslib": "^1.9.3" + "@sentry-internal/tracing": "7.93.0", + "@sentry/core": "7.93.0", + "@sentry/types": "7.93.0", + "@sentry/utils": "7.93.0", + "https-proxy-agent": "^5.0.0" + }, + "dependencies": { + "@sentry/types": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.93.0.tgz", + "integrity": "sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==" + }, + "@sentry/utils": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.93.0.tgz", + "integrity": "sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==", + "requires": { + "@sentry/types": "7.93.0" + } + } + } + }, + "@sentry/tracing": { + "version": "7.93.0", + "resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.93.0.tgz", + "integrity": "sha512-n4XbAQ7e098Jzv4ZvpXAsFgM+XFfjhKci18r7s3UfDMnrB4FTCwhHZoeiygO8PZhB944mEFbNXNFhHkb8nTDbA==", + "requires": { + "@sentry-internal/tracing": "7.93.0" } }, "@sentry/types": { @@ -18465,11 +18599,6 @@ "get-func-name": "^2.0.0" } }, - "lru_map": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz", - "integrity": "sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ==" - }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", diff --git a/package.json b/package.json index ee44b96f7..44f637ee5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "@octokit/request": "^6.2.1", "@octokit/rest": "^19.0.4", "@sentry/integrations": "^7.17.4", - "@sentry/node": "^7.17.4", + "@sentry/node": "^7.93.0", + "@sentry/tracing": "^7.93.0", "@types/react": "^18.2.0", "@types/react-dom": "^18.0.11", "airtable": "^0.12.1", diff --git a/src/index.ts b/src/index.ts index b28d931de..5e0bc3a31 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,6 @@ import * as indexController from '@controllers/indexController'; import * as resourceController from '@controllers/resourceController'; import * as hookController from '@controllers/hookController'; import * as pullRequestsController from '@controllers/pullRequestsController'; -import * as sentry from './lib/sentry'; import EventBus from '@infra/eventBus/eventBus'; import { MARRAINAGE_EVENTS_VALUES } from '@models/marrainage'; import routes from './routes/routes'; @@ -41,6 +40,7 @@ import { corsOptions } from './utils/corsConfig'; import { errorHandler } from './middlewares/errorHandler'; import { setupSessionMiddleware } from './middlewares/sessionMiddleware'; import { PUBLIC_ROUTES } from './config/jwt.config'; +import { initializeSentry, sentryErrorHandler } from './lib/sentry'; export const app = express(); app.set('trust proxy', 1); @@ -53,6 +53,7 @@ app.set('view engine', 'ejs'); app.set('views', path.join(__dirname, './views/templates')); // the code is running in directory "dist". // MIDDLEWARES +initializeSentry(app); app.use(compression()); setupStaticFiles(app); setupSessionMiddleware(app); @@ -116,8 +117,7 @@ app.post( express.json({ type: '*/*' }), hookController.postToHook ); - -sentry.initCaptureConsoleWithHandler(app); +app.use(sentryErrorHandler); export default app.listen(config.port, () => console.log(`Running on: ${config.protocol}://${config.host}:${config.port}`) diff --git a/src/lib/sentry.ts b/src/lib/sentry.ts index 5214f4e13..dc717be49 100644 --- a/src/lib/sentry.ts +++ b/src/lib/sentry.ts @@ -1,32 +1,21 @@ import * as Sentry from '@sentry/node'; -import { CaptureConsole as CaptureConsoleIntegration } from "@sentry/integrations"; -import config from '@config'; +import { ErrorRequestHandler } from 'express'; +import config from '@/config'; + +export const initializeSentry = (app) => { + if (!config.sentryDNS) { + console.log('Sentry DSN not found. Sentry is not initialized.'); + return; + } -export function initCaptureConsole() { - const logLevel = ['error']; - console.log( - `Initializing Sentry for log level "${logLevel}" and config: ${config.sentryDNS}` - ); Sentry.init({ - dsn: config.sentryDNS as string, - // https://docs.sentry.io/platforms/javascript/configuration/integrations/plugin/#captureconsole - integrations: [new CaptureConsoleIntegration({ levels: logLevel })], + dsn: process.env.SENTRY_DSN, + tracesSampleRate: 1.0, }); -} -export function initCaptureConsoleWithHandler(app) { - if (config.sentryDNS) { - initCaptureConsole(); + app.use(Sentry.Handlers.requestHandler()); + app.use(Sentry.Handlers.tracingHandler()); +}; - // RequestHandler creates a separate execution context using domains, so that every - // transaction/span/breadcrumb is attached to its own Hub instance - app.use(Sentry.Handlers.requestHandler()); - - // The error handler must be before any other error middleware and after all controllers - app.use(Sentry.Handlers.errorHandler()); - } else { - console.log( - 'Sentry was not initialized as SENTRY_DNS env variable is missing' - ); - } -} +export const sentryErrorHandler: ErrorRequestHandler = + Sentry.Handlers.errorHandler();