From 55d2afed21a0bc545642d015282f9e999921b581 Mon Sep 17 00:00:00 2001 From: Thomas Gratier Date: Wed, 15 Feb 2023 16:24:03 +0100 Subject: [PATCH] Add Sentry integration --- package.json | 2 ++ server.js | 26 ++++++++++++++++ yarn.lock | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/package.json b/package.json index 461f7a0..10a3328 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,8 @@ "access": "public" }, "dependencies": { + "@sentry/node": "^7.37.2", + "@sentry/tracing": "^7.37.2", "@turf/bbox": "^6.5.0", "@turf/bbox-polygon": "^6.5.0", "cors": "^2.8.5", diff --git a/server.js b/server.js index 56f6dd7..af455dc 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,8 @@ const express = require('express') const cors = require('cors') const morgan = require('morgan') +const Sentry = require('@sentry/node') +const Tracing = require('@sentry/tracing') const {initCommuneFields, initCommuneFormat, communesDefaultQuery} = require('./lib/communeHelpers') const {initCommunesAssocieeDelegueeFields, initCommuneAssocieeDelegueeFormat, communesAssocieesDelegueesDefaultQuery} = require('./lib/communeAssocieesDelegueesHelpers') const {initEpciFields, initEpciFormat, epciDefaultQuery} = require('./lib/epciHelpers') @@ -21,6 +23,26 @@ if (process.env.NODE_ENV !== 'production') { app.use(morgan('dev')) } +if (process.env.SENTRY_DSN) { + Sentry.init({ + dsn: process.env.SENTRY_DSN, + integrations: [ + // Enable HTTP calls tracing + new Sentry.Integrations.Http({tracing: true}), + // Enable Express.js middleware tracing + new Tracing.Integrations.Express({app}) + ], + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0 + }) + app.use(Sentry.Handlers.requestHandler()) + // TracingHandler creates a trace for every incoming request + app.use(Sentry.Handlers.tracingHandler()) +} + // Inject databases references app.use((req, res, next) => { req.db = { @@ -290,6 +312,10 @@ app.get('/definition.yml', (req, res) => { res.sendFile(__dirname + '/definition.yml') }) +if (process.env.SENTRY_DSN) { + app.use(Sentry.Handlers.errorHandler()) +} + const port = process.env.PORT || 5000 app.listen(port, () => { diff --git a/yarn.lock b/yarn.lock index 9c117b8..0ec1bf4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -107,6 +107,51 @@ resolved "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz" integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw== +"@sentry/core@7.37.2": + version "7.37.2" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.37.2.tgz#959b2bf953f442b07f8377d90f4f7735cf260ae4" + integrity sha512-LjofMDSTyVeBErl9N7TTqlyEVuW1g6U4iuJtdZ75JohnvVxzWdpZfWfddwQ6h7nGWfe9dNg0fGs1wxKtMhY+MA== + dependencies: + "@sentry/types" "7.37.2" + "@sentry/utils" "7.37.2" + tslib "^1.9.3" + +"@sentry/node@^7.37.2": + version "7.37.2" + resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.37.2.tgz#7ce3b09c93112afca0eef0fd65ec87ea1cd1b7d2" + integrity sha512-aeJQ4oU3vF9zks8S/fvoLPVVhofmTjyMhZZIpSQWtfFqWxrXQsrqNlNUZZdXoqAUPNjA4QAzzOoXHhpUsa3Nxw== + dependencies: + "@sentry/core" "7.37.2" + "@sentry/types" "7.37.2" + "@sentry/utils" "7.37.2" + cookie "^0.4.1" + https-proxy-agent "^5.0.0" + lru_map "^0.3.3" + tslib "^1.9.3" + +"@sentry/tracing@^7.37.2": + version "7.37.2" + resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-7.37.2.tgz#88f149aea6a4d5a3cfb9145868d885fac9fffb52" + integrity sha512-XBVvxbV5TADq2rHg/kJqGqDfOP8n2myMUxMMpfHMb38NrxkxQwXy+gDe41bA8FJKA2k7Y3Wkn8ZC/PelQ8c+ag== + dependencies: + "@sentry/core" "7.37.2" + "@sentry/types" "7.37.2" + "@sentry/utils" "7.37.2" + tslib "^1.9.3" + +"@sentry/types@7.37.2": + version "7.37.2" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.37.2.tgz#99fd76230d7c1d3c6901ed4c0bea35be7d6fe26d" + integrity sha512-SxKQOCX94ZaQM4C2ysNjHdJsjYapu/NYZCz1cnPyCdDvYfhwiVge1uq6ZHiQ/ARfxAAOmc3R4Mh3VvEz7WUOdw== + +"@sentry/utils@7.37.2": + version "7.37.2" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.37.2.tgz#14dea644454e3df247fb113fc834f509c1f0e48c" + integrity sha512-5irN1nN/mtdOoWwsJiwBK0gPgNMkciUubEMbCaaXqJaGyGz8+yfDvXj7L+xGYiU57z+7+QkkSKxKEZ/IcBpjVQ== + dependencies: + "@sentry/types" "7.37.2" + tslib "^1.9.3" + "@turf/area@^6.0.1": version "6.0.1" resolved "https://registry.npmjs.org/@turf/area/-/area-6.0.1.tgz" @@ -247,6 +292,13 @@ acorn@^6.0.2, acorn@^6.0.7: resolved "https://registry.npmjs.org/acorn/-/acorn-6.1.0.tgz" integrity sha512-MW/FjM+IvU9CgBzjO3UIPCE2pyEwUsoFl+VGdczOPEdxfGFjuKny/gN54mOuX7Qxmb9Rg9MCn2oKiSUeW+pjrw== +agent-base@6: + version "6.0.2" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" + integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== + dependencies: + debug "4" + agent-base@^4.3.0: version "4.3.0" resolved "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz" @@ -724,6 +776,11 @@ cookie@0.4.0: resolved "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz" integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== +cookie@^0.4.1: + version "0.4.2" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432" + integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA== + cookiejar@^2.1.0: version "2.1.2" resolved "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz" @@ -811,6 +868,13 @@ debug@3.1.0, debug@^3.1.0: dependencies: ms "2.0.0" +debug@4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + debug@^4.0.1, debug@^4.1.0, debug@^4.1.1: version "4.1.1" resolved "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz" @@ -1755,6 +1819,14 @@ https-proxy-agent@^2.2.1: agent-base "^4.3.0" debug "^3.1.0" +https-proxy-agent@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz#c59ef224a04fe8b754f3db0063a25ea30d0005d6" + integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA== + dependencies: + agent-base "6" + debug "4" + iconv-lite@0.4.24, iconv-lite@^0.4.24: version "0.4.24" resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz" @@ -2329,6 +2401,11 @@ lru-cache@^4.0.1: pseudomap "^1.0.2" yallist "^2.1.2" +lru_map@^0.3.3: + version "0.3.3" + resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" + integrity sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ== + lunr@1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/lunr/-/lunr-1.0.0.tgz" @@ -2545,6 +2622,11 @@ ms@2.1.1, ms@^2.1.1: resolved "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz" integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + multimatch@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/multimatch/-/multimatch-2.1.0.tgz" @@ -3703,6 +3785,11 @@ tslib@^1.9.0: resolved "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz" integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ== +tslib@^1.9.3: + version "1.14.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" + integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== + type-check@~0.3.2: version "0.3.2" resolved "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz"