mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-19 13:24:23 +01:00
HTTP Response metrics
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { MiddlewareHandler } from '@hono/hono';
|
||||
|
||||
import { httpRequestCounter } from '@/metrics.ts';
|
||||
import { httpRequestCounter, httpResponseCounter } from '@/metrics.ts';
|
||||
|
||||
export const metricsMiddleware: MiddlewareHandler = async (c, next) => {
|
||||
const { method } = c.req;
|
||||
httpRequestCounter.inc({ method });
|
||||
|
||||
await next();
|
||||
|
||||
const { status } = c.res;
|
||||
const path = c.req.matchedRoutes.find((r) => r.method !== 'ALL')?.path ?? c.req.routePath;
|
||||
httpResponseCounter.inc({ status, path });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user