@lensmcp/nest-instrumentation 1.22.5 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- "use strict";var S=Object.defineProperty;var m=(e,t)=>S(e,"name",{value:t,configurable:!0});var E=Object.defineProperty,u=m((e,t)=>E(e,"name",{value:t,configurable:!0}),"u");import{__decorate as M}from"tslib";import{Injectable as A}from"@nestjs/common";import{Observable as x}from"rxjs";import{catchError as O,tap as _}from"rxjs/operators";import{fingerprint as R,ulid as h}from"@lensmcp/core";import{activeMemoryOptions as H,onFlowStart as P,onFlowSettled as F}from"@lensmcp/memory-tracker";import{LENSMCP_CONTEXT_STORAGE as G}from"./context.js";import{activeOptions as y}from"./state.js";let b=class{static{m(this,"$")}static{u(this,"TraceInterceptor")}intercept(e,t){const r=y();if(!r.trace.requests)return t.handle();const a=e.switchToHttp(),s=a.getRequest(),i=a.getResponse(),o=f(s.headers?.["x-request-id"])??h(),n={sessionId:r.sessionId,requestId:o,parentRequestId:f(s.headers?.["x-lensmcp-parent-request-id"]),flowId:f(s.headers?.["x-lensmcp-flow-id"]),originNodeId:f(s.headers?.["x-lensmcp-origin-node-id"]),traceparent:f(s.headers?.traceparent),dbCallCount:0},d=(s.method??"GET").toUpperCase(),l=s.route?.path??s.url??"<unknown>",p=e.getClass?.()?.name,I=e.getHandler?.()?.name,g=Date.now(),$=r.memory.mode!=="off";$&&P(o);const T=u(()=>{if(!$)return;const w=H()?.settleMs??1e3;setTimeout(()=>F(o),w).unref?.()},"settleAndCheck");return new x(w=>{let j;return G.run(n,()=>{j=t.handle().pipe(_({next:u(q=>w.next(q),"next"),complete:u(()=>{v(r.projectName,n,d,l,i.statusCode??200,g),k(n,p,I,g,"ok"),T(),w.complete()},"complete")}),O(q=>{const c=q,N=typeof c?.getStatus=="function"?c.getStatus():typeof c?.status=="number"&&c.status>=100?c.status:typeof c?.statusCode=="number"&&c.statusCode>=100?c.statusCode:i.statusCode&&i.statusCode>=400?i.statusCode:500;return v(r.projectName,n,d,l,N,g,q),k(n,p,I,g,"error"),T(),w.error(q),new x})).subscribe()}),()=>j?.unsubscribe()})}};b=M([A()],b);export{b as TraceInterceptor};function f(e){if(typeof e=="string")return e;if(Array.isArray(e)&&typeof e[0]=="string")return e[0]}m(f,"w"),u(f,"stringHeader");function k(e,t,r,a,s){if(!t||!r)return;const i=y(),o=Date.now()-a,n=`${t}.${r}`,d={id:h(),sessionId:e.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:s==="error"?"error":"info",context:{sessionId:e.sessionId,flowId:e.flowId,requestId:e.requestId},fingerprint:R({kind:"method-call",identity:n}),title:`${n} (${o}ms)${s==="error"?" \u2717":""}`,raw:{kind:"span",span:{name:n,role:"controller",flowId:e.flowId,requestId:e.requestId,startTime:a,endTime:Date.now(),durationMs:o,status:s}}};C(d,y().projectName),i.emit(d)}m(k,"S"),u(k,"emitControllerSpan");function D(e){if(!(e instanceof Error))return{message:String(e)};const t=e.stack?e.stack.split(`
1
+ "use strict";var S=Object.defineProperty;var m=(e,t)=>S(e,"name",{value:t,configurable:!0});var E=Object.defineProperty,u=m((e,t)=>E(e,"name",{value:t,configurable:!0}),"u");import{__decorate as M}from"tslib";import{Injectable as A}from"@nestjs/common";import{Observable as x}from"rxjs";import{catchError as O,tap as _}from"rxjs/operators";import{fingerprint as R,ulid as h}from"@lensmcp/core";import{activeMemoryOptions as H,onFlowStart as P,onFlowSettled as F}from"@lensmcp/memory-tracker";import{LENSMCP_CONTEXT_STORAGE as G}from"./context.js";import{activeOptions as y}from"./state.js";let b=class{static{m(this,"$")}static{u(this,"TraceInterceptor")}intercept(e,t){const r=y();if(!r.trace.requests)return t.handle();const a=e.switchToHttp(),s=a.getRequest(),i=a.getResponse(),n=f(s.headers?.["x-request-id"])??h(),o={sessionId:r.sessionId,requestId:n,parentRequestId:f(s.headers?.["x-lensmcp-parent-request-id"]),flowId:f(s.headers?.["x-lensmcp-flow-id"]),originNodeId:f(s.headers?.["x-lensmcp-origin-node-id"]),traceparent:f(s.headers?.traceparent),dbCallCount:0},d=(s.method??"GET").toUpperCase(),l=s.route?.path??s.url??"<unknown>",p=e.getClass?.()?.name,I=e.getHandler?.()?.name,g=Date.now(),$=r.memory.mode!=="off";$&&P(n);const T=u(()=>{if(!$)return;const w=H()?.settleMs??1e3;setTimeout(()=>F(n,o.flowId),w).unref?.()},"settleAndCheck");return new x(w=>{let j;return G.run(o,()=>{j=t.handle().pipe(_({next:u(q=>w.next(q),"next"),complete:u(()=>{v(r.projectName,o,d,l,i.statusCode??200,g),k(o,p,I,g,"ok"),T(),w.complete()},"complete")}),O(q=>{const c=q,N=typeof c?.getStatus=="function"?c.getStatus():typeof c?.status=="number"&&c.status>=100?c.status:typeof c?.statusCode=="number"&&c.statusCode>=100?c.statusCode:i.statusCode&&i.statusCode>=400?i.statusCode:500;return v(r.projectName,o,d,l,N,g,q),k(o,p,I,g,"error"),T(),w.error(q),new x})).subscribe()}),()=>j?.unsubscribe()})}};b=M([A()],b);export{b as TraceInterceptor};function f(e){if(typeof e=="string")return e;if(Array.isArray(e)&&typeof e[0]=="string")return e[0]}m(f,"w"),u(f,"stringHeader");function k(e,t,r,a,s){if(!t||!r)return;const i=y(),n=Date.now()-a,o=`${t}.${r}`,d={id:h(),sessionId:e.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:s==="error"?"error":"info",context:{sessionId:e.sessionId,flowId:e.flowId,requestId:e.requestId},fingerprint:R({kind:"method-call",identity:o}),title:`${o} (${n}ms)${s==="error"?" \u2717":""}`,raw:{kind:"span",span:{name:o,role:"controller",flowId:e.flowId,requestId:e.requestId,startTime:a,endTime:Date.now(),durationMs:n,status:s}}};C(d,y().projectName),i.emit(d)}m(k,"S"),u(k,"emitControllerSpan");function D(e){if(!(e instanceof Error))return{message:String(e)};const t=e.stack?e.stack.split(`
2
2
  `).slice(0,30).join(`
3
- `):void 0;return{...e.name?{name:e.name}:{},message:e.message,...t?{stack:t}:{}}}m(D,"P"),u(D,"errorDetail");function C(e,t){if(!t)return;const r=e.raw;r&&r.project===void 0&&(r.project=t)}m(C,"h"),u(C,"stampProject");function v(e,t,r,a,s,i,o){const n=y(),d=Date.now()-i,l=s>=500||o!==void 0,p={id:h(),sessionId:t.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:l?"error":"info",context:{sessionId:t.sessionId,flowId:t.flowId,requestId:t.requestId,...t.parentRequestId?{parentRequestId:t.parentRequestId}:{},originNodeId:t.originNodeId,traceparent:t.traceparent},fingerprint:R({kind:"server-request",identity:`${r}:${a}:${Math.floor(s/100)}xx`}),title:`${r} ${a} \u2192 ${s} (${d}ms)`,message:o instanceof Error?o.message:void 0,raw:{kind:"server-request",request:{method:r,route:a,status:s,durationMs:d,startedAt:i,endedAt:Date.now(),flowId:t.flowId,requestId:t.requestId,...t.parentRequestId?{parentRequestId:t.parentRequestId}:{},...o?{error:D(o)}:{}}}},I={...p,id:h(),raw:{kind:"span",span:{name:`nest.request ${r} ${a}`,traceId:t.traceparent,flowId:t.flowId,requestId:t.requestId,startTime:i,endTime:Date.now(),durationMs:d,status:l?"error":"ok"}}};C(p,e),C(I,e),n.emit(p),n.emit(I)}m(v,"b"),u(v,"emitRequest");
3
+ `):void 0;return{...e.name?{name:e.name}:{},message:e.message,...t?{stack:t}:{}}}m(D,"P"),u(D,"errorDetail");function C(e,t){if(!t)return;const r=e.raw;r&&r.project===void 0&&(r.project=t)}m(C,"h"),u(C,"stampProject");function v(e,t,r,a,s,i,n){const o=y(),d=Date.now()-i,l=s>=500||n!==void 0,p={id:h(),sessionId:t.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:l?"error":"info",context:{sessionId:t.sessionId,flowId:t.flowId,requestId:t.requestId,...t.parentRequestId?{parentRequestId:t.parentRequestId}:{},originNodeId:t.originNodeId,traceparent:t.traceparent},fingerprint:R({kind:"server-request",identity:`${r}:${a}:${Math.floor(s/100)}xx`}),title:`${r} ${a} \u2192 ${s} (${d}ms)`,message:n instanceof Error?n.message:void 0,raw:{kind:"server-request",request:{method:r,route:a,status:s,durationMs:d,startedAt:i,endedAt:Date.now(),flowId:t.flowId,requestId:t.requestId,...t.parentRequestId?{parentRequestId:t.parentRequestId}:{},...n?{error:D(n)}:{}}}},I={...p,id:h(),raw:{kind:"span",span:{name:`nest.request ${r} ${a}`,traceId:t.traceparent,flowId:t.flowId,requestId:t.requestId,startTime:i,endTime:Date.now(),durationMs:d,status:l?"error":"ok"}}};C(p,e),C(I,e),o.emit(p),o.emit(I)}m(v,"b"),u(v,"emitRequest");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/nest-instrumentation",
3
- "version": "1.22.5",
3
+ "version": "1.23.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -14,9 +14,9 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@lensmcp/core": "1.22.5",
18
- "@lensmcp/memory-tracker": "1.22.5",
19
- "@lensmcp/protocol-types": "1.22.5",
17
+ "@lensmcp/core": "1.23.0",
18
+ "@lensmcp/memory-tracker": "1.23.0",
19
+ "@lensmcp/protocol-types": "1.23.0",
20
20
  "tslib": "^2.3.0"
21
21
  },
22
22
  "peerDependencies": {