feat(tools): sentry apm and other telemetry (#49385)

* feat(tools): sentry apm and other telemetry

* fix: use middleware json to remove duplication

---------

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Mrugesh Mohapatra
2023-02-17 18:23:18 +05:30
committed by Mrugesh Mohapatra
co-authored by Oliver Eyton-Williams
parent c29ecaf14f
commit 537ef39a8d
5 changed files with 193 additions and 25 deletions
+2 -1
View File
@@ -29,7 +29,8 @@
},
"dependencies": {
"@freecodecamp/loopback-component-passport": "1.2.0",
"@sentry/node": "6.19.7",
"@sentry/node": "7.37.1",
"@sentry/tracing": "7.37.1",
"accepts": "1.3.8",
"axios": "0.23.0",
"bad-words": "3.0.4",
+21 -9
View File
@@ -2,6 +2,7 @@ const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
const Sentry = require('@sentry/node');
const Tracing = require('@sentry/tracing');
const createDebugger = require('debug');
const _ = require('lodash');
const loopback = require('loopback');
@@ -14,15 +15,6 @@ const { setupPassport } = require('./component-passport');
const log = createDebugger('fcc:server');
const reqLogFormat = ':date[iso] :status :method :response-time ms - :url';
if (sentry.dsn === 'dsn_from_sentry_dashboard') {
log('Sentry reporting disabled unless DSN is provided.');
} else {
Sentry.init({
dsn: sentry.dsn
});
log('Sentry initialized');
}
const app = loopback();
app.set('state namespace', '__fcc__');
@@ -62,6 +54,7 @@ db.on(
'connected',
_.once(() => log('db connected'))
);
app.start = _.once(function () {
const server = app.listen(app.get('port'), function () {
app.emit('started');
@@ -89,6 +82,25 @@ app.start = _.once(function () {
});
});
if (sentry.dsn === 'dsn_from_sentry_dashboard') {
log('Sentry reporting disabled unless DSN is provided.');
} else {
Sentry.init({
dsn: sentry.dsn,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({
app
})
],
// Capture 20% of transactions to avoid
// overwhelming Sentry and remain within
// the usage quota
tracesSampleRate: 0.2
});
log('Sentry initialized');
}
module.exports = app;
if (require.main === module) {
+2 -1
View File
@@ -1,6 +1,7 @@
{
"initial:before": {
"./middlewares/sentry-request-handler": {}
"./middlewares/sentry-request-handler": {},
"./middlewares/sentry-tracing-handler": {}
},
"initial": {
"compression": {},
@@ -0,0 +1,8 @@
import { Handlers } from '@sentry/node';
import { sentry } from '../../../../config/secrets';
export default function sentryRequestHandler() {
return sentry.dsn === 'dsn_from_sentry_dashboard'
? (req, res, next) => next()
: Handlers.tracingHandler();
}
+160 -14
View File
@@ -114,7 +114,8 @@
"license": "BSD-3-Clause",
"dependencies": {
"@freecodecamp/loopback-component-passport": "1.2.0",
"@sentry/node": "6.19.7",
"@sentry/node": "7.37.1",
"@sentry/tracing": "7.37.1",
"accepts": "1.3.8",
"axios": "0.23.0",
"bad-words": "3.0.4",
@@ -5387,20 +5388,53 @@
}
},
"node_modules/@sentry/node": {
"version": "6.19.7",
"license": "BSD-3-Clause",
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.37.1.tgz",
"integrity": "sha512-nGerngIo5JwinJgl7m0SaL/xI+YRBlhb53gbkuLSAAcnoitBFzbp7LjywsqYFTWuWDIyk7O2t124GNxtolBAgA==",
"dependencies": {
"@sentry/core": "6.19.7",
"@sentry/hub": "6.19.7",
"@sentry/types": "6.19.7",
"@sentry/utils": "6.19.7",
"@sentry/core": "7.37.1",
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"cookie": "^0.4.1",
"https-proxy-agent": "^5.0.0",
"lru_map": "^0.3.3",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=6"
"node": ">=8"
}
},
"node_modules/@sentry/node/node_modules/@sentry/core": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.37.1.tgz",
"integrity": "sha512-eS5hoFDjAOl7POZg6K77J0oiypiqR1782oVSB49UkjK+D8tCZzZ5PxPMv0b/O0310p7x4oZ3WGRJaWEN3vY4KQ==",
"dependencies": {
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/node/node_modules/@sentry/types": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.37.1.tgz",
"integrity": "sha512-c2HWyWSgVA0V4+DSW2qVb0yjftrb1X/q2CzCom+ayjGHO72qyWC+9Tc+7ZfotU1mapRjqUWBgkXkbGmao8N8Ug==",
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/node/node_modules/@sentry/utils": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.37.1.tgz",
"integrity": "sha512-/4mJOyDsfysx+5TXyJgSI+Ihw2/0EVJbrHjCyXPDXW5ADwbtU8VdBZ0unOmF0hk4QfftqwM9cyEu3BN4iBJsEA==",
"dependencies": {
"@sentry/types": "7.37.1",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/react": {
@@ -5421,6 +5455,53 @@
"react": "15.x || 16.x || 17.x || 18.x"
}
},
"node_modules/@sentry/tracing": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.37.1.tgz",
"integrity": "sha512-3mQG2XtMCGqDkgfzhKpRJAIfRaokNAOF8WafgAmFmZQwEDsRAFjZ3pLoO+KiBUeQE5E5et7HyWBOl9rqHCkWnQ==",
"dependencies": {
"@sentry/core": "7.37.1",
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/tracing/node_modules/@sentry/core": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.37.1.tgz",
"integrity": "sha512-eS5hoFDjAOl7POZg6K77J0oiypiqR1782oVSB49UkjK+D8tCZzZ5PxPMv0b/O0310p7x4oZ3WGRJaWEN3vY4KQ==",
"dependencies": {
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/tracing/node_modules/@sentry/types": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.37.1.tgz",
"integrity": "sha512-c2HWyWSgVA0V4+DSW2qVb0yjftrb1X/q2CzCom+ayjGHO72qyWC+9Tc+7ZfotU1mapRjqUWBgkXkbGmao8N8Ug==",
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/tracing/node_modules/@sentry/utils": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.37.1.tgz",
"integrity": "sha512-/4mJOyDsfysx+5TXyJgSI+Ihw2/0EVJbrHjCyXPDXW5ADwbtU8VdBZ0unOmF0hk4QfftqwM9cyEu3BN4iBJsEA==",
"dependencies": {
"@sentry/types": "7.37.1",
"tslib": "^1.9.3"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/types": {
"version": "6.19.7",
"license": "BSD-3-Clause",
@@ -55587,7 +55668,8 @@
"@babel/preset-env": "7.18.0",
"@babel/register": "7.17.7",
"@freecodecamp/loopback-component-passport": "1.2.0",
"@sentry/node": "6.19.7",
"@sentry/node": "7.37.1",
"@sentry/tracing": "7.37.1",
"accepts": "1.3.8",
"axios": "0.23.0",
"babel-core": "7.0.0-bridge.0",
@@ -57572,16 +57654,43 @@
}
},
"@sentry/node": {
"version": "6.19.7",
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.37.1.tgz",
"integrity": "sha512-nGerngIo5JwinJgl7m0SaL/xI+YRBlhb53gbkuLSAAcnoitBFzbp7LjywsqYFTWuWDIyk7O2t124GNxtolBAgA==",
"requires": {
"@sentry/core": "6.19.7",
"@sentry/hub": "6.19.7",
"@sentry/types": "6.19.7",
"@sentry/utils": "6.19.7",
"@sentry/core": "7.37.1",
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"cookie": "^0.4.1",
"https-proxy-agent": "^5.0.0",
"lru_map": "^0.3.3",
"tslib": "^1.9.3"
},
"dependencies": {
"@sentry/core": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.37.1.tgz",
"integrity": "sha512-eS5hoFDjAOl7POZg6K77J0oiypiqR1782oVSB49UkjK+D8tCZzZ5PxPMv0b/O0310p7x4oZ3WGRJaWEN3vY4KQ==",
"requires": {
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"tslib": "^1.9.3"
}
},
"@sentry/types": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.37.1.tgz",
"integrity": "sha512-c2HWyWSgVA0V4+DSW2qVb0yjftrb1X/q2CzCom+ayjGHO72qyWC+9Tc+7ZfotU1mapRjqUWBgkXkbGmao8N8Ug=="
},
"@sentry/utils": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.37.1.tgz",
"integrity": "sha512-/4mJOyDsfysx+5TXyJgSI+Ihw2/0EVJbrHjCyXPDXW5ADwbtU8VdBZ0unOmF0hk4QfftqwM9cyEu3BN4iBJsEA==",
"requires": {
"@sentry/types": "7.37.1",
"tslib": "^1.9.3"
}
}
}
},
"@sentry/react": {
@@ -57595,6 +57704,43 @@
"tslib": "^1.9.3"
}
},
"@sentry/tracing": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/tracing/-/tracing-7.37.1.tgz",
"integrity": "sha512-3mQG2XtMCGqDkgfzhKpRJAIfRaokNAOF8WafgAmFmZQwEDsRAFjZ3pLoO+KiBUeQE5E5et7HyWBOl9rqHCkWnQ==",
"requires": {
"@sentry/core": "7.37.1",
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"tslib": "^1.9.3"
},
"dependencies": {
"@sentry/core": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.37.1.tgz",
"integrity": "sha512-eS5hoFDjAOl7POZg6K77J0oiypiqR1782oVSB49UkjK+D8tCZzZ5PxPMv0b/O0310p7x4oZ3WGRJaWEN3vY4KQ==",
"requires": {
"@sentry/types": "7.37.1",
"@sentry/utils": "7.37.1",
"tslib": "^1.9.3"
}
},
"@sentry/types": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.37.1.tgz",
"integrity": "sha512-c2HWyWSgVA0V4+DSW2qVb0yjftrb1X/q2CzCom+ayjGHO72qyWC+9Tc+7ZfotU1mapRjqUWBgkXkbGmao8N8Ug=="
},
"@sentry/utils": {
"version": "7.37.1",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.37.1.tgz",
"integrity": "sha512-/4mJOyDsfysx+5TXyJgSI+Ihw2/0EVJbrHjCyXPDXW5ADwbtU8VdBZ0unOmF0hk4QfftqwM9cyEu3BN4iBJsEA==",
"requires": {
"@sentry/types": "7.37.1",
"tslib": "^1.9.3"
}
}
}
},
"@sentry/types": {
"version": "6.19.7"
},