import{withPathPrefix as u}from"@redocly/theme/core/utils";import{OTEL_EXCLUDED_ROUTES as o}from"../../constants/common.js";import{telemetryTraceStep as a}from"../../telemetry/helpers/trace-step.js";import{getClientIp as m}from"../utils/get-client-ip.js";function A(){return async(e,r)=>{if(o.some(t=>e.req.path===u(t)))return r();await a("request",async t=>{t?.setAttribute("method",e.req.method||""),t?.setAttribute("host",e.req.header("host")||""),t?.setAttribute("url",e.req.url||""),t?.setAttribute("path",e.req.path||""),t?.setAttribute("user_agent",e.req.header("user-agent")||"");const s=e.get("auth")?.claims?.id||e.get("auth")?.claims?.sub,i=m(e.req.raw)||e.req.raw.context.remoteAddr?.ipAddress;t?.setAttribute("user_id",s),t?.setAttribute("user_ip",i),await r()})}}export{A as telemetryMiddleware};
