@lensmcp/nest-instrumentation 1.25.24 → 1.25.26
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/instrument.js +1 -1
- package/lib/state.js +1 -1
- package/package.json +4 -4
package/lib/instrument.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Q=Object.defineProperty;var m=(e,r)=>Q(e,"name",{value:r,configurable:!0});var V=Object.defineProperty,l=m((e,r)=>V(e,"name",{value:r,configurable:!0}),"i");import{fingerprint as b,ulid as w}from"@lensmcp/core";import{redactText as O}from"@lensmcp/core/redact";import{captureFor as z,capturedValue as R}from"./capture.js";import{currentLensmcpContext as H,currentSpanId as J,LENSMCP_SPAN_STORAGE as X}from"./context.js";import{activeOptions as K}from"./state.js";import{performance as T}from"node:perf_hooks";export const LENSMCP_TRACED=Symbol.for("@lensmcp/nest-instrumentation/traced"),LENSMCP_IGNORE=Symbol.for("@lensmcp/nest-instrumentation/ignore");const h=300;function A(e){if(e instanceof Error){const d=e.code,p=O(e.message??"");return{name:e.name||e.constructor?.name||"Error",...p?{message:p.length>h?`${p.slice(0,h)}\u2026`:p}:{},...typeof d=="string"&&d.length<=64?{code:d}:{}}}const r=typeof e=="string"?O(e):void 0;return{name:e==null?"nothing":typeof e=="object"?"non-Error object":`non-Error ${typeof e}`,...r?{message:r.slice(0,h)}:{}}}m(A,"J"),l(A,"thrownOf");export function LensmcpIgnore(){return((e,r)=>{if(r===void 0)e[LENSMCP_IGNORE]=!0;else{const d=e[r];typeof d=="function"&&(d[LENSMCP_IGNORE]=!0)}})}m(LensmcpIgnore,"LensmcpIgnore"),l(LensmcpIgnore,"LensmcpIgnore");export function isTraced(e){return typeof e=="function"&&!!e[LENSMCP_TRACED]}m(isTraced,"isTraced"),l(isTraced,"isTraced");export function isIgnored(e){return!!e&&(typeof e=="function"||typeof e=="object")&&!!e[LENSMCP_IGNORE]}m(isIgnored,"isIgnored"),l(isIgnored,"isIgnored");export function traceWrap(e,r,d={}){if(isTraced(e))return e;const p=d.db??!1,x=l(function(...I){let a;try{a=K()}catch{return e.apply(this,I)}if(!a.trace.services)return e.apply(this,I);const c=Date.now();let D=c,E=0;const t=H(),g=w(),v=J(),P=t?.dbCallCount??0,N=t?.redisCallCount??0,_=t?.externalCallCount??0,B=t?.loopDbCalls??0,G=t?.loopRedisCalls??0,W=t?.loopExternalCalls??0,f=d.capture??z(r),q=f==="args"||f==="both"?R(I):void 0,M=l((n,o,C)=>{const s=Date.now()-c,i={id:w(),sessionId:a.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:n==="error"?"error":"info",context:{sessionId:a.sessionId,flowId:t?.flowId,requestId:t?.requestId,...t?.runId?{runId:t.runId}:{}},fingerprint:b({kind:"method-call",identity:r}),title:`${r} (${s}ms)${n==="error"?" \u2717":""}`,message:o instanceof Error?o.message:void 0,raw:{kind:"span",span:{name:r,spanId:g,...v?{parentSpanId:v}:{},flowId:t?.flowId,requestId:t?.requestId,startTime:c,endTime:Date.now(),durationMs:s,syncStartedAt:D,syncDurationMs:E,status:n,outcome:n==="error"?"threw":"returned",...n==="error"?{error:A(o)}:{},...q!==void 0?{args:q}:{},...n==="ok"&&(f==="result"||f==="both")?{result:R(C)}:{}}}};a.emit(i)},"emitSpan"),S=l(()=>{t&&(t.dbCallCount=(t.dbCallCount??0)+1);const n=Date.now();a.emit({id:w(),sessionId:a.sessionId,timestamp:Date.now(),source:"db",category:"db",severity:"info",context:{sessionId:a.sessionId,flowId:t?.flowId,requestId:t?.requestId,...t?.runId?{runId:t.runId}:{}},fingerprint:b({kind:"db-query",identity:r}),title:`query ${r}`,raw:{kind:"db-query",query:{signature:r},startedAt:c,durationMs:n-c,span:{parentSpanId:g}}})},"emitDbQuery"),k=l(()=>{if(p||!t)return;const n=(t.dbCallCount??0)-P,o=(t.redisCallCount??0)-N,C=(t.externalCallCount??0)-_,s=Math.max(0,n-((t.loopDbCalls??0)-B)),i=Math.max(0,o-((t.loopRedisCalls??0)-G)),u=Math.max(0,C-((t.loopExternalCalls??0)-W));if(s<3&&i<3&&u<3)return;const F=Date.now()-c,y=[];s>=3&&y.push(`${s} DB calls`),i>=3&&y.push(`${i} redis calls`),u>=3&&y.push(`${u} external calls`),s>=3&&(t.loopDbCalls=(t.loopDbCalls??0)+s),i>=3&&(t.loopRedisCalls=(t.loopRedisCalls??0)+i),u>=3&&(t.loopExternalCalls=(t.loopExternalCalls??0)+u);const j=n-s+(o-i)+(C-u);a.emit({id:w(),sessionId:a.sessionId,timestamp:Date.now(),source:"nestjs",category:"backend",severity:"warning",context:{sessionId:a.sessionId,flowId:t.flowId,requestId:t.requestId,...t.runId?{runId:t.runId}:{}},fingerprint:b({kind:"loop",identity:r}),title:`loop in ${r} (${y.join(", ")})`,raw:{kind:"loop",loop:{iterations:Math.max(s,i,u),durationMs:F,startedAt:c,dbCallsInsideLoop:s,redisCallsInsideLoop:i,externalCallsInsideLoop:u,awaitedOperationsInsideLoop:s+i+u,...j>0?{reportedBeneath:j}:{}}}})},"emitLoopIfNeeded"),L=l(n=>{p&&S(),M("ok",void 0,n),k()},"onOk"),$=l(n=>{p&&S(),M("error",n),k()},"onErr");try{const n=X.run(g,()=>{D=Date.now();const o=T.now();try{return e.apply(this,I)}finally{E=Math.round((T.now()-o)*100)/100}});return n instanceof Promise?n.then(o=>(L(o),o),o=>{throw $(o),o}):(L(n),n)}catch(n){throw $(n),n}},"wrapped");return x[LENSMCP_TRACED]=!0,x}m(traceWrap,"traceWrap"),l(traceWrap,"traceWrap");
|
package/lib/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var r=(e,t)=>u(e,"name",{value:t,configurable:!0});var d=Object.defineProperty,o=r((e,t)=>d(e,"name",{value:t,configurable:!0}),"r");import{ulid as m}from"@lensmcp/core";import{defaultEventSink as p}from"./event-sink.js";import{performance as f}from"node:perf_hooks";import{threadId as l}from"node:worker_threads";let s,a=0;export function setActiveOptions(e){const t=e.emit??p(),c=`node:${process.pid}:${l}:${f.timeOrigin}`,n={projectName:e.projectName,sessionId:e.sessionId??process.env.LENSMCP_SESSION_ID??m(),emit:o(i=>t({...i,raw:{...i.raw,loopId:c}}),"emit"),trace:{requests:e.trace?.requests??!0,guards:e.trace?.guards??!0,controllers:e.trace?.controllers??!0,services:e.trace?.services??!0,db:e.trace?.db??!1,redis:e.trace?.redis??!1,queues:e.trace?.queues??!1,autoInstrumentMethods:e.trace?.autoInstrumentMethods??!1,suppressNoiseMethods:e.trace?.suppressNoiseMethods??!0},memory:{mode:e.memory?.mode??"off",scope:e.memory?.scope??"tagged"}};return s=n,a+=1,n}r(setActiveOptions,"setActiveOptions"),o(setActiveOptions,"setActiveOptions");export function activeOptions(){if(!s)throw new Error("@lensmcp/nest-instrumentation: LensmcpModule.forRoot(...) has not been registered. Did you forget to add it to your AppModule?");return s}r(activeOptions,"activeOptions"),o(activeOptions,"activeOptions");export function currentGeneration(){return a}r(currentGeneration,"currentGeneration"),o(currentGeneration,"currentGeneration");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/nest-instrumentation",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.26",
|
|
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.26",
|
|
18
|
+
"@lensmcp/memory-tracker": "1.25.26",
|
|
19
|
+
"@lensmcp/protocol-types": "1.25.26",
|
|
20
20
|
"tslib": "^2.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|