@lensmcp/nest-instrumentation 1.21.2 → 1.21.4
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.
- package/lib/trace-interceptor.js +3 -1
- package/package.json +4 -4
package/lib/trace-interceptor.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.defineProperty;var m=(e,t)=>j(e,"name",{value:t,configurable:!0});var E=Object.defineProperty,u=m((e,t)=>E(e,"name",{value:t,configurable:!0}),"m");import{__decorate as M}from"tslib";import{Injectable as N}from"@nestjs/common";import{Observable as T}from"rxjs";import{catchError as A,tap as O}from"rxjs/operators";import{fingerprint as x,ulid as y}from"@lensmcp/core";import{activeMemoryOptions as R,onFlowStart as _,onFlowSettled as H}from"@lensmcp/memory-tracker";import{LENSMCP_CONTEXT_STORAGE as F}from"./context.js";import{activeOptions as h}from"./state.js";let C=class{static{m(this,"k")}static{u(this,"TraceInterceptor")}intercept(e,t){const s=h();if(!s.trace.requests)return t.handle();const a=e.switchToHttp(),r=a.getRequest(),i=a.getResponse(),o=w(r.headers?.["x-request-id"])??y(),n={sessionId:s.sessionId,requestId:o,flowId:w(r.headers?.["x-lensmcp-flow-id"]),originNodeId:w(r.headers?.["x-lensmcp-origin-node-id"]),traceparent:w(r.headers?.traceparent),dbCallCount:0},c=(r.method??"GET").toUpperCase(),p=r.route?.path??r.url??"<unknown>",f=e.getClass?.()?.name,g=e.getHandler?.()?.name,q=Date.now(),v=s.memory.mode!=="off";v&&_(o);const b=u(()=>{if(!v)return;const l=R()?.settleMs??1e3;setTimeout(()=>H(o),l).unref?.()},"settleAndCheck");return new T(l=>{F.run(n,()=>{t.handle().pipe(O({next:u(I=>l.next(I),"next"),complete:u(()=>{$(s.projectName,n,c,p,i.statusCode??200,q),k(n,f,g,q,"ok"),b(),l.complete()},"complete")}),A(I=>{const d=I,S=typeof d?.getStatus=="function"?d.getStatus():typeof d?.status=="number"&&d.status>=100?d.status:typeof d?.statusCode=="number"&&d.statusCode>=100?d.statusCode:i.statusCode&&i.statusCode>=400?i.statusCode:500;return $(s.projectName,n,c,p,S,q,I),k(n,f,g,q,"error"),b(),l.error(I),new T})).subscribe()})})}};C=M([N()],C);export{C as TraceInterceptor};function w(e){if(typeof e=="string")return e;if(Array.isArray(e)&&typeof e[0]=="string")return e[0]}m(w,"q"),u(w,"stringHeader");function k(e,t,s,a,r){if(!t||!s)return;const i=h(),o=Date.now()-a,n=`${t}.${s}`;i.emit({id:y(),sessionId:e.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:r==="error"?"error":"info",context:{sessionId:e.sessionId,flowId:e.flowId,requestId:e.requestId},fingerprint:x({kind:"method-call",identity:n}),title:`${n} (${o}ms)${r==="error"?" \u2717":""}`,raw:{kind:"span",span:{name:n,role:"controller",flowId:e.flowId,requestId:e.requestId,startTime:a,endTime:Date.now(),durationMs:o,status:r}}})}m(k,"E"),u(k,"emitControllerSpan");function D(e){if(!(e instanceof Error))return{message:String(e)};const t=e.stack?e.stack.split(`
|
|
2
|
+
`).slice(0,30).join(`
|
|
3
|
+
`):void 0;return{...e.name?{name:e.name}:{},message:e.message,...t?{stack:t}:{}}}m(D,"F"),u(D,"errorDetail");function $(e,t,s,a,r,i,o){const n=h(),c=Date.now()-i,p=r>=500||o!==void 0,f={id:y(),sessionId:t.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:p?"error":"info",context:{sessionId:t.sessionId,flowId:t.flowId,requestId:t.requestId,originNodeId:t.originNodeId,traceparent:t.traceparent},fingerprint:x({kind:"server-request",identity:`${s}:${a}:${Math.floor(r/100)}xx`}),title:`${s} ${a} \u2192 ${r} (${c}ms)`,message:o instanceof Error?o.message:void 0,raw:{kind:"server-request",request:{method:s,route:a,status:r,durationMs:c,startedAt:i,endedAt:Date.now(),flowId:t.flowId,requestId:t.requestId,...o?{error:D(o)}:{}}}},g={...f,id:y(),raw:{kind:"span",span:{name:`nest.request ${s} ${a}`,traceId:t.traceparent,flowId:t.flowId,requestId:t.requestId,startTime:i,endTime:Date.now(),durationMs:c,status:p?"error":"ok"}}};n.emit(f),n.emit(g)}m($,"S"),u($,"emitRequest");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/nest-instrumentation",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.4",
|
|
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.21.
|
|
18
|
-
"@lensmcp/memory-tracker": "1.21.
|
|
19
|
-
"@lensmcp/protocol-types": "1.21.
|
|
17
|
+
"@lensmcp/core": "1.21.4",
|
|
18
|
+
"@lensmcp/memory-tracker": "1.21.4",
|
|
19
|
+
"@lensmcp/protocol-types": "1.21.4",
|
|
20
20
|
"tslib": "^2.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|