mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 04:08:21 +00:00
22 lines
557 B
TypeScript
22 lines
557 B
TypeScript
import opentelemetry from "@opentelemetry/api";
|
|
import fp from "fastify-plugin";
|
|
|
|
export const apiMetrics = fp(async (fastify) => {
|
|
const apiMeter = opentelemetry.metrics.getMeter("API");
|
|
const latencyHistogram = apiMeter.createHistogram("API_latency", {
|
|
unit: "ms"
|
|
});
|
|
|
|
fastify.addHook("onResponse", async (request, reply) => {
|
|
const { method } = request;
|
|
const route = request.routerPath;
|
|
const { statusCode } = reply;
|
|
|
|
latencyHistogram.record(reply.elapsedTime, {
|
|
route,
|
|
method,
|
|
statusCode
|
|
});
|
|
});
|
|
});
|