@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.
- package/lib/tap-ingress.js +1 -1
- package/package.json +4 -4
package/lib/tap-ingress.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var
|
|
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.
|
|
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.
|
|
19
|
-
"@lensmcp/nest-instrumentation": "1.25.
|
|
20
|
-
"@lensmcp/protocol-types": "1.25.
|
|
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": {
|