@lensmcp/nest-instrumentation 1.21.5 → 1.22.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.
- package/lib/event-sink.js +3 -3
- package/lib/lensmcp-app.d.ts +13 -1
- package/lib/trace-interceptor.js +2 -2
- package/package.json +4 -4
package/lib/event-sink.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`
|
|
3
|
-
`);e.length>1e4;)e.shift();if(
|
|
1
|
+
"use strict";var m=Object.defineProperty;var u=(n,e)=>m(n,"name",{value:e,configurable:!0});var d=Object.defineProperty,c=u((n,e)=>d(n,"name",{value:e,configurable:!0}),"s");import{createSocket as S}from"node:dgram";import{connect as v}from"node:net";import{appendFile as y}from"node:fs/promises";import{boundedClone as E,createEventFloodGuard as h,DEFAULT_RAW_BYTE_LIMIT as g}from"@lensmcp/protocol-types";import{maybeRotateEventFile as k}from"@lensmcp/protocol-types/bounded-writer";export function defaultEventSink(){const n=process.env.LENSMCP_EVENT_FILE;if(n){const r=h({burst:30,perSec:5});let i=Promise.resolve();return s=>{const o=r.admit(String(s.fingerprint??""));if(!o.ok)return;const a=f(s,o.suppressed);a&&(i=i.then(async()=>{k(n,a.length),await y(n,a).catch(()=>{})}))}}const e=process.env.LENSMCP_UDS;if(e)return l(e);const t=process.env.LENSMCP_IPC_SOCKET;if(t){const[r,i]=t.split(":");if(r&&i){const s=Number(i),o=S("udp4");return o.unref(),a=>{try{const p=Buffer.from(JSON.stringify(a));o.send(p,s,r,()=>{})}catch{}}}}return r=>{(r.severity==="error"||r.severity==="fatal")&&console.warn(`[lensmcp] ${r.severity}: ${r.title}`)}}u(defaultEventSink,"defaultEventSink"),c(defaultEventSink,"defaultEventSink");function f(n,e){try{const t=E(n.raw,{rawByteLimit:g}).value,r={...n,raw:t};return e>0&&(r.floodSuppressed=e),JSON.stringify(r)+`
|
|
2
|
+
`}catch{return}}u(f,"E"),c(f,"serializeBounded");export function inMemorySink(){const n=[];return{sink:c(e=>n.push(e),"sink"),events:n}}u(inMemorySink,"inMemorySink"),c(inMemorySink,"inMemorySink");function l(n){const e=[];let t=null,r=!1;const i=c(()=>{if(!(!t||!t.writable))for(;e.length>0;)t.write(e.shift())},"flush"),s=c(()=>{if(r||t)return;r=!0;const o=v(n);o.on("connect",()=>{r=!1,t=o,i()}),o.on("drain",i),o.on("error",()=>{r=!1,t=null}),o.on("close",()=>{t=null}),o.unref()},"open");return s(),o=>{for(e.push(JSON.stringify(o)+`
|
|
3
|
+
`);e.length>1e4;)e.shift();if(t&&t.writable){i();return}if(t){try{t.destroy()}catch{}t=null}s()}}u(l,"w"),c(l,"udsEventSink");
|
package/lib/lensmcp-app.d.ts
CHANGED
|
@@ -20,4 +20,16 @@ export interface CreateLensmcpNestAppOptions extends Partial<LensmcpModuleOption
|
|
|
20
20
|
/** Forwarded to `NestFactory.create` (logger, cors, etc.). */
|
|
21
21
|
nestOptions?: NestApplicationOptions;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The adapter generic is carried through, exactly as `NestFactory.create` carries it
|
|
25
|
+
* (issues/codex-security/59).
|
|
26
|
+
*
|
|
27
|
+
* const app = await createLensmcpNestApp<NestExpressApplication>(AppModule, { projectName: 'api' });
|
|
28
|
+
* app.useStaticAssets(join(__dirname, 'public'));
|
|
29
|
+
*
|
|
30
|
+
* Declaring the return as a bare `Promise<INestApplication>` meant the codemod's rewrite of
|
|
31
|
+
* `NestFactory.create<NestExpressApplication>(AppModule)` stopped type-checking every
|
|
32
|
+
* adapter-specific method the app used — `useStaticAssets`, `setViewEngine`, the Fastify surface —
|
|
33
|
+
* and the generated `main.ts` no longer compiled.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createLensmcpNestApp<T extends INestApplication = INestApplication>(appModule: Type<unknown> | DynamicModule, options?: CreateLensmcpNestAppOptions): Promise<T>;
|
package/lib/trace-interceptor.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var c=(e,t)=>E(e,"name",{value:t,configurable:!0});var M=Object.defineProperty,u=c((e,t)=>M(e,"name",{value:t,configurable:!0}),"u");import{__decorate as N}from"tslib";import{Injectable as A}from"@nestjs/common";import{Observable as x}from"rxjs";import{catchError as O,tap as R}from"rxjs/operators";import{fingerprint as D,ulid as y}from"@lensmcp/core";import{activeMemoryOptions as _,onFlowStart as H,onFlowSettled as F}from"@lensmcp/memory-tracker";import{LENSMCP_CONTEXT_STORAGE as G}from"./context.js";import{activeOptions as h}from"./state.js";let C=class{static{c(this,"$")}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},m=(r.method??"GET").toUpperCase(),p=r.route?.path??r.url??"<unknown>",f=e.getClass?.()?.name,g=e.getHandler?.()?.name,q=Date.now(),$=s.memory.mode!=="off";$&&H(o);const v=u(()=>{if(!$)return;const l=_()?.settleMs??1e3;setTimeout(()=>F(o),l).unref?.()},"settleAndCheck");return new x(l=>{let T;return G.run(n,()=>{T=t.handle().pipe(R({next:u(I=>l.next(I),"next"),complete:u(()=>{k(s.projectName,n,m,p,i.statusCode??200,q),b(n,f,g,q,"ok"),v(),l.complete()},"complete")}),O(I=>{const d=I,j=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 k(s.projectName,n,m,p,j,q,I),b(n,f,g,q,"error"),v(),l.error(I),new x})).subscribe()}),()=>T?.unsubscribe()})}};C=N([A()],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]}c(w,"q"),u(w,"stringHeader");function b(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:D({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}}})}c(b,"S"),u(b,"emitControllerSpan");function S(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}:{}}}
|
|
3
|
+
`):void 0;return{...e.name?{name:e.name}:{},message:e.message,...t?{stack:t}:{}}}c(S,"G"),u(S,"errorDetail");function k(e,t,s,a,r,i,o){const n=h(),m=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:D({kind:"server-request",identity:`${s}:${a}:${Math.floor(r/100)}xx`}),title:`${s} ${a} \u2192 ${r} (${m}ms)`,message:o instanceof Error?o.message:void 0,raw:{kind:"server-request",request:{method:s,route:a,status:r,durationMs:m,startedAt:i,endedAt:Date.now(),flowId:t.flowId,requestId:t.requestId,...o?{error:S(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:m,status:p?"error":"ok"}}};n.emit(f),n.emit(g)}c(k,"b"),u(k,"emitRequest");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/nest-instrumentation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.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.
|
|
18
|
-
"@lensmcp/memory-tracker": "1.
|
|
19
|
-
"@lensmcp/protocol-types": "1.
|
|
17
|
+
"@lensmcp/core": "1.22.0",
|
|
18
|
+
"@lensmcp/memory-tracker": "1.22.0",
|
|
19
|
+
"@lensmcp/protocol-types": "1.22.0",
|
|
20
20
|
"tslib": "^2.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|