@lensmcp/node-instrumentation 1.25.17 → 1.25.18

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/tap-pg.js CHANGED
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var p=(t,e)=>j(t,"name",{value:e,configurable:!0});var W=Object.defineProperty,r=p((t,e)=>W(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"),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}:{}}}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)})}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}}p(resultPreview,"resultPreview"),r(resultPreview,"resultPreview");function connectionOf(t){const e=t,n=e?.connectionParameters,o=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{...o?{database:o}:{},...s?{server:`${s}:${i}`}:{}}}p(connectionOf,"connectionOf"),r(connectionOf,"connectionOf");const APP_NAME_MAX=63;function taggedAppName(t,e,n,o){const s=` lens:${e.replace(/[^\x21-\x7e]/g,"?").replace(/:/g,"_")}${n>0?`:g${n}`:""}${o?`:p${o}`:""}`.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}`}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 o=e.call(this);try{o&&typeof o=="object"&&emit_2.PROJECT&&(o.application_name=taggedAppName(typeof o.application_name=="string"?o.application_name:void 0,emit_2.PROJECT,(0,active_work_1.activeWorkGeneration)(),process.pid))}catch{}return o},"wrapped");n.__lensmcp=!0,t.getStartupConf=n}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 o=r(function(s,i,_){const f=s,d=typeof f=="string"?f:f?.text;if(!d||f&&typeof f=="object"&&typeof f.submit=="function")return n.call(this,s,i,_);if(SKIP_OPS.has(firstWord(d)))return n.call(this,s,i,_);const{op:R,table:c,sqlId:g,tables:P,name:$}=parseSql(d),k=connectionOf(this),m=R.toLowerCase(),D=`db:${m}:${c??"query"}`,y=Date.now(),A=(0,flow_context_1.flowContext)(),J=(0,callsite_1.captureSite)(),C=(0,tap_pg_pool_1.checkoutSite)(),b=(0,flow_context_1.liveFlowContext)();b&&(b.dbCallCount=(b.dbCallCount??0)+1);const h=(0,sql_accounting_1.beginSqlStatement)(b,A,y),M=clip(oneLine(d),500),N=paramPreview(Array.isArray(i)?i:s?.values),q=N&&(0,redact_1.redactSqlParams)(d,N),w=r((a,u)=>{const l=Date.now()-y,v=y-(statementSentAt.get(g)??-1/0)>=STATEMENT_EVERY_MS;let T;try{T=sites.site(g,J,{force:!!a||v||l>=SLOW_SITE_MS,...C?{fallback:C}:{}})}catch{}const x={sqlId:g,...P.length?{tables:P}:{},...$?{sqlName:$}:{},...k,...T?{site:T}:{},...v?{statement:clip(d.trim(),STATEMENT_MAX)}:{}};let E;if(a)E=(0,emit_1.lensEmitOutcome)("db","error",`${m}${c?" "+c:""} failed (${l}ms)`,{name:"postgres",kind:"db-query",op:m,...c?{table:c}:{},...x,query:M,...q?{params:q}:{},startedAt:y,error:String(a?.message??a),durationMs:l},`db:error:${m}:${c??"query"}`,A);else{const L=rowsOf(u),I=resultPreview(u);E=(0,emit_1.lensEmitOutcome)("db","info",`${m} ${c??"query"} (${L} rows, ${l}ms)`,{name:"postgres",kind:"db-query",op:m,...c?{table:c}:{},...x,query:M,...q?{params:q}:{},...I?{result:I}:{},startedAt:y,rows:L,durationMs:l},D,A)}v&&E==="written"&&(statementSentAt.delete(g),statementSentAt.set(g,y),statementSentAt.size>MAX_SHAPES_REMEMBERED&&statementSentAt.delete(statementSentAt.keys().next().value)),(0,sql_accounting_1.endSqlStatement)(h,{durationMs:l,failed:!!a,emitted:E})},"done"),O=typeof _=="function"?_:typeof i=="function"?i:void 0;if(O){const a=r((u,l)=>{try{w(u,l)}catch{}O(u,l)},"wrappedCb");try{return typeof i=="function"?n.call(this,s,a):n.call(this,s,i,a)}catch(u){throw(0,sql_accounting_1.abandonSqlStatement)(h),u}}let S;try{S=n.call(this,s,i)}catch(a){throw(0,sql_accounting_1.abandonSqlStatement)(h),a}return S&&typeof S.then=="function"?S.then(a=>w(void 0,a),a=>w(a,void 0)):(0,sql_accounting_1.abandonSqlStatement)(h),S},"wrapped");return o.__lensmcp=!0,e.query=o,!0}p(pgTap,"pgTap"),r(pgTap,"pgTap");
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");
@@ -1 +1,3 @@
1
+ /** The flood bucket of a command: its op and key family — or the shared one past `MAX_SHAPES`. */
2
+ export declare function redisFingerprint(op: string, key: string): string;
1
3
  export declare function redisTap(exportsObject: unknown): boolean;
package/lib/tap-redis.js CHANGED
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var a=(t,e)=>b(t,"name",{value:e,configurable:!0});var h=Object.defineProperty,c=a((t,e)=>h(t,"name",{value:e,configurable:!0}),"c");Object.defineProperty(exports,"__esModule",{value:!0}),exports.redisTap=redisTap;const emit_1=require("./emit"),flow_context_1=require("./flow-context"),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=30;let emitted=0,windowStart=0;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}a(isBullTraffic,"isBullTraffic"),c(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=c(function(i,l){const f=n.call(this,i,l);try{observe(i)}catch{}return f},"wrapped");return s.__lensmcp=!0,r.sendCommand=s,!0}a(redisTap,"redisTap"),c(redisTap,"redisTap");const clip=c((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(" ")}a(commandLine,"commandLine"),c(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)return;const s=t?.args??[],i=String(s[0]??""),l=(0,flow_context_1.flowContext)(),f=commandLine(e,s),m={name:"cache",kind:"redis-op",op:e,key:i,command:f,startedAt:n};if(e==="get"&&t.promise&&typeof t.promise.then=="function"){const d=n;t.promise.then(u=>{const o=u!=null;(0,emit_1.lensEmit)("redis","info",`cache ${o?"hit":"miss"} ${i}`,{...m,hit:o,durationMs:Date.now()-d,...o?{value:clip(String(u),120)}:{}},"redis:cache",l)},()=>{});return}if(e==="set"){const d=s.map(p=>String(p)),u=d.findIndex(p=>p.toUpperCase()==="EX"),o=u>=0?Number(d[u+1]):void 0;(0,emit_1.lensEmit)("redis","info",o?`cache set ${i} (ttl ${o}s)`:`cache set ${i}`,{...m,...o?{ttlSec:o}:{}},"redis:cache",l);return}(0,emit_1.lensEmit)("redis","info",`cache ${e} ${i}`,m,"redis:cache",l)}a(observe,"observe"),c(observe,"observe");
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 R=Object.defineProperty;var f=(t,e)=>R(t,"name",{value:e,configurable:!0});var 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}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,p,c,l){const o=t.split(`
2
- `).map(r=>r.replace(ANSI,"").replace(/\s+$/,""));let s=0,n=p;for(;s<o.length;){const r=o[s];if(s+=1,!r.trim())continue;const i=[];for(;s<o.length&&o[s].trim()&&CONTINUATION.test(o[s]);)i.push(o[s]),s+=1;const g=[r,...i].filter(_=>STACK_FRAME.test(_)),a=CONTINUATION.test(r)&&n&&c-n.at<=CONTINUES_WITHIN_MS?n.severity:void 0,m=severityOf(r,e),O=m!==e||/\b(?:FATAL|ERROR|WARN|DEBUG|VERBOSE|LOG)\b/.test(r),b=a??(O?m:g.length>0?"error":e),d=[r,...i];if(!a&&(0,tap_nest_logger_1.isLoggerEcho)(d.join(`
3
- `),c)){n={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}),n={severity:b,at:c}}return n}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,p,c]of t){if(e.write.__lensmcp)continue;const l=e.write.bind(e);let o;const s=u(function(n,...r){try{if(!(0,emit_1.isLensWriting)()){const i=typeof n=="string"?n:Buffer.isBuffer(n)?n.toString("utf8"):"";i&&i.indexOf("[lensmcp]")===-1&&(o=emitChunk(i,p,o,Date.now(),c))}}catch{}return l(n,...r)},"wrapped");s.__lensmcp=!0,e.write=s}}f(tapStdout,"tapStdout"),u(tapStdout,"tapStdout");
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.17",
3
+ "version": "1.25.18",
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.17",
19
- "@lensmcp/nest-instrumentation": "1.25.17",
20
- "@lensmcp/protocol-types": "1.25.17",
18
+ "@lensmcp/core": "1.25.18",
19
+ "@lensmcp/nest-instrumentation": "1.25.18",
20
+ "@lensmcp/protocol-types": "1.25.18",
21
21
  "tslib": "^2.3.0"
22
22
  },
23
23
  "optionalDependencies": {
package/register.js CHANGED
@@ -1 +1 @@
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)();
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)();