mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 04:11:26 +08:00
feat: support Sentry
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user