@lensmcp/nest-instrumentation 1.25.13 → 1.25.14
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/context.d.ts +9 -0
- package/lib/context.js +1 -1
- package/lib/instrument.js +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { LensmcpIgnore, traceWrap, isTraced, isIgnored } from './lib/instrument.
|
|
|
5
5
|
export { TraceInterceptor } from './lib/trace-interceptor.js';
|
|
6
6
|
export { LensmcpProviderTracker } from './lib/provider-tracker.js';
|
|
7
7
|
export { TraceProvider, readTraceProvider, type TraceProviderOptions, } from './lib/trace-provider.js';
|
|
8
|
-
export { LENSMCP_CONTEXT_STORAGE, currentLensmcpContext, runInLensmcpContext, type LensmcpRequestContext, } from './lib/context.js';
|
|
8
|
+
export { LENSMCP_CONTEXT_STORAGE, currentLensmcpContext, LENSMCP_SPAN_STORAGE, currentSpanId, runInLensmcpContext, type LensmcpRequestContext, } from './lib/context.js';
|
|
9
9
|
export { nextHopHeaders, type NextHopHeaderNames } from './lib/next-hop.js';
|
|
10
10
|
export { defaultEventSink, inMemorySink } from './lib/event-sink.js';
|
|
11
11
|
export type { LensmcpModuleOptions, EventSink, ResolvedOptions } from './lib/types.js';
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export{LensmcpModule}from"./lib/lensmcp.module.js";export{createLensmcpNestApp}from"./lib/lensmcp-app.js";export{TraceMethod}from"./lib/trace-method.js";export{LensmcpIgnore,traceWrap,isTraced,isIgnored}from"./lib/instrument.js";export{TraceInterceptor}from"./lib/trace-interceptor.js";export{LensmcpProviderTracker}from"./lib/provider-tracker.js";export{TraceProvider,readTraceProvider}from"./lib/trace-provider.js";export{LENSMCP_CONTEXT_STORAGE,currentLensmcpContext,runInLensmcpContext}from"./lib/context.js";export{nextHopHeaders}from"./lib/next-hop.js";export{defaultEventSink,inMemorySink}from"./lib/event-sink.js";
|
|
1
|
+
"use strict";export{LensmcpModule}from"./lib/lensmcp.module.js";export{createLensmcpNestApp}from"./lib/lensmcp-app.js";export{TraceMethod}from"./lib/trace-method.js";export{LensmcpIgnore,traceWrap,isTraced,isIgnored}from"./lib/instrument.js";export{TraceInterceptor}from"./lib/trace-interceptor.js";export{LensmcpProviderTracker}from"./lib/provider-tracker.js";export{TraceProvider,readTraceProvider}from"./lib/trace-provider.js";export{LENSMCP_CONTEXT_STORAGE,currentLensmcpContext,LENSMCP_SPAN_STORAGE,currentSpanId,runInLensmcpContext}from"./lib/context.js";export{nextHopHeaders}from"./lib/next-hop.js";export{defaultEventSink,inMemorySink}from"./lib/event-sink.js";
|
package/lib/context.d.ts
CHANGED
|
@@ -61,4 +61,13 @@ export interface LensmcpRequestContext {
|
|
|
61
61
|
}
|
|
62
62
|
export declare const LENSMCP_CONTEXT_STORAGE: AsyncLocalStorage<LensmcpRequestContext>;
|
|
63
63
|
export declare function currentLensmcpContext(): LensmcpRequestContext | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The traced call running now — its span id — so every span names the span it ran inside (`parentSpanId`). Time
|
|
66
|
+
* containment cannot tell a wrapper from the call it wraps when both start and end in the same millisecond: on
|
|
67
|
+
* FoodGuard (2026-10-21) `Repository.find` and the `EntityManager.find` it delegates to (93 ms each) came out siblings,
|
|
68
|
+
* drawn as two calls side by side, each «cpu-heavy» with the other's time. Its own store: the request context above is
|
|
69
|
+
* one object every call of the request shares (its counters are mutated in place), a span is one call's.
|
|
70
|
+
*/
|
|
71
|
+
export declare const LENSMCP_SPAN_STORAGE: AsyncLocalStorage<string>;
|
|
72
|
+
export declare function currentSpanId(): string | undefined;
|
|
64
73
|
export declare function runInLensmcpContext<T>(ctx: LensmcpRequestContext, fn: () => T): T;
|
package/lib/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var t=(e,n)=>c(e,"name",{value:n,configurable:!0});var u=Object.defineProperty,r=t((e,n)=>u(e,"name",{value:n,configurable:!0}),"t");import{AsyncLocalStorage as o}from"node:async_hooks";export const LENSMCP_CONTEXT_STORAGE=new o;export function currentLensmcpContext(){return LENSMCP_CONTEXT_STORAGE.getStore()}t(currentLensmcpContext,"currentLensmcpContext"),r(currentLensmcpContext,"currentLensmcpContext");export const LENSMCP_SPAN_STORAGE=new o;export function currentSpanId(){return LENSMCP_SPAN_STORAGE.getStore()}t(currentSpanId,"currentSpanId"),r(currentSpanId,"currentSpanId");export function runInLensmcpContext(e,n){return LENSMCP_CONTEXT_STORAGE.run(e,n)}t(runInLensmcpContext,"runInLensmcpContext"),r(runInLensmcpContext,"runInLensmcpContext");
|
package/lib/instrument.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var G=Object.defineProperty;var p=(t,r)=>G(t,"name",{value:r,configurable:!0});var W=Object.defineProperty,l=p((t,r)=>W(t,"name",{value:r,configurable:!0}),"i");import{fingerprint as b,ulid as g}from"@lensmcp/core";import{redactText as M}from"@lensmcp/core/redact";import{captureFor as F,capturedValue as j}from"./capture.js";import{currentLensmcpContext as Q,currentSpanId as V,LENSMCP_SPAN_STORAGE as H}from"./context.js";import{activeOptions as z}from"./state.js";export const LENSMCP_TRACED=Symbol.for("@lensmcp/nest-instrumentation/traced"),LENSMCP_IGNORE=Symbol.for("@lensmcp/nest-instrumentation/ignore");const w=300;function O(t){if(t instanceof Error){const d=t.code,c=M(t.message??"");return{name:t.name||t.constructor?.name||"Error",...c?{message:c.length>w?`${c.slice(0,w)}\u2026`:c}:{},...typeof d=="string"&&d.length<=64?{code:d}:{}}}const r=typeof t=="string"?M(t):void 0;return{name:t==null?"nothing":typeof t=="object"?"non-Error object":`non-Error ${typeof t}`,...r?{message:r.slice(0,w)}:{}}}p(O,"W"),l(O,"thrownOf");export function LensmcpIgnore(){return((t,r)=>{if(r===void 0)t[LENSMCP_IGNORE]=!0;else{const d=t[r];typeof d=="function"&&(d[LENSMCP_IGNORE]=!0)}})}p(LensmcpIgnore,"LensmcpIgnore"),l(LensmcpIgnore,"LensmcpIgnore");export function isTraced(t){return typeof t=="function"&&!!t[LENSMCP_TRACED]}p(isTraced,"isTraced"),l(isTraced,"isTraced");export function isIgnored(t){return!!t&&(typeof t=="function"||typeof t=="object")&&!!t[LENSMCP_IGNORE]}p(isIgnored,"isIgnored"),l(isIgnored,"isIgnored");export function traceWrap(t,r,d={}){if(isTraced(t))return t;const c=d.db??!1,h=l(function(...m){let a;try{a=z()}catch{return t.apply(this,m)}if(!a.trace.services)return t.apply(this,m);const f=Date.now(),e=Q(),x=g(),E=V(),R=e?.dbCallCount??0,T=e?.redisCallCount??0,P=e?.externalCallCount??0,N=e?.loopDbCalls??0,A=e?.loopRedisCalls??0,_=e?.loopExternalCalls??0,I=d.capture??F(r),v=I==="args"||I==="both"?j(m):void 0,D=l((o,n,C)=>{const s=Date.now()-f,i={id:g(),sessionId:a.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:o==="error"?"error":"info",context:{sessionId:a.sessionId,flowId:e?.flowId,requestId:e?.requestId,...e?.runId?{runId:e.runId}:{}},fingerprint:b({kind:"method-call",identity:r}),title:`${r} (${s}ms)${o==="error"?" \u2717":""}`,message:n instanceof Error?n.message:void 0,raw:{kind:"span",span:{name:r,spanId:x,...E?{parentSpanId:E}:{},flowId:e?.flowId,requestId:e?.requestId,startTime:f,endTime:Date.now(),durationMs:s,status:o,outcome:o==="error"?"threw":"returned",...o==="error"?{error:O(n)}:{},...v!==void 0?{args:v}:{},...o==="ok"&&(I==="result"||I==="both")?{result:j(C)}:{}}}};a.emit(i)},"emitSpan"),q=l(()=>{e&&(e.dbCallCount=(e.dbCallCount??0)+1),a.emit({id:g(),sessionId:a.sessionId,timestamp:Date.now(),source:"db",category:"db",severity:"info",context:{sessionId:a.sessionId,flowId:e?.flowId,requestId:e?.requestId,...e?.runId?{runId:e.runId}:{}},fingerprint:b({kind:"db-query",identity:r}),title:`query ${r}`,raw:{kind:"db-query",query:{signature:r}}})},"emitDbQuery"),k=l(()=>{if(c||!e)return;const o=(e.dbCallCount??0)-R,n=(e.redisCallCount??0)-T,C=(e.externalCallCount??0)-P,s=Math.max(0,o-((e.loopDbCalls??0)-N)),i=Math.max(0,n-((e.loopRedisCalls??0)-A)),u=Math.max(0,C-((e.loopExternalCalls??0)-_));if(s<3&&i<3&&u<3)return;const B=Date.now()-f,y=[];s>=3&&y.push(`${s} DB calls`),i>=3&&y.push(`${i} redis calls`),u>=3&&y.push(`${u} external calls`),s>=3&&(e.loopDbCalls=(e.loopDbCalls??0)+s),i>=3&&(e.loopRedisCalls=(e.loopRedisCalls??0)+i),u>=3&&(e.loopExternalCalls=(e.loopExternalCalls??0)+u);const S=o-s+(n-i)+(C-u);a.emit({id:g(),sessionId:a.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:"warning",context:{sessionId:a.sessionId,flowId:e.flowId,requestId:e.requestId,...e.runId?{runId:e.runId}:{}},fingerprint:b({kind:"loop",identity:r}),title:`loop in ${r} (${y.join(", ")})`,raw:{kind:"loop",loop:{iterations:Math.max(s,i,u),durationMs:B,startedAt:f,dbCallsInsideLoop:s,redisCallsInsideLoop:i,externalCallsInsideLoop:u,awaitedOperationsInsideLoop:s+i+u,...S>0?{reportedBeneath:S}:{}}}})},"emitLoopIfNeeded"),L=l(o=>{c&&q(),D("ok",void 0,o),k()},"onOk"),$=l(o=>{c&&q(),D("error",o),k()},"onErr");try{const o=H.run(x,()=>t.apply(this,m));return o instanceof Promise?o.then(n=>(L(n),n),n=>{throw $(n),n}):(L(o),o)}catch(o){throw $(o),o}},"wrapped");return h[LENSMCP_TRACED]=!0,h}p(traceWrap,"traceWrap"),l(traceWrap,"traceWrap");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/nest-instrumentation",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.14",
|
|
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.25.
|
|
18
|
-
"@lensmcp/memory-tracker": "1.25.
|
|
19
|
-
"@lensmcp/protocol-types": "1.25.
|
|
17
|
+
"@lensmcp/core": "1.25.14",
|
|
18
|
+
"@lensmcp/memory-tracker": "1.25.14",
|
|
19
|
+
"@lensmcp/protocol-types": "1.25.14",
|
|
20
20
|
"tslib": "^2.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|