From 339271e819eddcc2349ef39cc7a8c2236775e175 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Tue, 6 Oct 2020 12:08:59 -0400 Subject: [PATCH] Integrate sentry --- package-lock.json | 136 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- server.js | 13 +++++ 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index eea2e1a..c6e19a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,103 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@sentry/core": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-5.25.0.tgz", + "integrity": "sha512-hY6Zmo7t/RV+oZuvXHP6nyAj/QnZr2jW0e7EbL5YKMV8q0vlnjcE0LgqFXme726OJemoLk67z+sQOJic/Ztehg==", + "requires": { + "@sentry/hub": "5.25.0", + "@sentry/minimal": "5.25.0", + "@sentry/types": "5.25.0", + "@sentry/utils": "5.25.0", + "tslib": "^1.9.3" + } + }, + "@sentry/hub": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/hub/-/hub-5.25.0.tgz", + "integrity": "sha512-kOlOiJV8wMX50lYpzMlOXBoH7MNG0Ho4RTusdZnXZBaASq5/ljngDJkLr6uylNjceZQP21wzipCQajsJMYB7EQ==", + "requires": { + "@sentry/types": "5.25.0", + "@sentry/utils": "5.25.0", + "tslib": "^1.9.3" + } + }, + "@sentry/minimal": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/minimal/-/minimal-5.25.0.tgz", + "integrity": "sha512-9JFKuW7U+1vPO86k3+XRtJyooiVZsVOsFFO4GulBzepi3a0ckNyPgyjUY1saLH+cEHx18hu8fGgajvI8ANUF2g==", + "requires": { + "@sentry/hub": "5.25.0", + "@sentry/types": "5.25.0", + "tslib": "^1.9.3" + } + }, + "@sentry/node": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/node/-/node-5.25.0.tgz", + "integrity": "sha512-zxoUVdAFTeK9kdEGY95TMs6g8Zx/P55HxG4gHD80BG/XIEvWiGPcGCLOspO4IdGqYXkGS74KfBOIXmmCawWwLg==", + "requires": { + "@sentry/core": "5.25.0", + "@sentry/hub": "5.25.0", + "@sentry/tracing": "5.25.0", + "@sentry/types": "5.25.0", + "@sentry/utils": "5.25.0", + "cookie": "^0.4.1", + "https-proxy-agent": "^5.0.0", + "lru_map": "^0.3.3", + "tslib": "^1.9.3" + } + }, + "@sentry/tracing": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-5.25.0.tgz", + "integrity": "sha512-KcyHEGFpqSDubHrdWT/vF2hKkjw/ts6NpJ6tPDjBXUNz98BHdAyMKtLOFTCeJFply7/s5fyiAYu44M+M6IG3Bw==", + "requires": { + "@sentry/hub": "5.25.0", + "@sentry/minimal": "5.25.0", + "@sentry/types": "5.25.0", + "@sentry/utils": "5.25.0", + "tslib": "^1.9.3" + } + }, + "@sentry/types": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-5.25.0.tgz", + "integrity": "sha512-8M4PREbcar+15wrtEqcwfcU33SS+2wBSIOd/NrJPXJPTYxi49VypCN1mZBDyWkaK+I+AuQwI3XlRPCfsId3D1A==" + }, + "@sentry/utils": { + "version": "5.25.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-5.25.0.tgz", + "integrity": "sha512-Hz5spdIkMSRH5NR1YFOp5qbsY5Ud2lKhEQWlqxcVThMG5YNUc10aYv5ijL19v0YkrC2rqPjCRm7GrVtzOc7bXQ==", + "requires": { + "@sentry/types": "5.25.0", + "tslib": "^1.9.3" + } + }, + "agent-base": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.1.tgz", + "integrity": "sha512-01q25QQDwLSsyfhrKbn8yuur+JNw0H+0Y4JiGIKd3z9aYk/w/2kxD/Upc+t2ZBBSUNff50VjPsSW2YxM8QYKVg==", + "requires": { + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", + "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -287,6 +384,11 @@ "resolved": "https://registry.npmjs.org/connect-route/-/connect-route-0.1.5.tgz", "integrity": "sha1-48IYMZ0uiKiprgsOD+Cacpw5dEo=" }, + "cookie": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", + "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==" + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -618,6 +720,30 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "requires": { + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", + "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", @@ -815,6 +941,11 @@ "yallist": "^2.1.2" } }, + "lru_map": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz", + "integrity": "sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=" + }, "mime": { "version": "2.4.6", "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.6.tgz", @@ -1284,6 +1415,11 @@ "is-number": "^7.0.0" } }, + "tslib": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.0.tgz", + "integrity": "sha512-+Zw5lu0D9tvBMjGP8LpvMb0u2WW2QV3y+D8mO6J+cNzCYIN4sVy43Bf9vl92nqFahutN0I8zHa7cc4vihIshnw==" + }, "uglify-js": { "version": "3.1.6", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.6.tgz", diff --git a/package.json b/package.json index 0ebec48..b582850 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,9 @@ "pg": "^6.0.0", "st": "^2.0.0", "winston": "^2.0.0", - "uglify-js": "3.1.6" + "uglify-js": "3.1.6", + "@sentry/node": "*", + "@sentry/tracing": "*" }, "devDependencies": { "mocha": "^8.1.3" diff --git a/server.js b/server.js index 57bd3da..5139d68 100644 --- a/server.js +++ b/server.js @@ -10,6 +10,13 @@ var connect_rate_limit = require('connect-ratelimit'); var DocumentHandler = require('./lib/document_handler'); +const Sentry = require('@sentry/node'); + +const sentryEnabled = process.env.SENTRY_DSN; +if (sentryEnabled) { + Sentry.init({dsn: process.env.SENTRY_DSN}); +} + // Load the configuration and set some defaults var config = JSON.parse(fs.readFileSync('./config.js', 'utf8')); config.port = process.env.PORT || config.port || 7777; @@ -100,6 +107,9 @@ var documentHandler = new DocumentHandler({ var app = connect(); +// Include sentry request handler if enabled +if (sentryEnabled) app.use(Sentry.Handlers.requestHandler()); + // Rate limit all requests if (config.rateLimits) { config.rateLimits.end = true; @@ -150,6 +160,9 @@ app.use(connect_st({ index: 'index.html' })); +// Include sentry error handler if enabled +if (sentryEnabled) { app.use(Sentry.Handlers.errorHandler()); } + http.createServer(app).listen(config.port, config.host); winston.info('listening on ' + config.host + ':' + config.port);