Files
RSSHub/lib/middleware/trace.ts
T
Nya Candyandincubator4 68c7430fbb feat(core): opentelementry support (update of #14668) (#16087)
* chore: squash commit

* fix: tweak some mentioned issues

---------

Co-authored-by: incubator4 <aries0robin@gmail.com>
2024-07-05 19:22:33 +08:00

26 lines
682 B
TypeScript

import { MiddlewareHandler } from 'hono';
import { getPath } from '@/utils/helpers';
import { config } from '@/config';
import { tracer } from '@/utils/otel';
const middleware: MiddlewareHandler = async (ctx, next) => {
if (config.debugInfo) {
// Only enable tracing in debug mode
const { method, raw } = ctx.req;
const path = getPath(raw);
const span = tracer.startSpan(`${method} ${path}`, {
kind: 1, // server
attributes: {},
});
span.addEvent('invoking handleRequest');
await next();
span.end();
} else {
// Skip
await next();
}
};
export default middleware;