@lensmcp/node-instrumentation 1.16.1 → 1.16.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/lib/emit.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/lib/emit.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AAC5C,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3E,mFAAmF;AACnF,eAAO,MAAM,OAAO,EAAE,MACkD,CAAC;AAEzE,yEAAyE;AACzE,eAAO,MAAM,UAAU,EAAE,MACsD,CAAC;AAKhF,8EAA8E;AAC9E,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,kFAAkF;AAClF,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,OAAO,GAChB,IAAI,CAiCN;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CA2BlE"}
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/lib/emit.ts"],"names":[],"mappings":"AAiDA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AAC5C,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3E,mFAAmF;AACnF,eAAO,MAAM,OAAO,EAAE,MACkD,CAAC;AAEzE,yEAAyE;AACzE,eAAO,MAAM,UAAU,EAAE,MACsD,CAAC;AAKhF,8EAA8E;AAC9E,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,kFAAkF;AAClF,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,OAAO,GAChB,IAAI,CAiCN;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CA2BlE"}
package/lib/emit.js CHANGED
@@ -23,6 +23,36 @@ const node_path_1 = require("node:path");
23
23
  // Pristine references, frozen at load — immune to the fs tap's later patching.
24
24
  const appendFileSync = nodeFs.appendFileSync;
25
25
  const mkdirSync = nodeFs.mkdirSync;
26
+ const statSync = nodeFs.statSync;
27
+ const renameSync = nodeFs.renameSync;
28
+ /** Cap the events.jsonl so a long-running dev session can't grow it to gigabytes (it hit 9 GB in the
29
+ * wild). Override with `LENSMCP_EVENT_MAX_BYTES` (default 256 MB). 0/invalid ⇒ the default. */
30
+ const MAX_EVENT_BYTES = (() => {
31
+ const n = Number(process.env['LENSMCP_EVENT_MAX_BYTES']);
32
+ return Number.isFinite(n) && n > 0 ? n : 256 * 1024 * 1024;
33
+ })();
34
+ const ROTATE_CHECK_BYTES = 1024 * 1024; // statSync at most ~once per MB appended (cheap amortized)
35
+ let bytesSinceCheck = 0;
36
+ /**
37
+ * Rotate the bus when it exceeds {@link MAX_EVENT_BYTES}: rename `events.jsonl` → `events.jsonl.1`
38
+ * (keeping ONE previous generation; the next append recreates a fresh file). Throttled by a byte
39
+ * counter so we `statSync` at most ~once per MB, not per event. Best-effort + fs-tap-safe (pristine
40
+ * refs, called while `writing` is already true). Many processes append to the same path — `renameSync`
41
+ * is atomic, so a concurrent rotate that loses the race just throws ENOENT and no-ops.
42
+ */
43
+ function rotateIfLarge(lineBytes) {
44
+ bytesSinceCheck += lineBytes;
45
+ if (bytesSinceCheck < ROTATE_CHECK_BYTES)
46
+ return;
47
+ bytesSinceCheck = 0;
48
+ try {
49
+ if (statSync(exports.EVENT_FILE).size > MAX_EVENT_BYTES)
50
+ renameSync(exports.EVENT_FILE, `${exports.EVENT_FILE}.1`);
51
+ }
52
+ catch {
53
+ /* missing / already rotated by another writer — fine */
54
+ }
55
+ }
26
56
  /** Service identity stamped on every event (set by the cluster serve executor). */
27
57
  exports.PROJECT = process.env['LENSMCP_PROJECT'] || process.env['SERVICE_NAME'] || 'app';
28
58
  /** The file bus — same default the cluster gateway and dashboard use. */
@@ -40,7 +70,7 @@ function lensEmit(source, severity, title, raw, fingerprint, flowCtx) {
40
70
  mkdirSync((0, node_path_1.dirname)(exports.EVENT_FILE), { recursive: true });
41
71
  dirReady = true;
42
72
  }
43
- appendFileSync(exports.EVENT_FILE, JSON.stringify({
73
+ const line = JSON.stringify({
44
74
  id: Date.now().toString(36) + Math.random().toString(36).slice(2, 10),
45
75
  sessionId: 'pending',
46
76
  timestamp: Date.now(),
@@ -57,7 +87,9 @@ function lensEmit(source, severity, title, raw, fingerprint, flowCtx) {
57
87
  fingerprint: fingerprint ?? `${source}:${String(raw['name'] ?? source)}`,
58
88
  title,
59
89
  raw: { project: exports.PROJECT, ...raw },
60
- }) + '\n');
90
+ }) + '\n';
91
+ rotateIfLarge(line.length);
92
+ appendFileSync(exports.EVENT_FILE, line);
61
93
  }
62
94
  catch {
63
95
  /* lens offline — never break the host */
@@ -79,7 +111,7 @@ function lensLog(severity, title) {
79
111
  mkdirSync((0, node_path_1.dirname)(exports.EVENT_FILE), { recursive: true });
80
112
  dirReady = true;
81
113
  }
82
- appendFileSync(exports.EVENT_FILE, JSON.stringify({
114
+ const line = JSON.stringify({
83
115
  id: Date.now().toString(36) + Math.random().toString(36).slice(2, 10),
84
116
  sessionId: 'pending',
85
117
  timestamp: Date.now(),
@@ -90,7 +122,9 @@ function lensLog(severity, title) {
90
122
  fingerprint: `log:${exports.PROJECT}`,
91
123
  title,
92
124
  raw: { project: exports.PROJECT, kind: 'log' },
93
- }) + '\n');
125
+ }) + '\n';
126
+ rotateIfLarge(line.length);
127
+ appendFileSync(exports.EVENT_FILE, line);
94
128
  }
95
129
  catch {
96
130
  /* lens offline — never break the host */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/node-instrumentation",
3
- "version": "1.16.1",
3
+ "version": "1.16.3",
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.16.1",
18
+ "@lensmcp/nest-instrumentation": "1.16.3",
19
19
  "tslib": "^2.3.0"
20
20
  },
21
21
  "optionalDependencies": {