@lensmcp/node-instrumentation 1.25.6 → 1.25.7
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/sql-accounting.d.ts +5 -0
- package/lib/sql-accounting.js +1 -1
- package/package.json +4 -4
package/lib/sql-accounting.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export declare const SQL_ACCOUNT_SETTLE_MS = 1000;
|
|
|
20
20
|
export interface SqlAccount {
|
|
21
21
|
/** Distinct per account: two requests that reuse one `x-request-id` keep two accounts. */
|
|
22
22
|
accountId: string;
|
|
23
|
+
/**
|
|
24
|
+
* The request's own id where its context has one (nest-instrumentation's interceptor: `runId`, also on its
|
|
25
|
+
* `server-request`) — how the lens finds the run an account belongs to when calls share a request id.
|
|
26
|
+
*/
|
|
27
|
+
runId?: string;
|
|
23
28
|
ctx: FlowCtx;
|
|
24
29
|
/** Records written so far; a later one carries the cumulative totals and supersedes. */
|
|
25
30
|
seq: number;
|
package/lib/sql-accounting.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var n=(t,e)=>u(t,"name",{value:e,configurable:!0});var l=Object.defineProperty,s=n((t,e)=>l(t,"name",{value:e,configurable:!0}),"s");Object.defineProperty(exports,"__esModule",{value:!0}),exports.SQL_ACCOUNT_SETTLE_MS=exports.SQL_ACCOUNT_KIND=void 0,exports.beginSqlStatement=beginSqlStatement,exports.endSqlStatement=endSqlStatement,exports.abandonSqlStatement=abandonSqlStatement;const flood_guard_1=require("./flood-guard"),emit_1=require("./emit"),flow_context_1=require("./flow-context");exports.SQL_ACCOUNT_KIND="db-request-account",exports.SQL_ACCOUNT_SETTLE_MS=1e3;const accountGuard=(0,flood_guard_1.createEventFloodGuard)({burst:120,perSec:20}),accounts=new WeakMap;let accountSeq=0;function newAccountId(){return accountSeq=(accountSeq+1)%16777215,`${Date.now().toString(36)}${accountSeq.toString(36)}${Math.random().toString(36).slice(2,6)}`}n(newAccountId,"newAccountId"),s(newAccountId,"newAccountId");function beginSqlStatement(t,e,d){if(!t||!e?.flowId||!e.requestId)return;let r=accounts.get(t);if(!r){const o=t.runId;r={accountId:newAccountId(),...typeof o=="string"&&o?{runId:o}:{},ctx:e,seq:0,inFlight:0,statements:0,failed:0,workMs:0,recorded:0,recordedWorkMs:0,suppressed:0,unwritten:0,firstStartedAt:d,lastEndedAt:d,awaitsEnd:!1,ended:!1},accounts.set(t,r);const i=(0,flow_context_1.contextEndOf)(t);if(i&&!i.ended){const a=r;a.awaitsEnd=!0,i.onEnd(()=>endSqlAccount(a))}}return r.inFlight+=1,r.timer&&(clearTimeout(r.timer),r.timer=void 0),r}n(beginSqlStatement,"beginSqlStatement"),s(beginSqlStatement,"beginSqlStatement");function endSqlStatement(t,e){t&&(t.inFlight=Math.max(0,t.inFlight-1),t.statements+=1,t.workMs+=e.durationMs,e.failed&&(t.failed+=1),e.emitted==="written"?(t.recorded+=1,t.recordedWorkMs+=e.durationMs):e.emitted==="suppressed"?t.suppressed+=1:t.unwritten+=1,t.lastEndedAt=Math.max(t.lastEndedAt,Date.now()),writeWhenDue(t))}n(endSqlStatement,"endSqlStatement"),s(endSqlStatement,"endSqlStatement");function abandonSqlStatement(t){t&&(t.inFlight=Math.max(0,t.inFlight-1),writeWhenDue(t))}n(abandonSqlStatement,"abandonSqlStatement"),s(abandonSqlStatement,"abandonSqlStatement");function endSqlAccount(t){t.ended=!0,writeWhenDue(t)}n(endSqlAccount,"endSqlAccount"),s(endSqlAccount,"endSqlAccount");function writeWhenDue(t){if(!(t.inFlight>0||t.statements===0)&&!(t.awaitsEnd&&!t.ended)){if(t.ended&&t.seq===0){writeAccount(t);return}settleLater(t)}}n(writeWhenDue,"writeWhenDue"),s(writeWhenDue,"writeWhenDue");function settleLater(t){t.timer&&clearTimeout(t.timer);const e=setTimeout(()=>writeAccount(t),exports.SQL_ACCOUNT_SETTLE_MS);e.unref?.(),t.timer=e}n(settleLater,"settleLater"),s(settleLater,"settleLater");function writeAccount(t){t.timer&&clearTimeout(t.timer),t.timer=void 0,t.seq+=1;const e=t.suppressed+t.unwritten,d=t.ended?"end":"settled";(0,emit_1.lensEmitOutcome)("lens","info",`SQL account: ${t.statements} statement${t.statements===1?"":"s"}`+(e>0?`, ${e} not on the bus`:", all on the bus"),{kind:exports.SQL_ACCOUNT_KIND,accountId:t.accountId,...t.runId?{runId:t.runId}:{},seq:t.seq,basis:d,statements:t.statements,failed:t.failed,workMs:t.workMs,recorded:t.recorded,recordedWorkMs:t.recordedWorkMs,suppressed:t.suppressed,unwritten:t.unwritten,firstStartedAt:t.firstStartedAt,lastEndedAt:t.lastEndedAt},`lens:sql-account:${emit_1.PROJECT}`,t.ctx,"db",accountGuard)}n(writeAccount,"writeAccount"),s(writeAccount,"writeAccount");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/node-instrumentation",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.7",
|
|
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.7",
|
|
19
|
+
"@lensmcp/nest-instrumentation": "1.25.7",
|
|
20
|
+
"@lensmcp/protocol-types": "1.25.7",
|
|
21
21
|
"tslib": "^2.3.0"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|