@lensmcp/node-instrumentation 1.25.52 → 1.25.54
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.js +1 -1
- package/lib/active-work.js +1 -1
- package/lib/ai-providers.js +9 -9
- package/lib/ai-store.js +1 -1
- package/lib/callsite.js +2 -2
- package/lib/capture-file.js +1 -1
- package/lib/emit-custom.js +1 -1
- package/lib/emit.js +3 -3
- package/lib/flood-guard.js +1 -1
- package/lib/flow-context.js +1 -1
- package/lib/http-capture.js +2 -2
- package/lib/http-store.d.ts +52 -3
- package/lib/http-store.js +1 -1
- package/lib/install.js +1 -1
- package/lib/lens-time.d.ts +9 -0
- package/lib/lens-time.js +1 -0
- package/lib/loop-watchdog.js +2 -2
- package/lib/require-hook.js +1 -1
- package/lib/sql-accounting.js +1 -1
- package/lib/sql-drops.js +1 -1
- package/lib/sql-values.js +2 -2
- package/lib/tap-ai.js +1 -1
- package/lib/tap-bullmq.js +1 -1
- package/lib/tap-egress.js +1 -1
- package/lib/tap-event-loop.js +1 -1
- package/lib/tap-exec.js +1 -1
- package/lib/tap-fs.js +1 -1
- package/lib/tap-ingress.js +1 -1
- package/lib/tap-loop-callbacks.d.ts +14 -0
- package/lib/tap-loop-callbacks.js +1 -1
- package/lib/tap-nest-logger.js +5 -5
- package/lib/tap-nest.js +1 -1
- package/lib/tap-pg-pool.js +2 -2
- package/lib/tap-pg.js +1 -1
- package/lib/tap-redis.js +1 -1
- package/lib/tap-stdout.js +5 -5
- package/package.json +4 -4
- package/register.js +1 -1
package/lib/tap-pg.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.defineProperty;var u=(t,e)=>j(t,"name",{value:e,configurable:!0});var U=Object.defineProperty,r=u((t,e)=>U(t,"name",{value:e,configurable:!0}),"r");Object.defineProperty(exports,"__esModule",{value:!0}),exports.taggedAppName=taggedAppName,exports.pgTap=pgTap;const redact_1=require("@lensmcp/core/redact"),sql_shape_1=require("@lensmcp/core/sql-shape"),emit_1=require("./emit"),flood_guard_1=require("./flood-guard"),flow_context_1=require("./flow-context"),sql_accounting_1=require("./sql-accounting"),tap_pg_pool_1=require("./tap-pg-pool"),callsite_1=require("./callsite"),active_work_1=require("./active-work"),emit_2=require("./emit"),sql_values_1=require("./sql-values"),sql_drops_1=require("./sql-drops"),SKIP_OPS=new Set(["BEGIN","START","COMMIT","END","ROLLBACK","SAVEPOINT","RELEASE","SET","RESET","SHOW","DEALLOCATE","DISCARD","LISTEN","UNLISTEN"]),STATEMENT_EVERY_MS=10*6e4,STATEMENT_MAX=64*1024,SLOW_SITE_MS=250,sites=new callsite_1.SiteSampler,buckets=(0,flood_guard_1.createEventFloodGuard)({burst:30,perSec:5}),statementGuard={admit:r(t=>({ok:buckets.admit(t).ok,suppressed:0}),"admit")},statementSentAt=new Map,MAX_SHAPES_REMEMBERED=2e3,firstWord=r(t=>(/^\s*(?:(?:\/\*[\s\S]*?\*\/|--[^\n]*\n?)\s*)*(\w+)/.exec(t)?.[1]??"query").toUpperCase(),"firstWord");function parseSql(t){const e=(0,sql_shape_1.sqlShape)(t),n=(e.target??e.tables[0])?.split(".").pop();return{op:e.verb,...n?{table:n}:{},sqlId:e.id,tables:e.tables,...e.name?{name:e.name}:{}}}u(parseSql,"parseSql"),r(parseSql,"parseSql");const oneLine=r(t=>t.replace(/\s+/g," ").trim(),"oneLine"),clip=r((t,e)=>t.length>e?t.slice(0,e-1)+"\u2026":t,"clip");function paramPreview(t){if(!(!Array.isArray(t)||t.length===0))return t.slice(0,10).map(e=>{if(e==null)return String(e);const n=typeof e=="string"?e:(()=>{try{return JSON.stringify(e)}catch{return String(e)}})();return clip(n,80)})}u(paramPreview,"paramPreview"),r(paramPreview,"paramPreview");const rowsOf=r(t=>t?.rowCount??t?.rows?.length??0,"rowsOf");function resultPreview(t){const e=t?.rows;if(!(!Array.isArray(e)||e.length===0))try{return clip(JSON.stringify((0,redact_1.redactDeep)(e.slice(0,2))),240)}catch{return}}u(resultPreview,"resultPreview"),r(resultPreview,"resultPreview");function connectionOf(t){const e=t,n=e?.connectionParameters,a=typeof e?.database=="string"?e.database:typeof n?.database=="string"?n.database:void 0,s=typeof e?.host=="string"?e.host:typeof n?.host=="string"?n.host:void 0,i=typeof e?.port=="number"||typeof e?.port=="string"?e.port:typeof n?.port=="number"||typeof n?.port=="string"?n.port:5432;return{...a?{database:a}:{},...s?{server:`${s}:${i}`}:{}}}u(connectionOf,"connectionOf"),r(connectionOf,"connectionOf");const APP_NAME_MAX=63;function taggedAppName(t,e,n,a){const s=` lens:${e.replace(/[^\x21-\x7e]/g,"?").replace(/:/g,"_")}${n>0?`:g${n}`:""}${a?`:p${a}`:""}`.slice(0,APP_NAME_MAX);return`${(t??"node").replace(/[^\x20-\x7e]/g,"?").replace(/ lens:\S+$/,"").slice(0,Math.max(0,APP_NAME_MAX-s.length))}${s}`}u(taggedAppName,"taggedAppName"),r(taggedAppName,"taggedAppName");function tagApplicationName(t){if(process.env.LENSMCP_PG_APP_NAME==="0")return;const e=t.getStartupConf;if(typeof e!="function"||e.__lensmcp)return;const n=r(function(){const a=e.call(this);try{a&&typeof a=="object"&&emit_2.PROJECT&&(a.application_name=taggedAppName(typeof a.application_name=="string"?a.application_name:void 0,emit_2.PROJECT,(0,active_work_1.activeWorkGeneration)(),process.pid))}catch{}return a},"wrapped");n.__lensmcp=!0,t.getStartupConf=n}u(tagApplicationName,"tagApplicationName"),r(tagApplicationName,"tagApplicationName");function pgTap(t){const e=t?.Client?.prototype,n=e?.query;if(!e||typeof n!="function")return!1;try{(0,tap_pg_pool_1.pgPoolTap)(t)}catch{}try{tagApplicationName(e)}catch{}if(n.__lensmcp)return!0;const a=r(function(s,i,b){const S=s,f=typeof S=="string"?S:S?.text;if(!f||S&&typeof S=="object"&&typeof S.submit=="function")return n.call(this,s,i,b);if(SKIP_OPS.has(firstWord(f)))return n.call(this,s,i,b);const{op:G,table:p,sqlId:m,tables:N,name:h}=parseSql(f),J=connectionOf(this),g=G.toLowerCase(),v=`${g}:${p??"query"}`,l=Date.now(),M=(0,flow_context_1.flowContext)(),V=(0,callsite_1.captureSite)(),O=(0,tap_pg_pool_1.checkoutSite)(),_=(0,flow_context_1.liveFlowContext)();_&&(_.dbCallCount=(_.dbCallCount??0)+1,(0,flow_context_1.countDbSecond)(_,l));const w=(0,sql_accounting_1.beginSqlStatement)(_,M,l),T=clip(oneLine(f),500),x=Array.isArray(i)?i:s?.values,I=paramPreview(x),E=I&&(0,redact_1.redactSqlParams)(f,I),$=r((o,d)=>{const c=Date.now()-l,P=l-(statementSentAt.get(m)??-1/0)>=STATEMENT_EVERY_MS;let C;try{C=sites.site(m,V,{force:!!o||P||c>=SLOW_SITE_MS,...O?{fallback:O}:{}})}catch{}const k={sqlId:m,...N.length?{tables:N}:{},...h?{sqlName:h}:{},...J,...C?{site:C}:{},...P?{statement:clip(f.trim(),STATEMENT_MAX)}:{}},A=(0,sql_values_1.newSqlValuesId)(l),R=A?{valuesId:A}:{};let y;if(o)y=(0,emit_1.lensEmitOutcome)("db","error",`${g}${p?" "+p:""} failed (${c}ms)`,{name:"postgres",kind:"db-query",op:g,...p?{table:p}:{},...k,query:T,...E?{params:E}:{},...R,startedAt:l,error:String(o?.message??o),durationMs:c},`db:error:${v}`,M,"cluster",statementGuard);else{const D=rowsOf(d),W=resultPreview(d);y=(0,emit_1.lensEmitOutcome)("db","info",`${g} ${p??"query"} (${D} rows, ${c}ms)`,{name:"postgres",kind:"db-query",op:g,...p?{table:p}:{},...k,query:T,...E?{params:E}:{},...W?{result:W}:{},...R,startedAt:l,rows:D,durationMs:c},c>=sql_drops_1.SLOW_QUERY_MS?`db:slow:${v}`:`db:${v}`,M,"cluster",statementGuard)}y==="suppressed"&&(0,sql_drops_1.noteDroppedRun)({sqlId:m,op:g,...p?{table:p}:{},...h?{sqlName:h}:{},...statementSentAt.has(m)?{}:{query:T},durationMs:c,failed:!!o,at:l}),A&&y==="written"&&(0,sql_values_1.keepSqlValues)(A,l,f,x,o?void 0:d?.rows),P&&y==="written"&&(statementSentAt.delete(m),statementSentAt.set(m,l),statementSentAt.size>MAX_SHAPES_REMEMBERED&&statementSentAt.delete(statementSentAt.keys().next().value)),(0,sql_accounting_1.endSqlStatement)(w,{durationMs:c,failed:!!o,emitted:y})},"done"),L=typeof b=="function"?b:typeof i=="function"?i:void 0;if(L){const o=r((d,c)=>{try{$(d,c)}catch{}L(d,c)},"wrappedCb");try{return typeof i=="function"?n.call(this,s,o):n.call(this,s,i,o)}catch(d){throw(0,sql_accounting_1.abandonSqlStatement)(w),d}}let q;try{q=n.call(this,s,i)}catch(o){throw(0,sql_accounting_1.abandonSqlStatement)(w),o}return q&&typeof q.then=="function"?q.then(o=>$(void 0,o),o=>$(o,void 0)):(0,sql_accounting_1.abandonSqlStatement)(w),q},"wrapped");return a.__lensmcp=!0,e.query=a,!0}u(pgTap,"pgTap"),r(pgTap,"pgTap");
|
package/lib/tap-redis.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var $=Object.defineProperty;var d=(t,e)=>$(t,"name",{value:e,configurable:!0});var E=Object.defineProperty,p=d((t,e)=>E(t,"name",{value:e,configurable:!0}),"p");Object.defineProperty(exports,"__esModule",{value:!0}),exports.redisFingerprint=redisFingerprint,exports.redisTap=redisTap;const key_pattern_1=require("@lensmcp/core/key-pattern"),redact_1=require("@lensmcp/core/redact"),redis_expiry_1=require("@lensmcp/core/redis-expiry"),emit_1=require("./emit"),flow_context_1=require("./flow-context"),sql_values_1=require("./sql-values"),HOUSEKEEPING=new Set(["info","ping","hello","auth","select","client","cluster","command","subscribe","psubscribe","unsubscribe","punsubscribe","echo","quit","wait","script","config","debug","memory","readonly","readwrite"]),MAX_PER_SEC=100,MAX_SHAPES=200,SHARED_BUCKET="redis:cache";let emitted=0,windowStart=0,capped=0;const shapes=new Set;function redisFingerprint(t,e){const n=`redis:${t} ${(0,key_pattern_1.foldKeyPattern)(e).slice(0,120)}`;return shapes.has(n)?n:shapes.size>=MAX_SHAPES?SHARED_BUCKET:(shapes.add(n),n)}d(redisFingerprint,"redisFingerprint"),p(redisFingerprint,"redisFingerprint");function isBullTraffic(t){const e=String(t.name??"").toLowerCase();if(e==="eval"||e==="evalsha")return!0;const n=t.args??[];for(let r=0;r<Math.min(n.length,4);r++){const i=String(n[r]??"");if(i.startsWith("bull:")||i.startsWith("{bull"))return!0}return!1}d(isBullTraffic,"isBullTraffic"),p(isBullTraffic,"isBullTraffic");function redisTap(t){const e=t,n=(e?.default??e)?.prototype,r=n?.sendCommand;if(!n||typeof r!="function")return!1;if(r.__lensmcp)return!0;const i=p(function(s,o){const a=r.call(this,s,o);try{observe(s)}catch{}return a},"wrapped");return i.__lensmcp=!0,n.sendCommand=i,!0}d(redisTap,"redisTap"),p(redisTap,"redisTap");const clip=p((t,e)=>t.length>e?t.slice(0,e-1)+"\u2026":t,"clip");function commandLine(t,e){const n=e.slice(0,6).map((r,i)=>{const s=String(r??"");return i>0&&s.length>48?`\u2026(${(s.length/1024).toFixed(1)}kb)`:clip(s,64)});return[t.toUpperCase(),...n].join(" ")}d(commandLine,"commandLine"),p(commandLine,"commandLine");function observe(t){const e=String(t?.name??"").toLowerCase();if(!e||HOUSEKEEPING.has(e)||isBullTraffic(t))return;const n=(0,flow_context_1.liveFlowContext)();n&&(n.redisCallCount=(n.redisCallCount??0)+1);const r=Date.now();if(r-windowStart>1e3&&(windowStart=r,emitted=0),++emitted>MAX_PER_SEC){capped+=1;return}const i=t?.args??[],s=String(i[0]??""),o=(0,redact_1.isSecretCacheKey)(s),a=o?(0,key_pattern_1.foldKeyPattern)(s):s,C=(0,flow_context_1.flowContext)(),x=o?`${e.toUpperCase()} ${a} \u2026`:(0,redact_1.redactSecretText)(commandLine(e,i)),g=redisFingerprint(e,s),b=capped;capped=0;const y={name:"cache",kind:"redis-op",op:e,key:a,command:x,startedAt:r,expiry:(0,redis_expiry_1.redisExpiry)(e,i),...o?{secretKey:!0}:{},...b?{capSuppressed:b}:{}},h=i.slice(1);if(e==="get"&&t.promise&&typeof t.promise.then=="function"){const l=r;t.promise.then(f=>{const c=f!=null,u=c&&!o?(0,sql_values_1.newCacheValuesId)(l):void 0,w=(0,emit_1.lensEmitOutcome)("redis","info",`cache ${c?"hit":"miss"} ${a}`,{...y,hit:c,durationMs:Date.now()-l,...c&&!o?{value:clip((0,redact_1.redactSecretText)(String(f).slice(0,4096)),120)}:{},...u?{valuesId:u}:{}},g,C);u&&w==="written"&&(0,sql_values_1.keepCacheValues)(u,l,e,s,h,f)},()=>{});return}const m=o?void 0:(0,sql_values_1.newCacheValuesId)(r),v=m?{valuesId:m}:{};let S;if(e==="set"){const l=i.map(u=>String(u)),f=l.findIndex((u,w)=>w>=2&&u.toUpperCase()==="EX"),c=f>=0?Number(l[f+1]):void 0;S=(0,emit_1.lensEmitOutcome)("redis","info",c?`cache set ${a} (ttl ${c}s)`:`cache set ${a}`,{...y,...c?{ttlSec:c}:{},...v},g,C)}else S=(0,emit_1.lensEmitOutcome)("redis","info",`cache ${e} ${a}`,{...y,...v},g,C);if(!m||S!=="written")return;const _=t.promise;_&&typeof _.then=="function"?_.then(l=>(0,sql_values_1.keepCacheValues)(m,r,e,s,h,l),()=>(0,sql_values_1.keepCacheValues)(m,r,e,s,h)):(0,sql_values_1.keepCacheValues)(m,r,e,s,h)}d(observe,"observe"),p(observe,"observe");
|
package/lib/tap-stdout.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).map(
|
|
3
|
-
`),c)){
|
|
4
|
-
`)}:{},...
|
|
5
|
-
`)}:{},...
|
|
1
|
+
"use strict";var R=Object.defineProperty;var f=(e,t)=>R(e,"name",{value:t,configurable:!0});var E=Object.defineProperty,u=f((e,t)=>E(e,"name",{value:t,configurable:!0}),"u");Object.defineProperty(exports,"__esModule",{value:!0}),exports.isServiceProcess=isServiceProcess,exports.tapStdout=tapStdout;const emit_1=require("./emit"),tap_nest_logger_1=require("./tap-nest-logger"),ANSI=new RegExp("\x1B\\[[0-9;]*m","g");function severityOf(e,t){return/\bFATAL\b/.test(e)?"fatal":/\bERROR\b/.test(e)?"error":/\bWARN\b/.test(e)?"warning":/\bDEBUG\b/.test(e)||/\bVERBOSE\b/.test(e)?"debug":/\bLOG\b/.test(e)?"info":t}f(severityOf,"severityOf"),u(severityOf,"severityOf");const STACK_FRAME=/^\s+(at\s|\.\.\.\s\d+\smore)/,CONTINUATION=/^(\s+\S|[}\])]+[,;]?$)/,CONTINUES_WITHIN_MS=1e3;function emitChunk(e,t,p,c,l){const o=e.split(`
|
|
2
|
+
`).map(r=>r.replace(ANSI,"").replace(/\s+$/,""));let n=0,s=p;for(;n<o.length;){const r=o[n];if(n+=1,!r.trim())continue;const i=[];for(;n<o.length&&o[n].trim()&&CONTINUATION.test(o[n]);)i.push(o[n]),n+=1;const g=[r,...i].filter(O=>STACK_FRAME.test(O)),a=CONTINUATION.test(r)&&s&&c-s.at<=CONTINUES_WITHIN_MS?s.severity:void 0,S=severityOf(r,t),_=S!==t||/\b(?:FATAL|ERROR|WARN|DEBUG|VERBOSE|LOG)\b/.test(r),b=a??(_?S:g.length>0?"error":t),d=[r,...i];if(!a&&(0,tap_nest_logger_1.isLoggerEcho)(d.join(`
|
|
3
|
+
`),c)){s={severity:b,at:c};continue}(0,emit_1.lensLog)(b,a?r.trim():r,{...g.length>0?{stack:d.join(`
|
|
4
|
+
`)}:{},...i.length>0&&g.length<i.length?{text:d.join(`
|
|
5
|
+
`)}:{},...a?{continues:!0}:{},stream:l}),s={severity:b,at:c}}return s}f(emitChunk,"emitChunk"),u(emitChunk,"emitChunk");function isServiceProcess(e=process.env){return e.APP_RUNNER==="1"||!!e.LENSMCP_WORKER}f(isServiceProcess,"isServiceProcess"),u(isServiceProcess,"isServiceProcess");function tapStdout(){if(process.env.LENSMCP_LOGS==="0"||!isServiceProcess())return;const e=[[process.stdout,"info","stdout"],[process.stderr,"error","stderr"]];for(const[t,p,c]of e){if(t.write.__lensmcp)continue;const l=t.write.bind(t);let o;const n=u(function(s,...r){try{if(!(0,emit_1.isLensWriting)()){const i=typeof s=="string"?s:Buffer.isBuffer(s)?s.toString("utf8"):"";i&&i.indexOf("[lensmcp]")===-1&&(o=emitChunk(i,p,o,Date.now(),c))}}catch{}return l(s,...r)},"wrapped");n.__lensmcp=!0,t.write=n}}f(tapStdout,"tapStdout"),u(tapStdout,"tapStdout");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/node-instrumentation",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.54",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lensmcp/core": "1.25.
|
|
19
|
-
"@lensmcp/nest-instrumentation": "1.25.
|
|
20
|
-
"@lensmcp/protocol-types": "1.25.
|
|
18
|
+
"@lensmcp/core": "1.25.54",
|
|
19
|
+
"@lensmcp/nest-instrumentation": "1.25.54",
|
|
20
|
+
"@lensmcp/protocol-types": "1.25.54",
|
|
21
21
|
"tslib": "^2.3.0"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|
package/register.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var r=(t,n)=>i(t,"name",{value:n,configurable:!0});var s=Object.defineProperty,e=r((t,n)=>s(t,"name",{value:n,configurable:!0}),"e");Object.defineProperty(exports,"__esModule",{value:!0}),exports.installLensmcpNodeInstrumentation=void 0;const install_1=require("./lib/install");Object.defineProperty(exports,"installLensmcpNodeInstrumentation",{enumerable:!0,get:e(function(){return install_1.installLensmcpNodeInstrumentation},"get")}),(0,install_1.installLensmcpNodeInstrumentation)();
|