mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
* feat(core): add honeybadger support * feat(honeybadger): configure Honeybadger to disable uncaught error tracking * feat(tests): add info logger mock to app-bootstrap tests * test: fix mock value * test: mock honeybadger as well
29 lines
822 B
TypeScript
29 lines
822 B
TypeScript
import * as Sentry from '@sentry/node';
|
|
import type { MiddlewareHandler } from 'hono';
|
|
|
|
import { config } from '@/config';
|
|
import { getRouteNameFromPath } from '@/utils/helpers';
|
|
import logger from '@/utils/logger';
|
|
|
|
if (config.sentry.dsn) {
|
|
Sentry.init({
|
|
dsn: config.sentry.dsn,
|
|
});
|
|
Sentry.getCurrentScope().setTag('node_name', config.nodeName);
|
|
|
|
logger.info('Sentry inited.');
|
|
}
|
|
|
|
const middleware: MiddlewareHandler = async (ctx, next) => {
|
|
const time = Date.now();
|
|
await next();
|
|
if (config.sentry.dsn && Date.now() - time >= config.errorTrackingRouteTimeout) {
|
|
Sentry.withScope((scope) => {
|
|
scope.setTag('name', getRouteNameFromPath(ctx.req.path));
|
|
Sentry.captureException(new Error('Route Timeout'));
|
|
});
|
|
}
|
|
};
|
|
|
|
export default middleware;
|