Skip to content

Add Sentry logging #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
// If not specified, Honeybadger integration is disabled
// No default
"honeybadger_apikey": "a531z298s",
// Sentry configuration
"sentry": {
"dsn": "",
"environment": ""
},
// A valid Slack incoming webhook url. Used for sending restart and status messages
// If not specified, Slack integration is disabled
// No default
Expand Down
7 changes: 6 additions & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const defaults = {
protocol: 'https',
port: 8000,
api_url: '', // if not set, generated from api_protocol and api_base_domain
honeybadger_apikey: '',
sentry: {
// Check all config options here: https://docs.sentry.io/platforms/node/configuration/
dsn: '', // required to enable Sentry
environment: 'localhost', // adjust to your environments
tracesSampleRate: 1.0, // adjust in production
},
slack_url: '',
mattermost_url: '',
management_role: 'admin',
Expand Down
15 changes: 8 additions & 7 deletions packages/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const
restify = require('restify'),
{ fullResponse, queryParser, jsonBodyParser, pre: { sanitizePath } } = restify.plugins,
config = require('config'),
{ preRequest, preCors, Honeybadger, getVersion, postToMattermost } = require('./lib/helpers/apiUtils'),
{ preRequest, preCors, Sentry, getVersion, postToMattermost } = require('./lib/helpers/apiUtils'),
routes = require('./lib/routes'),
pino = require('pino');

Expand Down Expand Up @@ -60,10 +60,10 @@ db.connect()
process.exit(1);
});

// InternalServerError is the only error we want to report to Honeybadger..
// InternalServerError is the only error we want to report to Sentry...
server.on('InternalServer', function (req, res, err, callback) {
// set honeybadger context
Honeybadger.resetContext({
// Pass some request information to sentry
Sentry.setContext('request', {
headers: req.headers,
method: req.method,
url: req.url,
Expand All @@ -73,11 +73,12 @@ server.on('InternalServer', function (req, res, err, callback) {
body: req.body,
_body: req._body,
query: req.query,
_userParams: req._userParams
_userParams: req._userParams,
});
log.error(err);
// and notify
Honeybadger.notify(err);

// Notify Sentry
Sentry.captureException(err);

return callback();
});
16 changes: 7 additions & 9 deletions packages/api/lib/helpers/apiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,18 @@ const preCors = function preCors (request, response, next) {
return next();
};

let Honeybadger = {
notify () { },
resetContext () { }
};
let Sentry = {};

/* eslint-disable global-require */
if (config.get('honeybadger_apikey')) {
Honeybadger = require('honeybadger').configure({
apiKey: config.get('honeybadger_apikey')
});
if (config.get('sentry') && config.has('sentry.dsn') && config.get('sentry.dsn').length > 0) {
const sentryConfig = Object.assign({}, config.get('sentry'));
Sentry = require('@sentry/node');
Sentry.init(sentryConfig);
}
/* eslint-enable global-require */



const postToSlack = function postToSlack (text) {
if (config.get('slack_url')) {
text = `[${hostname}]: ${text}`;
Expand Down Expand Up @@ -211,7 +209,7 @@ module.exports = {
checkContentType,
preRequest,
preCors,
Honeybadger,
Sentry,
postToSlack,
postToMattermost,
getVersion,
Expand Down
3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
],
"dependencies": {
"@sensebox/opensensemap-api-models": "2.0.3",
"@sentry/node": "^7.29.0",
"@sentry/tracing": "^7.29.0",
"@turf/area": "^6.3.0",
"@turf/bbox": "^6.3.0",
"@turf/centroid": "^6.3.0",
Expand All @@ -26,7 +28,6 @@
"csv-stringify": "^6.2.3",
"dashify": "^2.0.0",
"got": "^11.8.2",
"honeybadger": "^1.4.0",
"isemail": "^3.0.0",
"jsonwebtoken": "^9.0.0",
"millify": "^5.0.1",
Expand Down
75 changes: 61 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,51 @@
config "^3.3.7"
dedent "^0.7.0"

"@sentry/[email protected]":
version "7.29.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.29.0.tgz#bc4b54d56cf7652598d4430cf43ea97cc069f6fe"
integrity sha512-+e9aIp2ljtT4EJq3901z6TfEVEeqZd5cWzbKEuQzPn2UO6If9+Utd7kY2Y31eQYb4QnJgZfiIEz1HonuYY6zqQ==
dependencies:
"@sentry/types" "7.29.0"
"@sentry/utils" "7.29.0"
tslib "^1.9.3"

"@sentry/node@^7.29.0":
version "7.29.0"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.29.0.tgz#721aab15faef98f291b5a3fcb9b303565deb1e74"
integrity sha512-s/bN/JS5gPTmwzVms4FtI5YNYtC9aGY4uqdx/llVrIiVv7G6md/oJJzKtO1C4dt6YshjGjSs5KCpEn1NM4+1iA==
dependencies:
"@sentry/core" "7.29.0"
"@sentry/types" "7.29.0"
"@sentry/utils" "7.29.0"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"

"@sentry/tracing@^7.29.0":
version "7.29.0"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-7.29.0.tgz#767f309cbff46ab12bec6ab3c266f7f03fec91fd"
integrity sha512-MAN/G6XROtRhzo/KDjddb6VJn/Q1TaPLwdyj9vvfkUkBNtlt5k16oXp+u7eHWX0uujER9wnZtj2ivXaPeqq0VA==
dependencies:
"@sentry/core" "7.29.0"
"@sentry/types" "7.29.0"
"@sentry/utils" "7.29.0"
tslib "^1.9.3"

"@sentry/[email protected]":
version "7.29.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.29.0.tgz#ed829b6014ee19049035fec6af2b4fea44ff28b8"
integrity sha512-DmoEpoqHPty3VxqubS/5gxarwebHRlcBd/yuno+PS3xy++/i9YPjOWLZhU2jYs1cW68M9R6CcCOiC9f2ckJjdw==

"@sentry/[email protected]":
version "7.29.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.29.0.tgz#cbf8f87dd851b0fdc7870db9c68014c321c3bab8"
integrity sha512-ICcBwTiBGK8NQA8H2BJo0JcMN6yCeKLqNKNMVampRgS6wSfSk1edvcTdhRkW3bSktIGrIPZrKskBHyMwDGF2XQ==
dependencies:
"@sentry/types" "7.29.0"
tslib "^1.9.3"

"@sindresorhus/is@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.0.0.tgz#2ff674e9611b45b528896d820d3d7a812de2f0e4"
Expand Down Expand Up @@ -936,6 +981,11 @@ console-control-strings@^1.0.0, console-control-strings@^1.1.0:
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
integrity sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==

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, cookiejar@^2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.3.tgz#fc7a6216e408e74414b90230050842dacda75acc"
Expand Down Expand Up @@ -1788,14 +1838,6 @@ help-me@^3.0.0:
glob "^7.1.6"
readable-stream "^3.6.0"

honeybadger@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/honeybadger/-/honeybadger-1.4.0.tgz#3c74518b53c9bcb1c3327659d5ea4ead2d3adb43"
integrity sha512-n7i8cTfOvGx2z4kG4YSdzye+y3QOesfsSoGkmhWm2ddLTWlra+NLBPmGoo8CmCaYEQMbo3CpA56m5VOdc7LFqg==
dependencies:
request "~2.88.0"
stack-trace "~0.0.9"

[email protected]:
version "2.0.2"
resolved "https://registry.yarnpkg.com/hooks-fixed/-/hooks-fixed-2.0.2.tgz#20076daa07e77d8a6106883ce3f1722e051140b0"
Expand Down Expand Up @@ -2211,6 +2253,11 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

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==

make-dir@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
Expand Down Expand Up @@ -2958,7 +3005,7 @@ [email protected]:
dependencies:
stringify-clone "^1.0.0"

[email protected], request@~2.88.0:
[email protected]:
version "2.88.2"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3"
integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==
Expand Down Expand Up @@ -3316,11 +3363,6 @@ sshpk@^1.7.0:
safer-buffer "^2.0.2"
tweetnacl "~0.14.0"

stack-trace@~0.0.9:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=

[email protected]:
version "2.0.2"
resolved "https://registry.yarnpkg.com/static-eval/-/static-eval-2.0.2.tgz#2d1759306b1befa688938454c546b7871f806a42"
Expand Down Expand Up @@ -3531,6 +3573,11 @@ tr46@~0.0.3:
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

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==

tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
Expand Down