@lensmcp/node-instrumentation 1.22.2 → 1.22.3

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.d.ts CHANGED
@@ -4,7 +4,7 @@ export { createEventFloodGuard } from './lib/flood-guard';
4
4
  export type { FloodGuard, FloodGuardOptions, FloodAdmit } from './lib/flood-guard';
5
5
  export { installRequireHook } from './lib/require-hook';
6
6
  export type { ModuleTap } from './lib/require-hook';
7
- export { tapEgress } from './lib/tap-egress';
7
+ export { tapEgress, resetEgressTapForTests } from './lib/tap-egress';
8
8
  export { tapEventLoop, stopEventLoopTapForTests } from './lib/tap-event-loop';
9
9
  export { tapFs } from './lib/tap-fs';
10
10
  export { tapExec } from './lib/tap-exec';
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var i=Object.defineProperty;var o=(t,r)=>i(t,"name",{value:r,configurable:!0});var n=Object.defineProperty,e=o((t,r)=>n(t,"name",{value:r,configurable:!0}),"e");Object.defineProperty(exports,"__esModule",{value:!0}),exports.resetActiveWorkForTests=exports.installActiveWorkProbe=exports.beginActiveWork=exports.activeWorkSnapshot=exports.installLensmcpNodeInstrumentation=exports.installChildAppBridge=exports.nestTap=exports.bullmqTap=exports.redisTap=exports.pgTap=exports.tapExec=exports.tapFs=exports.stopEventLoopTapForTests=exports.tapEventLoop=exports.tapEgress=exports.installRequireHook=exports.createEventFloodGuard=exports.maybeRotateEventFile=exports.EVENT_MAX_FILES=exports.EVENT_MAX_BYTES=exports.EVENT_FILE=exports.PROJECT=exports.isLensWriting=exports.lensEmit=void 0;var emit_1=require("./lib/emit");Object.defineProperty(exports,"lensEmit",{enumerable:!0,get:e(function(){return emit_1.lensEmit},"get")}),Object.defineProperty(exports,"isLensWriting",{enumerable:!0,get:e(function(){return emit_1.isLensWriting},"get")}),Object.defineProperty(exports,"PROJECT",{enumerable:!0,get:e(function(){return emit_1.PROJECT},"get")}),Object.defineProperty(exports,"EVENT_FILE",{enumerable:!0,get:e(function(){return emit_1.EVENT_FILE},"get")}),Object.defineProperty(exports,"EVENT_MAX_BYTES",{enumerable:!0,get:e(function(){return emit_1.EVENT_MAX_BYTES},"get")}),Object.defineProperty(exports,"EVENT_MAX_FILES",{enumerable:!0,get:e(function(){return emit_1.EVENT_MAX_FILES},"get")}),Object.defineProperty(exports,"maybeRotateEventFile",{enumerable:!0,get:e(function(){return emit_1.maybeRotateEventFile},"get")});var flood_guard_1=require("./lib/flood-guard");Object.defineProperty(exports,"createEventFloodGuard",{enumerable:!0,get:e(function(){return flood_guard_1.createEventFloodGuard},"get")});var require_hook_1=require("./lib/require-hook");Object.defineProperty(exports,"installRequireHook",{enumerable:!0,get:e(function(){return require_hook_1.installRequireHook},"get")});var tap_egress_1=require("./lib/tap-egress");Object.defineProperty(exports,"tapEgress",{enumerable:!0,get:e(function(){return tap_egress_1.tapEgress},"get")});var tap_event_loop_1=require("./lib/tap-event-loop");Object.defineProperty(exports,"tapEventLoop",{enumerable:!0,get:e(function(){return tap_event_loop_1.tapEventLoop},"get")}),Object.defineProperty(exports,"stopEventLoopTapForTests",{enumerable:!0,get:e(function(){return tap_event_loop_1.stopEventLoopTapForTests},"get")});var tap_fs_1=require("./lib/tap-fs");Object.defineProperty(exports,"tapFs",{enumerable:!0,get:e(function(){return tap_fs_1.tapFs},"get")});var tap_exec_1=require("./lib/tap-exec");Object.defineProperty(exports,"tapExec",{enumerable:!0,get:e(function(){return tap_exec_1.tapExec},"get")});var tap_pg_1=require("./lib/tap-pg");Object.defineProperty(exports,"pgTap",{enumerable:!0,get:e(function(){return tap_pg_1.pgTap},"get")});var tap_redis_1=require("./lib/tap-redis");Object.defineProperty(exports,"redisTap",{enumerable:!0,get:e(function(){return tap_redis_1.redisTap},"get")});var tap_bullmq_1=require("./lib/tap-bullmq");Object.defineProperty(exports,"bullmqTap",{enumerable:!0,get:e(function(){return tap_bullmq_1.bullmqTap},"get")});var tap_nest_1=require("./lib/tap-nest");Object.defineProperty(exports,"nestTap",{enumerable:!0,get:e(function(){return tap_nest_1.nestTap},"get")}),Object.defineProperty(exports,"installChildAppBridge",{enumerable:!0,get:e(function(){return tap_nest_1.installChildAppBridge},"get")});var install_1=require("./lib/install");Object.defineProperty(exports,"installLensmcpNodeInstrumentation",{enumerable:!0,get:e(function(){return install_1.installLensmcpNodeInstrumentation},"get")});var active_work_1=require("./lib/active-work");Object.defineProperty(exports,"activeWorkSnapshot",{enumerable:!0,get:e(function(){return active_work_1.activeWorkSnapshot},"get")}),Object.defineProperty(exports,"beginActiveWork",{enumerable:!0,get:e(function(){return active_work_1.beginActiveWork},"get")}),Object.defineProperty(exports,"installActiveWorkProbe",{enumerable:!0,get:e(function(){return active_work_1.installActiveWorkProbe},"get")}),Object.defineProperty(exports,"resetActiveWorkForTests",{enumerable:!0,get:e(function(){return active_work_1.resetActiveWorkForTests},"get")});
1
+ "use strict";var p=Object.defineProperty;var o=(t,r)=>p(t,"name",{value:r,configurable:!0});var n=Object.defineProperty,e=o((t,r)=>n(t,"name",{value:r,configurable:!0}),"e");Object.defineProperty(exports,"__esModule",{value:!0}),exports.resetActiveWorkForTests=exports.installActiveWorkProbe=exports.beginActiveWork=exports.activeWorkSnapshot=exports.installLensmcpNodeInstrumentation=exports.installChildAppBridge=exports.nestTap=exports.bullmqTap=exports.redisTap=exports.pgTap=exports.tapExec=exports.tapFs=exports.stopEventLoopTapForTests=exports.tapEventLoop=exports.resetEgressTapForTests=exports.tapEgress=exports.installRequireHook=exports.createEventFloodGuard=exports.maybeRotateEventFile=exports.EVENT_MAX_FILES=exports.EVENT_MAX_BYTES=exports.EVENT_FILE=exports.PROJECT=exports.isLensWriting=exports.lensEmit=void 0;var emit_1=require("./lib/emit");Object.defineProperty(exports,"lensEmit",{enumerable:!0,get:e(function(){return emit_1.lensEmit},"get")}),Object.defineProperty(exports,"isLensWriting",{enumerable:!0,get:e(function(){return emit_1.isLensWriting},"get")}),Object.defineProperty(exports,"PROJECT",{enumerable:!0,get:e(function(){return emit_1.PROJECT},"get")}),Object.defineProperty(exports,"EVENT_FILE",{enumerable:!0,get:e(function(){return emit_1.EVENT_FILE},"get")}),Object.defineProperty(exports,"EVENT_MAX_BYTES",{enumerable:!0,get:e(function(){return emit_1.EVENT_MAX_BYTES},"get")}),Object.defineProperty(exports,"EVENT_MAX_FILES",{enumerable:!0,get:e(function(){return emit_1.EVENT_MAX_FILES},"get")}),Object.defineProperty(exports,"maybeRotateEventFile",{enumerable:!0,get:e(function(){return emit_1.maybeRotateEventFile},"get")});var flood_guard_1=require("./lib/flood-guard");Object.defineProperty(exports,"createEventFloodGuard",{enumerable:!0,get:e(function(){return flood_guard_1.createEventFloodGuard},"get")});var require_hook_1=require("./lib/require-hook");Object.defineProperty(exports,"installRequireHook",{enumerable:!0,get:e(function(){return require_hook_1.installRequireHook},"get")});var tap_egress_1=require("./lib/tap-egress");Object.defineProperty(exports,"tapEgress",{enumerable:!0,get:e(function(){return tap_egress_1.tapEgress},"get")}),Object.defineProperty(exports,"resetEgressTapForTests",{enumerable:!0,get:e(function(){return tap_egress_1.resetEgressTapForTests},"get")});var tap_event_loop_1=require("./lib/tap-event-loop");Object.defineProperty(exports,"tapEventLoop",{enumerable:!0,get:e(function(){return tap_event_loop_1.tapEventLoop},"get")}),Object.defineProperty(exports,"stopEventLoopTapForTests",{enumerable:!0,get:e(function(){return tap_event_loop_1.stopEventLoopTapForTests},"get")});var tap_fs_1=require("./lib/tap-fs");Object.defineProperty(exports,"tapFs",{enumerable:!0,get:e(function(){return tap_fs_1.tapFs},"get")});var tap_exec_1=require("./lib/tap-exec");Object.defineProperty(exports,"tapExec",{enumerable:!0,get:e(function(){return tap_exec_1.tapExec},"get")});var tap_pg_1=require("./lib/tap-pg");Object.defineProperty(exports,"pgTap",{enumerable:!0,get:e(function(){return tap_pg_1.pgTap},"get")});var tap_redis_1=require("./lib/tap-redis");Object.defineProperty(exports,"redisTap",{enumerable:!0,get:e(function(){return tap_redis_1.redisTap},"get")});var tap_bullmq_1=require("./lib/tap-bullmq");Object.defineProperty(exports,"bullmqTap",{enumerable:!0,get:e(function(){return tap_bullmq_1.bullmqTap},"get")});var tap_nest_1=require("./lib/tap-nest");Object.defineProperty(exports,"nestTap",{enumerable:!0,get:e(function(){return tap_nest_1.nestTap},"get")}),Object.defineProperty(exports,"installChildAppBridge",{enumerable:!0,get:e(function(){return tap_nest_1.installChildAppBridge},"get")});var install_1=require("./lib/install");Object.defineProperty(exports,"installLensmcpNodeInstrumentation",{enumerable:!0,get:e(function(){return install_1.installLensmcpNodeInstrumentation},"get")});var active_work_1=require("./lib/active-work");Object.defineProperty(exports,"activeWorkSnapshot",{enumerable:!0,get:e(function(){return active_work_1.activeWorkSnapshot},"get")}),Object.defineProperty(exports,"beginActiveWork",{enumerable:!0,get:e(function(){return active_work_1.beginActiveWork},"get")}),Object.defineProperty(exports,"installActiveWorkProbe",{enumerable:!0,get:e(function(){return active_work_1.installActiveWorkProbe},"get")}),Object.defineProperty(exports,"resetActiveWorkForTests",{enumerable:!0,get:e(function(){return active_work_1.resetActiveWorkForTests},"get")});
@@ -1 +1,11 @@
1
1
  export declare function tapEgress(): void;
2
+ /**
3
+ * Restore the originals and clear the install markers.
4
+ *
5
+ * Required for testability: the installed wrapper closes over the FIRST module
6
+ * instance's `EVENT_FILE`, and both markers (`globalThis.__lensmcpFetchTap`, and
7
+ * `request.__lensmcp` on the http module singleton) survive `jest.resetModules()`.
8
+ * Without this, every tap-egress test after the first writes into the first
9
+ * test's temp dir. Same trap `tap-stdout.spec.ts` documents for `process.stderr`.
10
+ */
11
+ export declare function resetEgressTapForTests(): void;
package/lib/tap-egress.js CHANGED
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var l=(s,n)=>p(s,"name",{value:n,configurable:!0});var u=Object.defineProperty,f=l((s,n)=>u(s,"name",{value:n,configurable:!0}),"f");Object.defineProperty(exports,"__esModule",{value:!0}),exports.tapEgress=tapEgress;const emit_1=require("./emit"),flow_context_1=require("./flow-context"),INTERNAL=[/\.local$/i,/^localhost$/i,/^127\./,/^\[?::1\]?$/,/^0\.0\.0\.0$/,/^10\./,/^192\.168\./],isInternal=f(s=>s===""||INTERNAL.some(n=>n.test(s)),"isInternal");function tapEgress(){tapFetch(),tapHttpModule("http"),tapHttpModule("https")}l(tapEgress,"tapEgress"),f(tapEgress,"tapEgress");function tapFetch(){const s=globalThis;if(typeof s.fetch!="function"||s.__lensmcpFetchTap)return;s.__lensmcpFetchTap=!0;const n=s.fetch.bind(globalThis);s.fetch=(async(e,o)=>{let t="";try{t=new URL(typeof e=="string"?e:e instanceof URL?e.href:e.url).hostname}catch{}if(isInternal(t))return n(e,o);const a=Date.now(),h=(0,flow_context_1.flowContext)(),i=(0,flow_context_1.liveFlowContext)();i&&(i.externalCallCount=(i.externalCallCount??0)+1);const c=String(o?.method??"GET").toUpperCase();try{const r=await n(e,o);return(0,emit_1.lensEmit)("external","info",`egress ${c} ${t} \u2192 ${r.status}`,{name:t,kind:"egress",method:c,host:t,status:r.status,startedAt:a,durationMs:Date.now()-a},void 0,h),r}catch(r){throw(0,emit_1.lensEmit)("external","error",`egress ${c} ${t} failed`,{name:t,kind:"egress",method:c,host:t,error:String(r?.message??r),startedAt:a,durationMs:Date.now()-a},void 0,h),r}})}l(tapFetch,"tapFetch"),f(tapFetch,"tapFetch");function tapHttpModule(s){const n=require(`node:${s}`),e=n.request;if(typeof e!="function"||e.__lensmcp)return;const o=f(function(...t){const a=e.apply(this,t);try{observe(t,a)}catch{}return a},"wrapped");o.__lensmcp=!0,n.request=o,typeof n.get=="function"&&(n.get=function(...t){const a=o.apply(this,t);return a.end(),a})}l(tapHttpModule,"tapHttpModule"),f(tapHttpModule,"tapHttpModule");function observe(s,n){const{host:e,method:o}=parseTarget(s);if(isInternal(e))return;const t=Date.now(),a=(0,flow_context_1.flowContext)(),h=(0,flow_context_1.liveFlowContext)();h&&(h.externalCallCount=(h.externalCallCount??0)+1);let i=!1;n.once("response",(...c)=>{if(i)return;i=!0;const r=c[0];(0,emit_1.lensEmit)("external","info",`egress ${o} ${e} \u2192 ${r?.statusCode??"?"}`,{name:e,kind:"egress",method:o,host:e,...r?.statusCode!=null?{status:r.statusCode}:{},startedAt:t,durationMs:Date.now()-t},void 0,a)}),n.once("error",(...c)=>{if(i)return;i=!0;const r=c[0];(0,emit_1.lensEmit)("external","error",`egress ${o} ${e} failed`,{name:e,kind:"egress",method:o,host:e,error:String(r?.message??r),startedAt:t,durationMs:Date.now()-t},void 0,a)})}l(observe,"observe"),f(observe,"observe");function parseTarget(s){let n="",e="GET";for(const o of s)if(typeof o=="string")try{n=new URL(o).hostname}catch{}else if(o instanceof URL)n=o.hostname;else if(o&&typeof o=="object"){const t=o;if(typeof t.method=="string"&&(e=t.method.toUpperCase()),typeof t.socketPath=="string")return{host:"",method:e};typeof t.hostname=="string"&&t.hostname?n=t.hostname:typeof t.host=="string"&&t.host&&(n=t.host.split(":")[0]??"")}return{host:n,method:e}}l(parseTarget,"parseTarget"),f(parseTarget,"parseTarget");
1
+ "use strict";var y=Object.defineProperty;var f=(t,s)=>y(t,"name",{value:s,configurable:!0});var g=Object.defineProperty,i=f((t,s)=>g(t,"name",{value:s,configurable:!0}),"i");Object.defineProperty(exports,"__esModule",{value:!0}),exports.tapEgress=tapEgress,exports.resetEgressTapForTests=resetEgressTapForTests;const redact_1=require("@lensmcp/core/redact"),emit_1=require("./emit"),flow_context_1=require("./flow-context"),INTERNAL=[/\.local$/i,/\.internal$/i,/^localhost$/i,/^127\./,/^\[?::1\]?$/,/^0\.0\.0\.0$/,/^10\./,/^192\.168\./,/^172\.(1[6-9]|2\d|3[01])\./,/^169\.254\./,/^\[?[fF][cCdD][0-9a-fA-F]{2}:/,/^\[?[fF][eE]80:/],isInternal=i(t=>t===""||INTERNAL.some(s=>s.test(t)),"isInternal"),CAPTURE_QUERY=process.env.LENSMCP_EGRESS_QUERY==="1",MAX_PATH_CHARS=256,clipPath=i(t=>t.length>MAX_PATH_CHARS?`${t.slice(0,MAX_PATH_CHARS)}\u2026`:t,"clipPath");function capturePath(t,s){const e=t||"/";return!CAPTURE_QUERY||s.length<=1?clipPath(e):(0,redact_1.redactUrl)(`${e}${s}`)}f(capturePath,"capturePath"),i(capturePath,"capturePath");const fingerprintFor=i((t,s)=>s?`external:error:${t}`:`external:${t}`,"fingerprintFor");function tapEgress(){tapFetch(),tapHttpModule("http"),tapHttpModule("https")}f(tapEgress,"tapEgress"),i(tapEgress,"tapEgress");let savedFetch;const httpOriginals=new Map;function resetEgressTapForTests(){const t=globalThis;savedFetch&&(t.fetch=savedFetch),delete t.__lensmcpFetchTap,restoreHttp("http"),restoreHttp("https"),savedFetch=void 0}f(resetEgressTapForTests,"resetEgressTapForTests"),i(resetEgressTapForTests,"resetEgressTapForTests");function restoreHttp(t){const s=httpOriginals.get(t);if(!s)return;const e=require(`node:${t}`);e.request=s.request,e.get=s.get,httpOriginals.delete(t)}f(restoreHttp,"restoreHttp"),i(restoreHttp,"restoreHttp");function tapFetch(){const t=globalThis;if(typeof t.fetch!="function"||t.__lensmcpFetchTap)return;t.__lensmcpFetchTap=!0;const s=t.fetch.bind(globalThis);savedFetch=t.fetch,t.fetch=(async(e,a)=>{let r="",c="/",o=!1;try{const p=new URL(typeof e=="string"?e:e instanceof URL?e.href:e.url);r=p.hostname,o=p.search.length>1,c=capturePath(p.pathname,p.search)}catch{}if(isInternal(r))return s(e,a);const n=Date.now(),u=(0,flow_context_1.flowContext)(),h=(0,flow_context_1.liveFlowContext)();h&&(h.externalCallCount=(h.externalCallCount??0)+1);const d=typeof e=="object"&&e!==null&&!(e instanceof URL)?e.method:void 0,l=String(a?.method??d??"GET").toUpperCase();try{const p=await s(e,a),m=p.status>=500;return(0,emit_1.lensEmit)("external","info",`egress ${l} ${r} \u2192 ${p.status}`,{name:r,kind:"egress",method:l,host:r,path:c,status:p.status,...o?{hasQuery:!0}:{},startedAt:n,durationMs:Date.now()-n},fingerprintFor(r,m),u),p}catch(p){throw(0,emit_1.lensEmit)("external","error",`egress ${l} ${r} failed`,{name:r,kind:"egress",method:l,host:r,path:c,...o?{hasQuery:!0}:{},error:String(p?.message??p),startedAt:n,durationMs:Date.now()-n},fingerprintFor(r,!0),u),p}})}f(tapFetch,"tapFetch"),i(tapFetch,"tapFetch");function tapHttpModule(t){const s=require(`node:${t}`),e=s.request;if(typeof e!="function"||e.__lensmcp)return;httpOriginals.set(t,{request:e,get:s.get});const a=i(function(...r){const c=e.apply(this,r);try{observe(r,c)}catch{}return c},"wrapped");a.__lensmcp=!0,s.request=a,typeof s.get=="function"&&(s.get=function(...r){const c=a.apply(this,r);return c.end(),c})}f(tapHttpModule,"tapHttpModule"),i(tapHttpModule,"tapHttpModule");function observe(t,s){const{host:e,method:a,path:r,hasQuery:c}=parseTarget(t);if(isInternal(e))return;const o=Date.now(),n=(0,flow_context_1.flowContext)(),u=(0,flow_context_1.liveFlowContext)();u&&(u.externalCallCount=(u.externalCallCount??0)+1);let h=!1;s.once("response",(...d)=>{if(h)return;h=!0;const l=d[0]?.statusCode;(0,emit_1.lensEmit)("external","info",`egress ${a} ${e} \u2192 ${l??"?"}`,{name:e,kind:"egress",method:a,host:e,path:r,...l!=null?{status:l}:{},...c?{hasQuery:!0}:{},startedAt:o,durationMs:Date.now()-o},fingerprintFor(e,l!=null&&l>=500),n)}),s.once("error",(...d)=>{if(h)return;h=!0;const l=d[0];(0,emit_1.lensEmit)("external","error",`egress ${a} ${e} failed`,{name:e,kind:"egress",method:a,host:e,path:r,...c?{hasQuery:!0}:{},error:String(l?.message??l),startedAt:o,durationMs:Date.now()-o},fingerprintFor(e,!0),n)})}f(observe,"observe"),i(observe,"observe");function parseTarget(t){let s="",e="GET",a="/",r=!1;const c=i((o,n)=>{r=n.length>1,a=capturePath(o,n)},"take");for(const o of t)if(typeof o=="string")try{const n=new URL(o);s=n.hostname,c(n.pathname,n.search)}catch{}else if(o instanceof URL)s=o.hostname,c(o.pathname,o.search);else if(o&&typeof o=="object"){const n=o;if(typeof n.method=="string"&&(e=n.method.toUpperCase()),typeof n.socketPath=="string")return{host:"",method:e,path:a,hasQuery:r};if(typeof n.path=="string"){const u=n.path,h=u.indexOf("?");c(h===-1?u:u.slice(0,h),h===-1?"":u.slice(h))}typeof n.hostname=="string"&&n.hostname?s=n.hostname:typeof n.host=="string"&&n.host&&(s=n.host.split(":")[0]??"")}return{host:s,method:e,path:a,hasQuery:r}}f(parseTarget,"parseTarget"),i(parseTarget,"parseTarget");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/node-instrumentation",
3
- "version": "1.22.2",
3
+ "version": "1.22.3",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -15,8 +15,9 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@lensmcp/nest-instrumentation": "1.22.2",
19
- "@lensmcp/protocol-types": "1.22.2",
18
+ "@lensmcp/core": "1.22.3",
19
+ "@lensmcp/nest-instrumentation": "1.22.3",
20
+ "@lensmcp/protocol-types": "1.22.3",
20
21
  "tslib": "^2.3.0"
21
22
  },
22
23
  "optionalDependencies": {