@lensmcp/node-instrumentation 1.18.7 → 1.18.8
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-pg.js +1 -1
- package/package.json +2 -2
package/lib/tap-pg.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var
|
|
1
|
+
"use strict";var x=Object.defineProperty;var c=(t,e)=>x(t,"name",{value:e,configurable:!0});var E=Object.defineProperty,n=c((t,e)=>E(t,"name",{value:e,configurable:!0}),"n");Object.defineProperty(exports,"__esModule",{value:!0}),exports.pgTap=pgTap;const emit_1=require("./emit"),flow_context_1=require("./flow-context"),SKIP_OPS=new Set(["BEGIN","COMMIT","ROLLBACK","SET","SHOW","DEALLOCATE","DISCARD"]);function parseSql(t){const e=(t.match(/^\s*(\w+)/)?.[1]??"query").toUpperCase(),r=t.match(/\b(?:from|into|update|join|table(?:\s+if\s+not\s+exists)?)\s+"?([\w$.]+)"?/i)?.[1]?.split(".").pop();return{op:e,...r?{table:r}:{}}}c(parseSql,"parseSql"),n(parseSql,"parseSql");const oneLine=n(t=>t.replace(/\s+/g," ").trim(),"oneLine"),clip=n((t,e)=>t.length>e?t.slice(0,e-1)+"\u2026":t,"clip");function paramPreview(t){if(!(!Array.isArray(t)||t.length===0))return t.slice(0,10).map(e=>{if(e==null)return String(e);const r=typeof e=="string"?e:(()=>{try{return JSON.stringify(e)}catch{return String(e)}})();return clip(r,80)})}c(paramPreview,"paramPreview"),n(paramPreview,"paramPreview");const rowsOf=n(t=>t?.rowCount??t?.rows?.length??0,"rowsOf");function resultPreview(t){const e=t?.rows;if(!(!Array.isArray(e)||e.length===0))try{return clip(JSON.stringify(e.slice(0,2)),240)}catch{return}}c(resultPreview,"resultPreview"),n(resultPreview,"resultPreview");function pgTap(t){const e=t?.Client?.prototype,r=e?.query;if(!e||typeof r!="function")return!1;if(r.__lensmcp)return!0;const C=n(function(a,i,y){const l=a,m=typeof l=="string"?l:l?.text;if(!m||l&&typeof l=="object"&&typeof l.submit=="function")return r.call(this,a,i,y);const{op:q,table:s}=parseSql(m);if(SKIP_OPS.has(q))return r.call(this,a,i,y);const p=q.toLowerCase(),_=`db:${p}:${s??"query"}`,b=Date.now(),S=(0,flow_context_1.flowContext)(),g=(0,flow_context_1.liveFlowContext)();g&&(g.dbCallCount=(g.dbCallCount??0)+1);const v=clip(oneLine(m),500),d=paramPreview(Array.isArray(i)?i:a?.values),h=n((o,f)=>{const u=Date.now()-b;if(o)(0,emit_1.lensEmit)("db","error",`${p}${s?" "+s:""} failed (${u}ms)`,{name:"postgres",kind:"db-query",op:p,...s?{table:s}:{},query:v,...d?{params:d}:{},startedAt:b,error:String(o?.message??o),durationMs:u},`db:error:${p}:${s??"query"}`,S);else{const $=rowsOf(f),O=resultPreview(f);(0,emit_1.lensEmit)("db","info",`${p} ${s??"query"} (${$} rows, ${u}ms)`,{name:"postgres",kind:"db-query",op:p,...s?{table:s}:{},query:v,...d?{params:d}:{},...O?{result:O}:{},startedAt:b,rows:$,durationMs:u},_,S)}},"done"),A=typeof y=="function"?y:typeof i=="function"?i:void 0;if(A){const o=n((f,u)=>{try{h(f,u)}catch{}A(f,u)},"wrappedCb");return typeof i=="function"?r.call(this,a,o):r.call(this,a,i,o)}const w=r.call(this,a,i);return w&&typeof w.then=="function"&&w.then(o=>h(void 0,o),o=>h(o,void 0)),w},"wrapped");return C.__lensmcp=!0,e.query=C,!0}c(pgTap,"pgTap"),n(pgTap,"pgTap");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/node-instrumentation",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.8",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lensmcp/nest-instrumentation": "1.18.
|
|
18
|
+
"@lensmcp/nest-instrumentation": "1.18.8",
|
|
19
19
|
"tslib": "^2.3.0"
|
|
20
20
|
},
|
|
21
21
|
"optionalDependencies": {
|