@lensmcp/node-instrumentation 1.25.23 → 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.
- package/lib/tap-redis.js +1 -1
- 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
|
|
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.
|
|
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.
|
|
19
|
-
"@lensmcp/nest-instrumentation": "1.25.
|
|
20
|
-
"@lensmcp/protocol-types": "1.25.
|
|
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": {
|