@lensmcp/nest-instrumentation 1.25.18 → 1.25.21
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/package.json +4 -4
package/lib/instrument.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var
|
|
1
|
+
"use strict";var G=Object.defineProperty;var c=(r,t)=>G(r,"name",{value:t,configurable:!0});var F=Object.defineProperty,f=c((r,t)=>F(r,"name",{value:t,configurable:!0}),"c"),Q=Object.defineProperty,l=f((r,t)=>Q(r,"name",{value:t,configurable:!0}),"i");import{fingerprint as h,ulid as b}from"@lensmcp/core";import{redactText as O}from"@lensmcp/core/redact";import{captureFor as V,capturedValue as T}from"./capture.js";import{currentLensmcpContext as z,currentSpanId as H,LENSMCP_SPAN_STORAGE as J}from"./context.js";import{activeOptions as K}from"./state.js";export const LENSMCP_TRACED=Symbol.for("@lensmcp/nest-instrumentation/traced"),LENSMCP_IGNORE=Symbol.for("@lensmcp/nest-instrumentation/ignore");const x=300;function v(r){if(r instanceof Error){const d=r.code,u=O(r.message??"");return{name:r.name||r.constructor?.name||"Error",...u?{message:u.length>x?`${u.slice(0,x)}\u2026`:u}:{},...typeof d=="string"&&d.length<=64?{code:d}:{}}}const t=typeof r=="string"?O(r):void 0;return{name:r==null?"nothing":typeof r=="object"?"non-Error object":`non-Error ${typeof r}`,...t?{message:t.slice(0,x)}:{}}}c(v,"O"),f(v,"W"),l(v,"thrownOf");export function LensmcpIgnore(){return((r,t)=>{if(t===void 0)r[LENSMCP_IGNORE]=!0;else{const d=r[t];typeof d=="function"&&(d[LENSMCP_IGNORE]=!0)}})}c(LensmcpIgnore,"LensmcpIgnore"),f(LensmcpIgnore,"LensmcpIgnore"),l(LensmcpIgnore,"LensmcpIgnore");export function isTraced(r){return typeof r=="function"&&!!r[LENSMCP_TRACED]}c(isTraced,"isTraced"),f(isTraced,"isTraced"),l(isTraced,"isTraced");export function isIgnored(r){return!!r&&(typeof r=="function"||typeof r=="object")&&!!r[LENSMCP_IGNORE]}c(isIgnored,"isIgnored"),f(isIgnored,"isIgnored"),l(isIgnored,"isIgnored");export function traceWrap(r,t,d={}){if(isTraced(r))return r;const u=d.db??!1,E=l(function(...I){let a;try{a=K()}catch{return r.apply(this,I)}if(!a.trace.services)return r.apply(this,I);const m=Date.now(),e=z(),w=b(),D=H(),P=e?.dbCallCount??0,R=e?.redisCallCount??0,N=e?.externalCallCount??0,A=e?.loopDbCalls??0,W=e?.loopRedisCalls??0,_=e?.loopExternalCalls??0,C=d.capture??V(t),q=C==="args"||C==="both"?T(I):void 0,L=l((o,n,y)=>{const s=Date.now()-m,i={id:b(),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:h({kind:"method-call",identity:t}),title:`${t} (${s}ms)${o==="error"?" \u2717":""}`,message:n instanceof Error?n.message:void 0,raw:{kind:"span",span:{name:t,spanId:w,...D?{parentSpanId:D}:{},flowId:e?.flowId,requestId:e?.requestId,startTime:m,endTime:Date.now(),durationMs:s,status:o,outcome:o==="error"?"threw":"returned",...o==="error"?{error:v(n)}:{},...q!==void 0?{args:q}:{},...o==="ok"&&(C==="result"||C==="both")?{result:T(y)}:{}}}};a.emit(i)},"emitSpan"),k=l(()=>{e&&(e.dbCallCount=(e.dbCallCount??0)+1);const o=Date.now();a.emit({id:b(),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:h({kind:"db-query",identity:t}),title:`query ${t}`,raw:{kind:"db-query",query:{signature:t},startedAt:m,durationMs:o-m,span:{parentSpanId:w}}})},"emitDbQuery"),S=l(()=>{if(u||!e)return;const o=(e.dbCallCount??0)-P,n=(e.redisCallCount??0)-R,y=(e.externalCallCount??0)-N,s=Math.max(0,o-((e.loopDbCalls??0)-A)),i=Math.max(0,n-((e.loopRedisCalls??0)-W)),p=Math.max(0,y-((e.loopExternalCalls??0)-_));if(s<3&&i<3&&p<3)return;const B=Date.now()-m,g=[];s>=3&&g.push(`${s} DB calls`),i>=3&&g.push(`${i} redis calls`),p>=3&&g.push(`${p} external calls`),s>=3&&(e.loopDbCalls=(e.loopDbCalls??0)+s),i>=3&&(e.loopRedisCalls=(e.loopRedisCalls??0)+i),p>=3&&(e.loopExternalCalls=(e.loopExternalCalls??0)+p);const j=o-s+(n-i)+(y-p);a.emit({id:b(),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:h({kind:"loop",identity:t}),title:`loop in ${t} (${g.join(", ")})`,raw:{kind:"loop",loop:{iterations:Math.max(s,i,p),durationMs:B,startedAt:m,dbCallsInsideLoop:s,redisCallsInsideLoop:i,externalCallsInsideLoop:p,awaitedOperationsInsideLoop:s+i+p,...j>0?{reportedBeneath:j}:{}}}})},"emitLoopIfNeeded"),$=l(o=>{u&&k(),L("ok",void 0,o),S()},"onOk"),M=l(o=>{u&&k(),L("error",o),S()},"onErr");try{const o=J.run(w,()=>r.apply(this,I));return o instanceof Promise?o.then(n=>($(n),n),n=>{throw M(n),n}):($(o),o)}catch(o){throw M(o),o}},"wrapped");return E[LENSMCP_TRACED]=!0,E}c(traceWrap,"traceWrap"),f(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.21",
|
|
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.21",
|
|
18
|
+
"@lensmcp/memory-tracker": "1.25.21",
|
|
19
|
+
"@lensmcp/protocol-types": "1.25.21",
|
|
20
20
|
"tslib": "^2.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|