@lensmcp/node-instrumentation 1.25.22 → 1.25.24

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.
Files changed (2) hide show
  1. package/lib/tap-redis.js +1 -1
  2. package/package.json +4 -4
package/lib/tap-redis.js CHANGED
@@ -1 +1 @@
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"),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)}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 i=String(r[n]??"");if(i.startsWith("bull:")||i.startsWith("{bull"))return!0}return!1}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 i=p(function(s,c){const a=n.call(this,s,c);try{observe(s)}catch{}return a},"wrapped");return i.__lensmcp=!0,r.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 r=e.slice(0,6).map((n,i)=>{const s=String(n??"");return i>0&&s.length>48?`\u2026(${(s.length/1024).toFixed(1)}kb)`:clip(s,64)});return[t.toUpperCase(),...r].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 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 i=t?.args??[],s=String(i[0]??""),c=(0,redact_1.isSecretCacheKey)(s),a=c?(0,key_pattern_1.foldKeyPattern)(s):s,C=(0,flow_context_1.flowContext)(),y=c?`${e.toUpperCase()} ${a} \u2026`:(0,redact_1.redactSecretText)(commandLine(e,i)),g=redisFingerprint(e,s),_=capped;capped=0;const S={name:"cache",kind:"redis-op",op:e,key:a,command:y,startedAt:n,...c?{secretKey:!0}:{},..._?{capSuppressed:_}:{}},h=i.slice(1);if(e==="get"&&t.promise&&typeof t.promise.then=="function"){const l=n;t.promise.then(f=>{const o=f!=null,u=o&&!c?(0,sql_values_1.newCacheValuesId)(l):void 0,x=(0,emit_1.lensEmitOutcome)("redis","info",`cache ${o?"hit":"miss"} ${a}`,{...S,hit:o,durationMs:Date.now()-l,...o&&!c?{value:clip((0,redact_1.redactSecretText)(String(f).slice(0,4096)),120)}:{},...u?{valuesId:u}:{}},g,C);u&&x==="written"&&(0,sql_values_1.keepCacheValues)(u,l,e,s,h,f)},()=>{});return}const m=c?void 0:(0,sql_values_1.newCacheValuesId)(n),v=m?{valuesId:m}:{};let w;if(e==="set"){const l=i.map(u=>String(u)),f=l.findIndex(u=>u.toUpperCase()==="EX"),o=f>=0?Number(l[f+1]):void 0;w=(0,emit_1.lensEmitOutcome)("redis","info",o?`cache set ${a} (ttl ${o}s)`:`cache set ${a}`,{...S,...o?{ttlSec:o}:{},...v},g,C)}else w=(0,emit_1.lensEmitOutcome)("redis","info",`cache ${e} ${a}`,{...S,...v},g,C);if(!m||w!=="written")return;const b=t.promise;b&&typeof b.then=="function"?b.then(l=>(0,sql_values_1.keepCacheValues)(m,n,e,s,h,l),()=>(0,sql_values_1.keepCacheValues)(m,n,e,s,h)):(0,sql_values_1.keepCacheValues)(m,n,e,s,h)}d(observe,"observe"),p(observe,"observe");
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/node-instrumentation",
3
- "version": "1.25.22",
3
+ "version": "1.25.24",
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.22",
19
- "@lensmcp/nest-instrumentation": "1.25.22",
20
- "@lensmcp/protocol-types": "1.25.22",
18
+ "@lensmcp/core": "1.25.24",
19
+ "@lensmcp/nest-instrumentation": "1.25.24",
20
+ "@lensmcp/protocol-types": "1.25.24",
21
21
  "tslib": "^2.3.0"
22
22
  },
23
23
  "optionalDependencies": {