@lensmcp/node-instrumentation 1.25.17 → 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/index.js +1 -1
- package/lib/active-work.js +1 -1
- package/lib/ai-providers.js +9 -9
- package/lib/ai-store.d.ts +3 -1
- package/lib/ai-store.js +1 -1
- package/lib/callsite.js +2 -2
- package/lib/capture-file.d.ts +5 -0
- 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.d.ts +68 -0
- package/lib/http-capture.js +2 -2
- package/lib/http-store.js +1 -1
- package/lib/install.js +1 -1
- package/lib/require-hook.js +1 -1
- package/lib/sql-accounting.js +1 -1
- package/lib/sql-values.d.ts +21 -0
- package/lib/sql-values.js +3 -0
- 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.d.ts +2 -1
- package/lib/tap-exec.js +1 -1
- package/lib/tap-fs.d.ts +30 -10
- package/lib/tap-fs.js +1 -1
- package/lib/tap-ingress.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.d.ts +2 -0
- 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 H=Object.defineProperty;var u=(t,e)=>H(t,"name",{value:e,configurable:!0});var B=Object.defineProperty,p=u((t,e)=>B(t,"name",{value:e,configurable:!0}),"p"),X=Object.defineProperty,r=p((t,e)=>X(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"),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"),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,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"),p(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"),p(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"),p(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"),p(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"),p(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"),p(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,q){const g=s,m=typeof g=="string"?g:g?.text;if(!m||g&&typeof g=="object"&&typeof g.submit=="function")return n.call(this,s,i,q);if(SKIP_OPS.has(firstWord(m)))return n.call(this,s,i,q);const{op:W,table:c,sqlId:S,tables:O,name:$}=parseSql(m),J=connectionOf(this),y=W.toLowerCase(),V=`db:${y}:${c??"query"}`,f=Date.now(),v=(0,flow_context_1.flowContext)(),G=(0,callsite_1.captureSite)(),C=(0,tap_pg_pool_1.checkoutSite)(),h=(0,flow_context_1.liveFlowContext)();h&&(h.dbCallCount=(h.dbCallCount??0)+1);const w=(0,sql_accounting_1.beginSqlStatement)(h,v,f),M=clip(oneLine(m),500),x=Array.isArray(i)?i:s?.values,I=paramPreview(x),A=I&&(0,redact_1.redactSqlParams)(m,I),P=r((o,d)=>{const l=Date.now()-f,T=f-(statementSentAt.get(S)??-1/0)>=STATEMENT_EVERY_MS;let N;try{N=sites.site(S,G,{force:!!o||T||l>=SLOW_SITE_MS,...C?{fallback:C}:{}})}catch{}const R={sqlId:S,...O.length?{tables:O}:{},...$?{sqlName:$}:{},...J,...N?{site:N}:{},...T?{statement:clip(m.trim(),STATEMENT_MAX)}:{}},E=(0,sql_values_1.newSqlValuesId)(f),k=E?{valuesId:E}:{};let b;if(o)b=(0,emit_1.lensEmitOutcome)("db","error",`${y}${c?" "+c:""} failed (${l}ms)`,{name:"postgres",kind:"db-query",op:y,...c?{table:c}:{},...R,query:M,...A?{params:A}:{},...k,startedAt:f,error:String(o?.message??o),durationMs:l},`db:error:${y}:${c??"query"}`,v);else{const D=rowsOf(d),j=resultPreview(d);b=(0,emit_1.lensEmitOutcome)("db","info",`${y} ${c??"query"} (${D} rows, ${l}ms)`,{name:"postgres",kind:"db-query",op:y,...c?{table:c}:{},...R,query:M,...A?{params:A}:{},...j?{result:j}:{},...k,startedAt:f,rows:D,durationMs:l},V,v)}E&&b==="written"&&(0,sql_values_1.keepSqlValues)(E,f,m,x,o?void 0:d?.rows),T&&b==="written"&&(statementSentAt.delete(S),statementSentAt.set(S,f),statementSentAt.size>MAX_SHAPES_REMEMBERED&&statementSentAt.delete(statementSentAt.keys().next().value)),(0,sql_accounting_1.endSqlStatement)(w,{durationMs:l,failed:!!o,emitted:b})},"done"),L=typeof q=="function"?q:typeof i=="function"?i:void 0;if(L){const o=r((d,l)=>{try{P(d,l)}catch{}L(d,l)},"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 _;try{_=n.call(this,s,i)}catch(o){throw(0,sql_accounting_1.abandonSqlStatement)(w),o}return _&&typeof _.then=="function"?_.then(o=>P(void 0,o),o=>P(o,void 0)):(0,sql_accounting_1.abandonSqlStatement)(w),_},"wrapped");return a.__lensmcp=!0,e.query=a,!0}u(pgTap,"pgTap"),p(pgTap,"pgTap"),r(pgTap,"pgTap");
|
package/lib/tap-redis.d.ts
CHANGED
package/lib/tap-redis.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.defineProperty;var f=(t,e)=>k(t,"name",{value:e,configurable:!0});var $=Object.defineProperty,d=f((t,e)=>$(t,"name",{value:e,configurable:!0}),"d"),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"),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 r=`redis:${t} ${(0,key_pattern_1.foldKeyPattern)(e).slice(0,120)}`;return shapes.has(r)?r:shapes.size>=MAX_SHAPES?SHARED_BUCKET:(shapes.add(r),r)}f(redisFingerprint,"redisFingerprint"),d(redisFingerprint,"redisFingerprint"),p(redisFingerprint,"redisFingerprint");function isBullTraffic(t){const e=String(t.name??"").toLowerCase();if(e==="eval"||e==="evalsha")return!0;const r=t.args??[];for(let n=0;n<Math.min(r.length,4);n++){const s=String(r[n]??"");if(s.startsWith("bull:")||s.startsWith("{bull"))return!0}return!1}f(isBullTraffic,"isBullTraffic"),d(isBullTraffic,"isBullTraffic"),p(isBullTraffic,"isBullTraffic");function redisTap(t){const e=t,r=(e?.default??e)?.prototype,n=r?.sendCommand;if(!r||typeof n!="function")return!1;if(n.__lensmcp)return!0;const s=p(function(i,o){const a=n.call(this,i,o);try{observe(i)}catch{}return a},"wrapped");return s.__lensmcp=!0,r.sendCommand=s,!0}f(redisTap,"redisTap"),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 r=e.slice(0,6).map((n,s)=>{const i=String(n??"");return s>0&&i.length>48?`\u2026(${(i.length/1024).toFixed(1)}kb)`:clip(i,64)});return[t.toUpperCase(),...r].join(" ")}f(commandLine,"commandLine"),d(commandLine,"commandLine"),p(commandLine,"commandLine");function observe(t){const e=String(t?.name??"").toLowerCase();if(!e||HOUSEKEEPING.has(e)||isBullTraffic(t))return;const r=(0,flow_context_1.liveFlowContext)();r&&(r.redisCallCount=(r.redisCallCount??0)+1);const n=Date.now();if(n-windowStart>1e3&&(windowStart=n,emitted=0),++emitted>MAX_PER_SEC){capped+=1;return}const s=t?.args??[],i=String(s[0]??""),o=(0,redact_1.isSecretCacheKey)(i),a=o?(0,key_pattern_1.foldKeyPattern)(i):i,C=(0,flow_context_1.flowContext)(),x=o?`${e.toUpperCase()} ${a} \u2026`:(0,redact_1.redactSecretText)(commandLine(e,s)),b=redisFingerprint(e,i),_=capped;capped=0;const v={name:"cache",kind:"redis-op",op:e,key:a,command:x,startedAt:n,...o?{secretKey:!0}:{},..._?{capSuppressed:_}:{}},g=s.slice(1);if(e==="get"&&t.promise&&typeof t.promise.then=="function"){const l=n;t.promise.then(h=>{const c=h!=null,u=c&&!o?(0,sql_values_1.newCacheValuesId)(l):void 0,T=(0,emit_1.lensEmitOutcome)("redis","info",`cache ${c?"hit":"miss"} ${a}`,{...v,hit:c,durationMs:Date.now()-l,...c&&!o?{value:clip((0,redact_1.redactSecretText)(String(h).slice(0,4096)),120)}:{},...u?{valuesId:u}:{}},b,C);u&&T==="written"&&(0,sql_values_1.keepCacheValues)(u,l,e,i,g,h)},()=>{});return}const m=o?void 0:(0,sql_values_1.newCacheValuesId)(n),y=m?{valuesId:m}:{};let S;if(e==="set"){const l=s.map(u=>String(u)),h=l.findIndex(u=>u.toUpperCase()==="EX"),c=h>=0?Number(l[h+1]):void 0;S=(0,emit_1.lensEmitOutcome)("redis","info",c?`cache set ${a} (ttl ${c}s)`:`cache set ${a}`,{...v,...c?{ttlSec:c}:{},...y},b,C)}else S=(0,emit_1.lensEmitOutcome)("redis","info",`cache ${e} ${a}`,{...v,...y},b,C);if(!m||S!=="written")return;const w=t.promise;w&&typeof w.then=="function"?w.then(l=>(0,sql_values_1.keepCacheValues)(m,n,e,i,g,l),()=>(0,sql_values_1.keepCacheValues)(m,n,e,i,g)):(0,sql_values_1.keepCacheValues)(m,n,e,i,g)}f(observe,"observe"),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
|
-
`)}:{},...i.length>0&&
|
|
5
|
-
`)}:{},...
|
|
1
|
+
"use strict";var S=Object.defineProperty;var a=(t,e)=>S(t,"name",{value:e,configurable:!0});var R=Object.defineProperty,f=a((t,e)=>R(t,"name",{value:e,configurable:!0}),"f"),E=Object.defineProperty,u=f((t,e)=>E(t,"name",{value:e,configurable:!0}),"u");Object.defineProperty(exports,"__esModule",{value:!0}),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(t,e){return/\bFATAL\b/.test(t)?"fatal":/\bERROR\b/.test(t)?"error":/\bWARN\b/.test(t)?"warning":/\bDEBUG\b/.test(t)||/\bVERBOSE\b/.test(t)?"debug":/\bLOG\b/.test(t)?"info":e}a(severityOf,"severityOf"),f(severityOf,"severityOf"),u(severityOf,"severityOf");const STACK_FRAME=/^\s+(at\s|\.\.\.\s\d+\smore)/,CONTINUATION=/^(\s+\S|[}\])]+[,;]?$)/,CONTINUES_WITHIN_MS=1e3;function emitChunk(t,e,l,c,g){const o=t.split(`
|
|
2
|
+
`).map(n=>n.replace(ANSI,"").replace(/\s+$/,""));let s=0,r=l;for(;s<o.length;){const n=o[s];if(s+=1,!n.trim())continue;const i=[];for(;s<o.length&&o[s].trim()&&CONTINUATION.test(o[s]);)i.push(o[s]),s+=1;const b=[n,...i].filter(_=>STACK_FRAME.test(_)),p=CONTINUATION.test(n)&&r&&c-r.at<=CONTINUES_WITHIN_MS?r.severity:void 0,O=severityOf(n,e),v=O!==e||/\b(?:FATAL|ERROR|WARN|DEBUG|VERBOSE|LOG)\b/.test(n),d=p??(v?O:b.length>0?"error":e),m=[n,...i];if(!p&&(0,tap_nest_logger_1.isLoggerEcho)(m.join(`
|
|
3
|
+
`),c)){r={severity:d,at:c};continue}(0,emit_1.lensLog)(d,p?n.trim():n,{...b.length>0?{stack:m.join(`
|
|
4
|
+
`)}:{},...i.length>0&&b.length<i.length?{text:m.join(`
|
|
5
|
+
`)}:{},...p?{continues:!0}:{},stream:g}),r={severity:d,at:c}}return r}a(emitChunk,"emitChunk"),f(emitChunk,"emitChunk"),u(emitChunk,"emitChunk");function tapStdout(){if(process.env.LENSMCP_LOGS==="0"||process.env.APP_RUNNER!=="1")return;const t=[[process.stdout,"info","stdout"],[process.stderr,"error","stderr"]];for(const[e,l,c]of t){if(e.write.__lensmcp)continue;const g=e.write.bind(e);let o;const s=u(function(r,...n){try{if(!(0,emit_1.isLensWriting)()){const i=typeof r=="string"?r:Buffer.isBuffer(r)?r.toString("utf8"):"";i&&i.indexOf("[lensmcp]")===-1&&(o=emitChunk(i,l,o,Date.now(),c))}}catch{}return g(r,...n)},"wrapped");s.__lensmcp=!0,e.write=s}}a(tapStdout,"tapStdout"),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.21",
|
|
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.21",
|
|
19
|
+
"@lensmcp/nest-instrumentation": "1.25.21",
|
|
20
|
+
"@lensmcp/protocol-types": "1.25.21",
|
|
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 o=Object.defineProperty;var a=(t,n)=>o(t,"name",{value:n,configurable:!0});var i=Object.defineProperty,r=a((t,n)=>i(t,"name",{value:n,configurable:!0}),"r"),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)();
|