feat: support Sentry

This commit is contained in:
DIYgod
2019-09-03 18:11:05 +08:00
parent 2ca197b622
commit 7c65bb5b18
6 changed files with 99 additions and 3 deletions

View File

@@ -1,4 +1,15 @@
const logger = require('@/utils/logger');
const config = require('@/config');
const Sentry = require('@sentry/node');
if (config.sentry) {
Sentry.init({
dsn: config.sentry,
});
Sentry.configureScope((scope) => {
scope.setTag('node_name', config.nodeName);
});
}
module.exports = async (ctx, next) => {
try {
@@ -20,5 +31,13 @@ module.exports = async (ctx, next) => {
ctx.debug.errorRoutes[ctx._matchedRoute] = 0;
}
ctx.debug.errorRoutes[ctx._matchedRoute]++;
if (config.sentry) {
Sentry.withScope((scope) => {
scope.setTag('route', ctx._matchedRoute);
scope.addEventProcessor((event) => Sentry.Handlers.parseRequest(event, ctx.request));
Sentry.captureException(err);
});
}
}
};