Skip to content

Commit

Permalink
Merge pull request #174 from etalab/sentry-integration
Browse files Browse the repository at this point in the history
Add Sentry integration
  • Loading branch information
ThomasG77 authored Feb 28, 2023
2 parents a38f249 + 55d2afe commit 3f68e7a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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 = {
Expand Down Expand Up @@ -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, () => {
Expand Down
87 changes: 87 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,51 @@
resolved "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==

"@sentry/[email protected]":
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/[email protected]":
version "7.37.2"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.37.2.tgz#99fd76230d7c1d3c6901ed4c0bea35be7d6fe26d"
integrity sha512-SxKQOCX94ZaQM4C2ysNjHdJsjYapu/NYZCz1cnPyCdDvYfhwiVge1uq6ZHiQ/ARfxAAOmc3R4Mh3VvEz7WUOdw==

"@sentry/[email protected]":
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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -724,6 +776,11 @@ [email protected]:
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"
Expand Down Expand Up @@ -811,6 +868,13 @@ [email protected], 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"
Expand Down Expand Up @@ -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"

[email protected], iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz"
Expand Down Expand Up @@ -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==

[email protected]:
version "1.0.0"
resolved "https://registry.npmjs.org/lunr/-/lunr-1.0.0.tgz"
Expand Down Expand Up @@ -2545,6 +2622,11 @@ [email protected], ms@^2.1.1:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz"
integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==

[email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 3f68e7a

Please sign in to comment.