@lensmcp/node-instrumentation 1.25.71 → 1.25.73

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.
@@ -1 +1 @@
1
- "use strict";var q=Object.defineProperty;var a=(r,e)=>q(r,"name",{value:e,configurable:!0});var x=Object.defineProperty,d=a((r,e)=>x(r,"name",{value:e,configurable:!0}),"d");Object.defineProperty(exports,"__esModule",{value:!0}),exports.EXCHANGE_ID=void 0,exports.tapIngress=tapIngress,exports.resetIngressTapForTests=resetIngressTapForTests;const tslib_1=require("tslib"),http=tslib_1.__importStar(require("node:http")),zlib=tslib_1.__importStar(require("node:zlib")),headless_flow_1=require("@lensmcp/core/headless-flow"),http_exchange_1=require("@lensmcp/core/http-exchange"),emit_1=require("./emit"),lens_time_1=require("./lens-time"),http_store_1=require("./http-store");exports.EXCHANGE_ID=Symbol.for("lensmcp.exchangeId");const MAX_READ=2*1024*1024,MAX_PATH_CHARS=256;let originalEmit;function tapIngress(){if(originalEmit)return;const r=(0,http_store_1.httpCaptureMode)();if(r==="off")return;(0,http_store_1.primeHttpStore)();const e=http.Server.prototype,s=e.emit;originalEmit=s,e.emit=function(t,...i){if(t==="request")try{watch(i[0],i[1],r)}catch{}return s.call(this,t,...i)}}a(tapIngress,"tapIngress"),d(tapIngress,"tapIngress");function resetIngressTapForTests(){originalEmit&&(http.Server.prototype.emit=originalEmit),originalEmit=void 0}a(resetIngressTapForTests,"resetIngressTapForTests"),d(resetIngressTapForTests,"resetIngressTapForTests");const one=d(r=>r===void 0?void 0:Array.isArray(r)?r.join(", "):String(r),"one"),pairs=d(r=>Object.entries(r).flatMap(([e,s])=>s===void 0?[]:[[e,one(s)]]),"pairs");class Tee{static{a(this,"Tee")}static{d(this,"Tee")}constructor(){this.chunks=[],this.read=0,this.size=0}take(e,s){if(e==null||typeof e=="function")return;const t=Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?Buffer.from(e,typeof s=="string"?s:"utf8"):void 0;t&&(this.size+=t.length,this.read<MAX_READ&&(this.chunks.push(t),this.read+=t.length))}bytes(){return Buffer.concat(this.chunks)}}function watch(r,e,s){if(!r||!e||r[exports.EXCHANGE_ID])return;const t=r.url??"/",i=t.indexOf("?"),l=i<0?t:t.slice(0,i);if((0,headless_flow_1.isProbePath)(l))return;const h=(0,http_store_1.newExchangeId)();r[exports.EXCHANGE_ID]=h;const m=Date.now(),f=s==="bodies"&&!(0,http_store_1.proofBoundHeaders)(r.headers),g=new Tee,c=new Tee;if(f){const y=r.emit;r.emit=function(o,...n){return o==="data"&&g.take(n[0]),y.call(this,o,...n)};const b=e.write,w=e.end;e.write=function(o,...n){return c.take(o,n[0]),b.call(this,o,...n)},e.end=function(o,...n){return c.take(o,n[0]),w.call(this,o,...n)}}let u=!1;const p=d(()=>{if(!u){u=!0;try{(0,lens_time_1.lensTimed)(()=>(0,http_store_1.queueHttpExchange)(exchangeOf(h,r,e,{url:t,q:i,path:l,startedAt:m,bodies:f,sent:g,answered:c})))}catch{}}},"finish");e.once("finish",p),e.once("close",p)}a(watch,"watch"),d(watch,"watch");function unpacked(r,e){try{if(r==="gzip"||r==="x-gzip")return zlib.gunzipSync(e,{maxOutputLength:MAX_READ});if(r==="br")return zlib.brotliDecompressSync(e,{maxOutputLength:MAX_READ});if(r==="deflate")return zlib.inflateSync(e,{maxOutputLength:MAX_READ})}catch{return}}a(unpacked,"unpacked"),d(unpacked,"unpacked");function exchangeOf(r,e,s,t){const i=[],l=[],h=[],m=(0,http_store_1.redactHeaders)(pairs(e.headers));i.push(...m.redacted);const f=(0,http_store_1.redactHeaders)(pairs(s.getHeaders()));i.push(...f.redacted);const g=t.bodies&&t.q>=0?(0,http_store_1.redactQuery)(t.url.slice(t.q)):[];let c;t.bodies&&t.sent.size&&(c=(0,http_store_1.keepBody)(one(e.headers["content-type"])??"",t.sent.bytes(),t.sent.size,l));let u;if(t.bodies&&t.answered.size){const n=one(s.getHeader("content-type"))??"",_=(one(s.getHeader("content-encoding"))??"").trim().toLowerCase();if(!_||_==="identity")u=(0,http_store_1.keepBody)(n,t.answered.bytes(),t.answered.size,h);else{const E=t.answered.size<=MAX_READ?unpacked(_,t.answered.bytes()):void 0;u=E?(0,http_store_1.keepBody)(n,E,E.length,h):{contentType:n.split(";")[0].trim().toLowerCase(),size:t.answered.size,kept:0,truncated:!1,omitted:"encoded"}}}const p=one(e.headers.host)??"localhost",y=t.path.length>MAX_PATH_CHARS?`${t.path.slice(0,MAX_PATH_CHARS)}\u2026`:t.path,b=one(e.headers["x-lensmcp-flow-id"]),w=one(e.headers[http_exchange_1.LENS_REQUEST_ID_HEADER])||one(e.headers["x-request-id"]),o=!s.writableFinished;return{schemaVersion:1,id:r,capturedAt:Date.now(),side:"ingress",service:emit_1.PROJECT,...b?{flowId:b}:{},...w?{requestId:w}:{},method:(e.method??"GET").toUpperCase(),url:`http://${p}${y}`,host:p.split(":")[0]??p,path:y,status:s.statusCode,...s.statusMessage?{statusText:s.statusMessage}:{},...o?{error:"the client went away before the answer ended"}:{},startedAt:t.startedAt,durationMs:Date.now()-t.startedAt,capture:t.bodies?"bodies":"headers",request:{headers:m.headers,...g.length?{query:g}:{},...c?{body:c}:{}},response:{headers:f.headers,...u?{body:u}:{}},redacted:{headers:[...new Set(i)],bodyFields:[...l.map(n=>`request.${n}`),...h.map(n=>`response.${n}`)]}}}a(exchangeOf,"exchangeOf"),d(exchangeOf,"exchangeOf");
1
+ "use strict";var q=Object.defineProperty;var u=(r,t)=>q(r,"name",{value:t,configurable:!0});var z=Object.defineProperty,o=u((r,t)=>z(r,"name",{value:t,configurable:!0}),"o");Object.defineProperty(exports,"__esModule",{value:!0}),exports.EXCHANGE_ID=void 0,exports.tapIngress=tapIngress,exports.resetIngressTapForTests=resetIngressTapForTests;const tslib_1=require("tslib"),http=tslib_1.__importStar(require("node:http")),zlib=tslib_1.__importStar(require("node:zlib")),headless_flow_1=require("@lensmcp/core/headless-flow"),http_exchange_1=require("@lensmcp/core/http-exchange"),emit_1=require("./emit"),lens_time_1=require("./lens-time"),http_store_1=require("./http-store");exports.EXCHANGE_ID=Symbol.for("lensmcp.exchangeId");const MAX_READ=2*1024*1024,MAX_PATH_CHARS=256;let originalEmit;function tapIngress(){if(originalEmit)return;const r=(0,http_store_1.httpCaptureMode)();if(r==="off")return;(0,http_store_1.primeHttpStore)();const t=http.Server.prototype,s=t.emit;originalEmit=s,t.emit=function(e,...n){if(e==="request")try{watch(n[0],n[1],r)}catch{}return s.call(this,e,...n)}}u(tapIngress,"tapIngress"),o(tapIngress,"tapIngress");function resetIngressTapForTests(){originalEmit&&(http.Server.prototype.emit=originalEmit),originalEmit=void 0}u(resetIngressTapForTests,"resetIngressTapForTests"),o(resetIngressTapForTests,"resetIngressTapForTests");const one=o(r=>r===void 0?void 0:Array.isArray(r)?r.join(", "):String(r),"one"),pairs=o(r=>Object.entries(r).flatMap(([t,s])=>s===void 0?[]:[[t,one(s)]]),"pairs");class Tee{static{u(this,"Tee")}static{o(this,"Tee")}constructor(t=!0){this.keep=t,this.chunks=[],this.read=0,this.size=0,this.tail=Buffer.alloc(0)}take(t,s){if(t==null||typeof t=="function")return;if(!this.keep&&typeof t=="string"){this.size+=Buffer.byteLength(t,typeof s=="string"?s:"utf8"),this.tail=Buffer.alloc(0);return}const e=Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t):typeof t=="string"?Buffer.from(t,typeof s=="string"?s:"utf8"):void 0;e&&(this.size+=e.length,this.tail=Buffer.from(e.length>=4?e.subarray(e.length-4):Buffer.concat([this.tail,e]).subarray(-4)),this.keep&&this.read<MAX_READ&&(this.chunks.push(e),this.read+=e.length))}bytes(){return Buffer.concat(this.chunks)}}function watch(r,t,s){if(!r||!t||r[exports.EXCHANGE_ID])return;const e=r.url??"/",n=e.indexOf("?"),m=n<0?e:e.slice(0,n);if((0,headless_flow_1.isProbePath)(m))return;const g=(0,http_store_1.newExchangeId)();r[exports.EXCHANGE_ID]=g;const _=Date.now(),y=s==="bodies"&&!(0,http_store_1.proofBoundHeaders)(r.headers),w=new Tee,h=new Tee(y);if(y){const l=r.emit;r.emit=function(d,...i){return d==="data"&&w.take(i[0]),l.call(this,d,...i)}}{const l=t.write,d=t.end;t.write=function(i,...c){return h.take(i,c[0]),l.call(this,i,...c)},t.end=function(i,...c){return h.take(i,c[0]),d.call(this,i,...c)}}let p=!1;const a=o(()=>{if(!p){p=!0;try{(0,lens_time_1.lensTimed)(()=>(0,http_store_1.queueHttpExchange)(exchangeOf(g,r,t,{url:e,q:n,path:m,startedAt:_,bodies:y,sent:w,answered:h})))}catch{}}},"finish");t.once("finish",a),t.once("close",a)}u(watch,"watch"),o(watch,"watch");function unpacked(r,t){try{if(r==="gzip"||r==="x-gzip")return zlib.gunzipSync(t,{maxOutputLength:MAX_READ});if(r==="br")return zlib.brotliDecompressSync(t,{maxOutputLength:MAX_READ});if(r==="deflate")return zlib.inflateSync(t,{maxOutputLength:MAX_READ})}catch{return}}u(unpacked,"unpacked"),o(unpacked,"unpacked");function exchangeOf(r,t,s,e){const n=[],m=[],g=[],_=(0,http_store_1.redactHeaders)(pairs(t.headers));n.push(..._.redacted);const y=(0,http_store_1.redactHeaders)(pairs(s.getHeaders()));n.push(...y.redacted);const w=e.bodies&&e.q>=0?(0,http_store_1.redactQuery)(e.url.slice(e.q)):[];let h;e.bodies&&e.sent.size&&(h=(0,http_store_1.keepBody)(one(t.headers["content-type"])??"",e.sent.bytes(),e.sent.size,m));let p;const a=(one(s.getHeader("content-encoding"))??"").trim().toLowerCase();let l=!a||a==="identity"?e.answered.size:(a==="gzip"||a==="x-gzip")&&e.answered.size>=18&&e.answered.tail.length===4?e.answered.tail.readUInt32LE(0):void 0;if(e.bodies&&e.answered.size){const f=one(s.getHeader("content-type"))??"";if(!a||a==="identity")p=(0,http_store_1.keepBody)(f,e.answered.bytes(),e.answered.size,g);else{const b=e.answered.size<=MAX_READ?unpacked(a,e.answered.bytes()):void 0;b&&(l=b.length),p=b?(0,http_store_1.keepBody)(f,b,b.length,g):{contentType:f.split(";")[0].trim().toLowerCase(),size:e.answered.size,kept:0,truncated:!1,omitted:"encoded"}}}const d=one(t.headers.host)??"localhost",i=e.path.length>MAX_PATH_CHARS?`${e.path.slice(0,MAX_PATH_CHARS)}\u2026`:e.path,c=one(t.headers["x-lensmcp-flow-id"]),x=one(t.headers[http_exchange_1.LENS_REQUEST_ID_HEADER])||one(t.headers["x-request-id"]),E=!s.writableFinished;return{schemaVersion:1,id:r,capturedAt:Date.now(),side:"ingress",service:emit_1.PROJECT,...c?{flowId:c}:{},...x?{requestId:x}:{},method:(t.method??"GET").toUpperCase(),url:`http://${d}${i}`,host:d.split(":")[0]??d,path:i,status:s.statusCode,...s.statusMessage?{statusText:s.statusMessage}:{},...E?{error:"the client went away before the answer ended"}:{},startedAt:e.startedAt,durationMs:Date.now()-e.startedAt,capture:e.bodies?"bodies":"headers",request:{headers:_.headers,...w.length?{query:w}:{},...h?{body:h}:{}},response:{headers:y.headers,bytes:{wire:e.answered.size,...l!==void 0?{decoded:l}:{}},...p?{body:p}:{}},redacted:{headers:[...new Set(n)],bodyFields:[...m.map(f=>`request.${f}`),...g.map(f=>`response.${f}`)]}}}u(exchangeOf,"exchangeOf"),o(exchangeOf,"exchangeOf");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/node-instrumentation",
3
- "version": "1.25.71",
3
+ "version": "1.25.73",
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.71",
19
- "@lensmcp/nest-instrumentation": "1.25.71",
20
- "@lensmcp/protocol-types": "1.25.71",
18
+ "@lensmcp/core": "1.25.73",
19
+ "@lensmcp/nest-instrumentation": "1.25.73",
20
+ "@lensmcp/protocol-types": "1.25.73",
21
21
  "tslib": "^2.3.0"
22
22
  },
23
23
  "optionalDependencies": {