@bymax-one/nest-telemetry 1.0.10 → 1.0.11

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/CHANGELOG.md CHANGED
@@ -8,6 +8,31 @@ The `release.yml` workflow extracts the section matching the pushed `vX.Y.Z` tag
8
8
  as the GitHub Release body, so each released version needs a matching `## [X.Y.Z]`
9
9
  heading here.
10
10
 
11
+ ## [1.0.11] - 2026-11-21
12
+
13
+ ### Fixed
14
+
15
+ - **`ignorePaths` copies its patterns by index and refuses what is not a list of regular expressions.** It copied
16
+ with `patterns.map`, so an array subclass whose `map` returns nothing ignored no path, and an object with a
17
+ `source` and `flags` was accepted as an expression. It now reads the length once (at most 1000), each index once
18
+ and each entry through `util.types.isRegExp`, and throws `BYMAX_TELEMETRY_OPTION_INVALID` for anything else, an expression whose own `flags` cannot be built, or a list that throws while it is read, included (the error it raised is the `cause`).
19
+ - **An option that must be an object refuses a `Map`, a `Set`, a `Date`, a `RegExp`, a `Promise` and a boxed
20
+ primitive.** They were accepted and read as an empty object; they are refused as the wrong kind, by the kind
21
+ Node reports and not by the prototype, so a class instance and a `Proxy` of a plain object are still read.
22
+
23
+ ### Documentation
24
+
25
+ - **The README says that a `__proto__` key is refused as the name of an instrumentation too**, and that an entry
26
+ or a setting that is `null` or `undefined` is dropped and not refused.
27
+
28
+ ### Apply to a derived backend
29
+
30
+ A `Map`, `Set`, `Date`, `RegExp`, `Promise` or boxed primitive passed for `unsafe`, `instrumentations`,
31
+ `instrumentations.overrides` or `env` now fails at start with `BYMAX_TELEMETRY_OPTION_INVALID`. `ignorePaths` throws
32
+ the same code when it is called, not at start, for an argument that is not an array of at most 1000 regular expressions, a list that reads
33
+ empty while it holds index keys, a pattern whose flags cannot be built, and a list whose own read throws (the
34
+ error it raised is the `cause`). Pass a plain object, and a real array of `RegExp`. Nothing else changes.
35
+
11
36
  ## [1.0.10] - 2026-11-21
12
37
 
13
38
  ### Fixed
@@ -444,6 +469,7 @@ First release.
444
469
  - Verification from the packed tarball: real `node --import` processes in a CommonJS and a native-ESM
445
470
  application, with planted secrets absent from the exported body and negative controls.
446
471
 
472
+ [1.0.11]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.11
447
473
  [1.0.10]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.10
448
474
  [1.0.9]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.9
449
475
  [1.0.8]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.8
package/README.md CHANGED
@@ -225,7 +225,7 @@ The start emits these warnings:
225
225
  | `BYMAX_TELEMETRY_WINSTON_TRANSPORT_MISSING` | Log forwarding is on and winston is installed, but `@opentelemetry/winston-transport` cannot be resolved from the winston instrumentation, so winston records are not forwarded. Install it as a direct dependency of the application, or ignore the warning when your application never creates a winston logger or `OTEL_LOGS_EXPORTER` is `none`. |
226
226
  | `BYMAX_TELEMETRY_BSP_VALUE_IGNORED` | An `OTEL_BSP_SCHEDULE_DELAY` or `OTEL_BSP_EXPORT_TIMEOUT` above 2147483647 ms was ignored, because a timer cannot hold it and Node would clamp it to 1 ms. The default applies. |
227
227
 
228
- An option of the wrong kind is refused before anything starts: `startTelemetry` rejects with an error whose `code` is `BYMAX_TELEMETRY_OPTION_INVALID` and whose `option` names it, such as `instrumentations.sendLogs`. The message says what the option must be and never repeats the value. A boolean option (`enabled`, `instrumentations.fs`, `instrumentations.sendLogs` and each `unsafe` flag) must be a boolean, so the string `'false'` is refused and not read as true; `serviceName` and `serviceVersion` must be strings, `ignoreIncomingRequest` a function, and `unsafe`, `instrumentations`, `instrumentations.overrides` and `env` objects. `extraRedactedQueryParams` must be an array of at most 1000 strings, and `instrumentations.overrides` an object of at most 1000 entries that are each an object. Inside an override, `enabled` and `disableLogSending` must be booleans, `redactedQueryParams` an array of at most 1000 strings, every setting whose name ends in `Hook` a function, an entry holds at most 1000 settings, and a key named `__proto__` is refused; any other setting, a function that is not a hook included, is passed on as the host wrote it. The error names the setting as `instrumentations.overrides[].enabled` and never the instrumentation or the value. `null` and `undefined` mean the option was not given. `shutdownTimeoutMs` is not refused: a value that is not a number in range means the default. Each option of a call is read once, so what a warning says and what the call does come from the same read.
228
+ An option of the wrong kind is refused before anything starts: `startTelemetry` rejects with an error whose `code` is `BYMAX_TELEMETRY_OPTION_INVALID` and whose `option` names it, such as `instrumentations.sendLogs`. The message says what the option must be and never repeats the value. A boolean option (`enabled`, `instrumentations.fs`, `instrumentations.sendLogs` and each `unsafe` flag) must be a boolean, so the string `'false'` is refused and not read as true; `serviceName` and `serviceVersion` must be strings, `ignoreIncomingRequest` a function, and `unsafe`, `instrumentations`, `instrumentations.overrides` and `env` objects (a `Map`, `Set`, `Date`, `RegExp`, `Promise` or boxed primitive is refused as the wrong kind; an object with a prototype of its own, such as a class instance, is read as written). `extraRedactedQueryParams` must be an array of at most 1000 strings, and `instrumentations.overrides` an object of at most 1000 entries that are each an object. Inside an override, `enabled` and `disableLogSending` must be booleans, `redactedQueryParams` an array of at most 1000 strings, every setting whose name ends in `Hook` a function, an entry holds at most 1000 settings, and a key named `__proto__` is refused, in an entry and as the name of an instrumentation; an entry or a setting that is `null` or `undefined` is dropped and not refused; any other setting, a function that is not a hook included, is passed on as the host wrote it. The error names the setting as `instrumentations.overrides[].enabled` and never the instrumentation or the value. `null` and `undefined` mean the option was not given. `shutdownTimeoutMs` is not refused: a value that is not a number in range means the default. Each option of a call is read once, so what a warning says and what the call does come from the same read.
229
229
 
230
230
  The programmatic `startTelemetry` keeps its rejection when the SDK cannot start, for callers that want it. It rejects with the error that was thrown, as it was thrown, and only a refused option carries a code, so an option whose getter throws (or a proxy that fails an operation) ends the start with that error and starts no new SDK, so a first start leaves no handle either. A later call that finds an SDK already running can also reject, while it reads the options of the call; the running SDK and its handle are not touched.
231
231
 
@@ -448,7 +448,7 @@ pnpm check:runtime # packed-tarball consumer proofs
448
448
  | `InstrumentationOptions` | type | `fs`, `sendLogs` and `overrides` |
449
449
  | `IncomingRequestTarget` | type | What an incoming-request predicate sees: the request `url` |
450
450
 
451
- `ignorePaths` copies each pattern without its `g` and `y` flags, which would keep state between calls. Anchor the patterns at both ends, with no nested quantifiers: an unanchored one also matches routes that merely contain the word, and `/^\/(a+)+$/` took 2.5 s and 5.5 s in two runs on a 28-character path (as of 2026-11-13, not a test; the tests pin the refusal of a path over 2,048 characters), and the time grows exponentially with the length.
451
+ `ignorePaths` refuses anything that is not an array of at most 1000 regular expressions, copies the array by index and each pattern without its `g` and `y` flags, which would keep state between calls. Anchor the patterns at both ends, with no nested quantifiers: an unanchored one also matches routes that merely contain the word, and `/^\/(a+)+$/` took 2.5 s and 5.5 s in two runs on a 28-character path (as of 2026-11-13, not a test; the tests pin the refusal of a path over 2,048 characters), and the time grows exponentially with the length.
452
452
 
453
453
  ### Register: `@bymax-one/nest-telemetry/register`
454
454
 
@@ -1,4 +1,5 @@
1
1
  import { register, createRequire } from 'module';
2
+ import { types } from 'util';
2
3
  import { join } from 'path';
3
4
 
4
5
  // src/register/boot.ts
@@ -94,16 +95,19 @@ function describeFailure(error) {
94
95
  return code;
95
96
  }
96
97
  }
97
-
98
- // src/sdk/option-kinds.ts
98
+ var isIndex = (key) => String(Number(key) >>> 0) === key && key !== "4294967295";
99
99
  var MAX_OPTION_ENTRIES = 1e3;
100
100
  var TelemetryOptionError = class extends Error {
101
101
  /**
102
102
  * @param option - The option that was refused.
103
103
  * @param expected - What the option must be.
104
+ * @param cause - The error of the host's own value that made the option unusable.
104
105
  */
105
- constructor(option, expected) {
106
- super(`The ${option} option must be ${expected}, so the start was refused.`);
106
+ constructor(option, expected, cause) {
107
+ super(
108
+ `The ${option} option must be ${expected}, so the start was refused.`,
109
+ cause === void 0 ? void 0 : { cause }
110
+ );
107
111
  /** The stable code of this error. */
108
112
  this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
109
113
  this.name = "TelemetryOptionError";
@@ -130,29 +134,47 @@ function requireFunction(option, value) {
130
134
  }
131
135
  function requireObject(option, value) {
132
136
  if (value === void 0 || value === null) return void 0;
133
- if (typeof value !== "object" || Array.isArray(value)) {
137
+ if (typeof value !== "object" || Array.isArray(value) || isOtherKind(value)) {
134
138
  throw new TelemetryOptionError(option, "an object");
135
139
  }
136
140
  return value;
137
141
  }
138
- function settleStringList(option, value) {
142
+ function isOtherKind(value) {
143
+ return types.isBoxedPrimitive(value) || types.isMap(value) || types.isSet(value) || types.isDate(value) || types.isRegExp(value) || types.isPromise(value);
144
+ }
145
+ function copyByIndex(option, value, noun, take, guarded) {
139
146
  if (!isGiven(value)) return void 0;
140
- if (!Array.isArray(value)) throw new TelemetryOptionError(option, "an array of strings");
141
- const length = value.length;
147
+ const expected = `an array of ${noun}`;
148
+ const host = (read) => {
149
+ return read();
150
+ };
151
+ if (!host(() => Array.isArray(value))) throw new TelemetryOptionError(option, expected);
152
+ const list = value;
153
+ const length = host(() => list.length);
142
154
  if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
143
- throw new TelemetryOptionError(option, "an array of strings");
155
+ throw new TelemetryOptionError(option, expected);
144
156
  }
145
157
  if (length > MAX_OPTION_ENTRIES) {
146
- throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} strings`);
158
+ throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} ${noun}`);
159
+ }
160
+ if (length === 0 && host(() => Object.keys(list).some(isIndex))) {
161
+ throw new TelemetryOptionError(option, expected);
147
162
  }
148
163
  const copy = [];
149
164
  for (let index = 0; index < length; index++) {
150
- const item = value[index];
151
- if (typeof item !== "string") throw new TelemetryOptionError(option, "an array of strings");
152
- copy.push(item);
165
+ const taken = take(host(() => list[index]));
166
+ if (taken === void 0) throw new TelemetryOptionError(option, expected);
167
+ copy.push(taken);
153
168
  }
154
169
  return copy;
155
170
  }
171
+ function settleStringList(option, value) {
172
+ return copyByIndex(
173
+ option,
174
+ value,
175
+ "strings",
176
+ (entry) => typeof entry === "string" ? entry : void 0);
177
+ }
156
178
  var OVERRIDE_PATH = "instrumentations.overrides[]";
157
179
  function refuseProtoKey(key) {
158
180
  if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var util = require('util');
3
4
  var module$1 = require('module');
4
5
  var path = require('path');
5
6
 
@@ -57,11 +58,163 @@ function createUrlQueryRedactor() {
57
58
  function serializeRedisCommandName(commandName) {
58
59
  return commandName;
59
60
  }
61
+ var isIndex = (key) => String(Number(key) >>> 0) === key && key !== "4294967295";
62
+ var MAX_OPTION_ENTRIES = 1e3;
63
+ var TelemetryOptionError = class extends Error {
64
+ /**
65
+ * @param option - The option that was refused.
66
+ * @param expected - What the option must be.
67
+ * @param cause - The error of the host's own value that made the option unusable.
68
+ */
69
+ constructor(option, expected, cause) {
70
+ super(
71
+ `The ${option} option must be ${expected}, so the start was refused.`,
72
+ cause === void 0 ? void 0 : { cause }
73
+ );
74
+ /** The stable code of this error. */
75
+ this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
76
+ this.name = "TelemetryOptionError";
77
+ this.option = option;
78
+ }
79
+ };
80
+ function isGiven(value) {
81
+ return value !== void 0 && value !== null;
82
+ }
83
+ function requireBoolean(option, value) {
84
+ if (!isGiven(value)) return void 0;
85
+ if (typeof value !== "boolean") throw new TelemetryOptionError(option, "a boolean");
86
+ return value;
87
+ }
88
+ function requireString(option, value) {
89
+ if (!isGiven(value)) return void 0;
90
+ if (typeof value !== "string") throw new TelemetryOptionError(option, "a string");
91
+ return value;
92
+ }
93
+ function requireFunction(option, value) {
94
+ if (!isGiven(value)) return void 0;
95
+ if (typeof value !== "function") throw new TelemetryOptionError(option, "a function");
96
+ return value;
97
+ }
98
+ function requireObject(option, value) {
99
+ if (value === void 0 || value === null) return void 0;
100
+ if (typeof value !== "object" || Array.isArray(value) || isOtherKind(value)) {
101
+ throw new TelemetryOptionError(option, "an object");
102
+ }
103
+ return value;
104
+ }
105
+ function isOtherKind(value) {
106
+ return util.types.isBoxedPrimitive(value) || util.types.isMap(value) || util.types.isSet(value) || util.types.isDate(value) || util.types.isRegExp(value) || util.types.isPromise(value);
107
+ }
108
+ function copyByIndex(option, value, noun, take, guarded) {
109
+ if (!isGiven(value)) return void 0;
110
+ const expected = `an array of ${noun}`;
111
+ const host = (read) => {
112
+ if (!guarded) return read();
113
+ try {
114
+ return read();
115
+ } catch (cause) {
116
+ throw new TelemetryOptionError(option, expected, cause);
117
+ }
118
+ };
119
+ if (!host(() => Array.isArray(value))) throw new TelemetryOptionError(option, expected);
120
+ const list = value;
121
+ const length = host(() => list.length);
122
+ if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
123
+ throw new TelemetryOptionError(option, expected);
124
+ }
125
+ if (length > MAX_OPTION_ENTRIES) {
126
+ throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} ${noun}`);
127
+ }
128
+ if (length === 0 && host(() => Object.keys(list).some(isIndex))) {
129
+ throw new TelemetryOptionError(option, expected);
130
+ }
131
+ const copy = [];
132
+ for (let index = 0; index < length; index++) {
133
+ const taken = take(host(() => list[index]));
134
+ if (taken === void 0) throw new TelemetryOptionError(option, expected);
135
+ copy.push(taken);
136
+ }
137
+ return copy;
138
+ }
139
+ function settleStringList(option, value) {
140
+ return copyByIndex(
141
+ option,
142
+ value,
143
+ "strings",
144
+ (entry) => typeof entry === "string" ? entry : void 0,
145
+ false
146
+ );
147
+ }
148
+ function settleRegExpList(option, value) {
149
+ return copyByIndex(
150
+ option,
151
+ value,
152
+ "regular expressions",
153
+ (entry) => {
154
+ if (!util.types.isRegExp(entry)) return void 0;
155
+ try {
156
+ const { source, flags } = entry;
157
+ return new RegExp(source, flags);
158
+ } catch (cause) {
159
+ throw new TelemetryOptionError(option, "an array of regular expressions", cause);
160
+ }
161
+ },
162
+ true
163
+ );
164
+ }
165
+ var OVERRIDE_PATH = "instrumentations.overrides[]";
166
+ function refuseProtoKey(key) {
167
+ if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
168
+ }
169
+ function settleOverrideEntry(entry) {
170
+ const settings = Object.entries(entry);
171
+ if (settings.length > MAX_OPTION_ENTRIES) {
172
+ throw new TelemetryOptionError(
173
+ OVERRIDE_PATH,
174
+ `an object of at most ${MAX_OPTION_ENTRIES} settings`
175
+ );
176
+ }
177
+ const copy = {};
178
+ for (const [key, setting] of settings) {
179
+ refuseProtoKey(key);
180
+ let settled = setting;
181
+ if (key === "enabled" || key === "disableLogSending") {
182
+ settled = requireBoolean(`${OVERRIDE_PATH}.${key}`, setting);
183
+ } else if (key === "redactedQueryParams") {
184
+ settled = settleStringList(`${OVERRIDE_PATH}.${key}`, setting);
185
+ } else if (key.endsWith("Hook")) {
186
+ settled = requireFunction(`${OVERRIDE_PATH}.<a hook>`, setting);
187
+ }
188
+ if (isGiven(settled)) copy[key] = settled;
189
+ }
190
+ return copy;
191
+ }
192
+ function settleOverrides(option, value) {
193
+ const map = requireObject(option, value);
194
+ if (map === void 0) return void 0;
195
+ const entries = Object.entries(map);
196
+ if (entries.length > MAX_OPTION_ENTRIES) {
197
+ throw new TelemetryOptionError(option, `an object of at most ${MAX_OPTION_ENTRIES} entries`);
198
+ }
199
+ const copy = {};
200
+ for (const [name, entry] of entries) {
201
+ refuseProtoKey(name);
202
+ const config = requireObject(option, entry);
203
+ if (config !== void 0) copy[name] = settleOverrideEntry(config);
204
+ }
205
+ return copy;
206
+ }
60
207
 
61
208
  // src/sdk/ignore-paths.ts
62
209
  var MAX_PATH_LENGTH = 2048;
210
+ var PATTERNS = "ignorePaths patterns";
211
+ var EXPECTED = "an array of regular expressions";
63
212
  function ignorePaths(patterns) {
64
- const stateless = patterns.map(
213
+ const copied = settleRegExpList(PATTERNS, patterns);
214
+ if (copied === void 0) {
215
+ throw new TelemetryOptionError(PATTERNS, EXPECTED);
216
+ }
217
+ const stateless = copied.map(
65
218
  (pattern) => new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""))
66
219
  );
67
220
  return (request) => {
@@ -166,107 +319,6 @@ async function shutdownTelemetry() {
166
319
  await currentHandle()?.shutdown();
167
320
  }
168
321
 
169
- // src/sdk/option-kinds.ts
170
- var MAX_OPTION_ENTRIES = 1e3;
171
- var TelemetryOptionError = class extends Error {
172
- /**
173
- * @param option - The option that was refused.
174
- * @param expected - What the option must be.
175
- */
176
- constructor(option, expected) {
177
- super(`The ${option} option must be ${expected}, so the start was refused.`);
178
- /** The stable code of this error. */
179
- this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
180
- this.name = "TelemetryOptionError";
181
- this.option = option;
182
- }
183
- };
184
- function isGiven(value) {
185
- return value !== void 0 && value !== null;
186
- }
187
- function requireBoolean(option, value) {
188
- if (!isGiven(value)) return void 0;
189
- if (typeof value !== "boolean") throw new TelemetryOptionError(option, "a boolean");
190
- return value;
191
- }
192
- function requireString(option, value) {
193
- if (!isGiven(value)) return void 0;
194
- if (typeof value !== "string") throw new TelemetryOptionError(option, "a string");
195
- return value;
196
- }
197
- function requireFunction(option, value) {
198
- if (!isGiven(value)) return void 0;
199
- if (typeof value !== "function") throw new TelemetryOptionError(option, "a function");
200
- return value;
201
- }
202
- function requireObject(option, value) {
203
- if (value === void 0 || value === null) return void 0;
204
- if (typeof value !== "object" || Array.isArray(value)) {
205
- throw new TelemetryOptionError(option, "an object");
206
- }
207
- return value;
208
- }
209
- function settleStringList(option, value) {
210
- if (!isGiven(value)) return void 0;
211
- if (!Array.isArray(value)) throw new TelemetryOptionError(option, "an array of strings");
212
- const length = value.length;
213
- if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
214
- throw new TelemetryOptionError(option, "an array of strings");
215
- }
216
- if (length > MAX_OPTION_ENTRIES) {
217
- throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} strings`);
218
- }
219
- const copy = [];
220
- for (let index = 0; index < length; index++) {
221
- const item = value[index];
222
- if (typeof item !== "string") throw new TelemetryOptionError(option, "an array of strings");
223
- copy.push(item);
224
- }
225
- return copy;
226
- }
227
- var OVERRIDE_PATH = "instrumentations.overrides[]";
228
- function refuseProtoKey(key) {
229
- if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
230
- }
231
- function settleOverrideEntry(entry) {
232
- const settings = Object.entries(entry);
233
- if (settings.length > MAX_OPTION_ENTRIES) {
234
- throw new TelemetryOptionError(
235
- OVERRIDE_PATH,
236
- `an object of at most ${MAX_OPTION_ENTRIES} settings`
237
- );
238
- }
239
- const copy = {};
240
- for (const [key, setting] of settings) {
241
- refuseProtoKey(key);
242
- let settled = setting;
243
- if (key === "enabled" || key === "disableLogSending") {
244
- settled = requireBoolean(`${OVERRIDE_PATH}.${key}`, setting);
245
- } else if (key === "redactedQueryParams") {
246
- settled = settleStringList(`${OVERRIDE_PATH}.${key}`, setting);
247
- } else if (key.endsWith("Hook")) {
248
- settled = requireFunction(`${OVERRIDE_PATH}.<a hook>`, setting);
249
- }
250
- if (isGiven(settled)) copy[key] = settled;
251
- }
252
- return copy;
253
- }
254
- function settleOverrides(option, value) {
255
- const map = requireObject(option, value);
256
- if (map === void 0) return void 0;
257
- const entries = Object.entries(map);
258
- if (entries.length > MAX_OPTION_ENTRIES) {
259
- throw new TelemetryOptionError(option, `an object of at most ${MAX_OPTION_ENTRIES} entries`);
260
- }
261
- const copy = {};
262
- for (const [name, entry] of entries) {
263
- refuseProtoKey(name);
264
- const config = requireObject(option, entry);
265
- if (config !== void 0) copy[name] = settleOverrideEntry(config);
266
- }
267
- return copy;
268
- }
269
-
270
322
  // src/sdk/assembly.ts
271
323
  var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
272
324
  var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
@@ -113,11 +113,6 @@ interface TelemetryHandle {
113
113
  shutdown(): Promise<void>;
114
114
  }
115
115
 
116
- /**
117
- * @fileoverview Path-based predicate for incoming requests that must produce no span.
118
- * @layer sdk
119
- */
120
-
121
116
  /**
122
117
  * Builds a predicate that matches the path of an incoming request against the patterns.
123
118
  *
@@ -113,11 +113,6 @@ interface TelemetryHandle {
113
113
  shutdown(): Promise<void>;
114
114
  }
115
115
 
116
- /**
117
- * @fileoverview Path-based predicate for incoming requests that must produce no span.
118
- * @layer sdk
119
- */
120
-
121
116
  /**
122
117
  * Builds a predicate that matches the path of an incoming request against the patterns.
123
118
  *
@@ -1,3 +1,4 @@
1
+ import { types } from 'util';
1
2
  import { createRequire } from 'module';
2
3
  import { join } from 'path';
3
4
 
@@ -55,11 +56,163 @@ function createUrlQueryRedactor() {
55
56
  function serializeRedisCommandName(commandName) {
56
57
  return commandName;
57
58
  }
59
+ var isIndex = (key) => String(Number(key) >>> 0) === key && key !== "4294967295";
60
+ var MAX_OPTION_ENTRIES = 1e3;
61
+ var TelemetryOptionError = class extends Error {
62
+ /**
63
+ * @param option - The option that was refused.
64
+ * @param expected - What the option must be.
65
+ * @param cause - The error of the host's own value that made the option unusable.
66
+ */
67
+ constructor(option, expected, cause) {
68
+ super(
69
+ `The ${option} option must be ${expected}, so the start was refused.`,
70
+ cause === void 0 ? void 0 : { cause }
71
+ );
72
+ /** The stable code of this error. */
73
+ this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
74
+ this.name = "TelemetryOptionError";
75
+ this.option = option;
76
+ }
77
+ };
78
+ function isGiven(value) {
79
+ return value !== void 0 && value !== null;
80
+ }
81
+ function requireBoolean(option, value) {
82
+ if (!isGiven(value)) return void 0;
83
+ if (typeof value !== "boolean") throw new TelemetryOptionError(option, "a boolean");
84
+ return value;
85
+ }
86
+ function requireString(option, value) {
87
+ if (!isGiven(value)) return void 0;
88
+ if (typeof value !== "string") throw new TelemetryOptionError(option, "a string");
89
+ return value;
90
+ }
91
+ function requireFunction(option, value) {
92
+ if (!isGiven(value)) return void 0;
93
+ if (typeof value !== "function") throw new TelemetryOptionError(option, "a function");
94
+ return value;
95
+ }
96
+ function requireObject(option, value) {
97
+ if (value === void 0 || value === null) return void 0;
98
+ if (typeof value !== "object" || Array.isArray(value) || isOtherKind(value)) {
99
+ throw new TelemetryOptionError(option, "an object");
100
+ }
101
+ return value;
102
+ }
103
+ function isOtherKind(value) {
104
+ return types.isBoxedPrimitive(value) || types.isMap(value) || types.isSet(value) || types.isDate(value) || types.isRegExp(value) || types.isPromise(value);
105
+ }
106
+ function copyByIndex(option, value, noun, take, guarded) {
107
+ if (!isGiven(value)) return void 0;
108
+ const expected = `an array of ${noun}`;
109
+ const host = (read) => {
110
+ if (!guarded) return read();
111
+ try {
112
+ return read();
113
+ } catch (cause) {
114
+ throw new TelemetryOptionError(option, expected, cause);
115
+ }
116
+ };
117
+ if (!host(() => Array.isArray(value))) throw new TelemetryOptionError(option, expected);
118
+ const list = value;
119
+ const length = host(() => list.length);
120
+ if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
121
+ throw new TelemetryOptionError(option, expected);
122
+ }
123
+ if (length > MAX_OPTION_ENTRIES) {
124
+ throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} ${noun}`);
125
+ }
126
+ if (length === 0 && host(() => Object.keys(list).some(isIndex))) {
127
+ throw new TelemetryOptionError(option, expected);
128
+ }
129
+ const copy = [];
130
+ for (let index = 0; index < length; index++) {
131
+ const taken = take(host(() => list[index]));
132
+ if (taken === void 0) throw new TelemetryOptionError(option, expected);
133
+ copy.push(taken);
134
+ }
135
+ return copy;
136
+ }
137
+ function settleStringList(option, value) {
138
+ return copyByIndex(
139
+ option,
140
+ value,
141
+ "strings",
142
+ (entry) => typeof entry === "string" ? entry : void 0,
143
+ false
144
+ );
145
+ }
146
+ function settleRegExpList(option, value) {
147
+ return copyByIndex(
148
+ option,
149
+ value,
150
+ "regular expressions",
151
+ (entry) => {
152
+ if (!types.isRegExp(entry)) return void 0;
153
+ try {
154
+ const { source, flags } = entry;
155
+ return new RegExp(source, flags);
156
+ } catch (cause) {
157
+ throw new TelemetryOptionError(option, "an array of regular expressions", cause);
158
+ }
159
+ },
160
+ true
161
+ );
162
+ }
163
+ var OVERRIDE_PATH = "instrumentations.overrides[]";
164
+ function refuseProtoKey(key) {
165
+ if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
166
+ }
167
+ function settleOverrideEntry(entry) {
168
+ const settings = Object.entries(entry);
169
+ if (settings.length > MAX_OPTION_ENTRIES) {
170
+ throw new TelemetryOptionError(
171
+ OVERRIDE_PATH,
172
+ `an object of at most ${MAX_OPTION_ENTRIES} settings`
173
+ );
174
+ }
175
+ const copy = {};
176
+ for (const [key, setting] of settings) {
177
+ refuseProtoKey(key);
178
+ let settled = setting;
179
+ if (key === "enabled" || key === "disableLogSending") {
180
+ settled = requireBoolean(`${OVERRIDE_PATH}.${key}`, setting);
181
+ } else if (key === "redactedQueryParams") {
182
+ settled = settleStringList(`${OVERRIDE_PATH}.${key}`, setting);
183
+ } else if (key.endsWith("Hook")) {
184
+ settled = requireFunction(`${OVERRIDE_PATH}.<a hook>`, setting);
185
+ }
186
+ if (isGiven(settled)) copy[key] = settled;
187
+ }
188
+ return copy;
189
+ }
190
+ function settleOverrides(option, value) {
191
+ const map = requireObject(option, value);
192
+ if (map === void 0) return void 0;
193
+ const entries = Object.entries(map);
194
+ if (entries.length > MAX_OPTION_ENTRIES) {
195
+ throw new TelemetryOptionError(option, `an object of at most ${MAX_OPTION_ENTRIES} entries`);
196
+ }
197
+ const copy = {};
198
+ for (const [name, entry] of entries) {
199
+ refuseProtoKey(name);
200
+ const config = requireObject(option, entry);
201
+ if (config !== void 0) copy[name] = settleOverrideEntry(config);
202
+ }
203
+ return copy;
204
+ }
58
205
 
59
206
  // src/sdk/ignore-paths.ts
60
207
  var MAX_PATH_LENGTH = 2048;
208
+ var PATTERNS = "ignorePaths patterns";
209
+ var EXPECTED = "an array of regular expressions";
61
210
  function ignorePaths(patterns) {
62
- const stateless = patterns.map(
211
+ const copied = settleRegExpList(PATTERNS, patterns);
212
+ if (copied === void 0) {
213
+ throw new TelemetryOptionError(PATTERNS, EXPECTED);
214
+ }
215
+ const stateless = copied.map(
63
216
  (pattern) => new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""))
64
217
  );
65
218
  return (request) => {
@@ -164,107 +317,6 @@ async function shutdownTelemetry() {
164
317
  await currentHandle()?.shutdown();
165
318
  }
166
319
 
167
- // src/sdk/option-kinds.ts
168
- var MAX_OPTION_ENTRIES = 1e3;
169
- var TelemetryOptionError = class extends Error {
170
- /**
171
- * @param option - The option that was refused.
172
- * @param expected - What the option must be.
173
- */
174
- constructor(option, expected) {
175
- super(`The ${option} option must be ${expected}, so the start was refused.`);
176
- /** The stable code of this error. */
177
- this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
178
- this.name = "TelemetryOptionError";
179
- this.option = option;
180
- }
181
- };
182
- function isGiven(value) {
183
- return value !== void 0 && value !== null;
184
- }
185
- function requireBoolean(option, value) {
186
- if (!isGiven(value)) return void 0;
187
- if (typeof value !== "boolean") throw new TelemetryOptionError(option, "a boolean");
188
- return value;
189
- }
190
- function requireString(option, value) {
191
- if (!isGiven(value)) return void 0;
192
- if (typeof value !== "string") throw new TelemetryOptionError(option, "a string");
193
- return value;
194
- }
195
- function requireFunction(option, value) {
196
- if (!isGiven(value)) return void 0;
197
- if (typeof value !== "function") throw new TelemetryOptionError(option, "a function");
198
- return value;
199
- }
200
- function requireObject(option, value) {
201
- if (value === void 0 || value === null) return void 0;
202
- if (typeof value !== "object" || Array.isArray(value)) {
203
- throw new TelemetryOptionError(option, "an object");
204
- }
205
- return value;
206
- }
207
- function settleStringList(option, value) {
208
- if (!isGiven(value)) return void 0;
209
- if (!Array.isArray(value)) throw new TelemetryOptionError(option, "an array of strings");
210
- const length = value.length;
211
- if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
212
- throw new TelemetryOptionError(option, "an array of strings");
213
- }
214
- if (length > MAX_OPTION_ENTRIES) {
215
- throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} strings`);
216
- }
217
- const copy = [];
218
- for (let index = 0; index < length; index++) {
219
- const item = value[index];
220
- if (typeof item !== "string") throw new TelemetryOptionError(option, "an array of strings");
221
- copy.push(item);
222
- }
223
- return copy;
224
- }
225
- var OVERRIDE_PATH = "instrumentations.overrides[]";
226
- function refuseProtoKey(key) {
227
- if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
228
- }
229
- function settleOverrideEntry(entry) {
230
- const settings = Object.entries(entry);
231
- if (settings.length > MAX_OPTION_ENTRIES) {
232
- throw new TelemetryOptionError(
233
- OVERRIDE_PATH,
234
- `an object of at most ${MAX_OPTION_ENTRIES} settings`
235
- );
236
- }
237
- const copy = {};
238
- for (const [key, setting] of settings) {
239
- refuseProtoKey(key);
240
- let settled = setting;
241
- if (key === "enabled" || key === "disableLogSending") {
242
- settled = requireBoolean(`${OVERRIDE_PATH}.${key}`, setting);
243
- } else if (key === "redactedQueryParams") {
244
- settled = settleStringList(`${OVERRIDE_PATH}.${key}`, setting);
245
- } else if (key.endsWith("Hook")) {
246
- settled = requireFunction(`${OVERRIDE_PATH}.<a hook>`, setting);
247
- }
248
- if (isGiven(settled)) copy[key] = settled;
249
- }
250
- return copy;
251
- }
252
- function settleOverrides(option, value) {
253
- const map = requireObject(option, value);
254
- if (map === void 0) return void 0;
255
- const entries = Object.entries(map);
256
- if (entries.length > MAX_OPTION_ENTRIES) {
257
- throw new TelemetryOptionError(option, `an object of at most ${MAX_OPTION_ENTRIES} entries`);
258
- }
259
- const copy = {};
260
- for (const [name, entry] of entries) {
261
- refuseProtoKey(name);
262
- const config = requireObject(option, entry);
263
- if (config !== void 0) copy[name] = settleOverrideEntry(config);
264
- }
265
- return copy;
266
- }
267
-
268
320
  // src/sdk/assembly.ts
269
321
  var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
270
322
  var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-telemetry",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "OpenTelemetry tracing for NestJS 11 and plain Node: starts the SDK before your app loads, redacts secrets from spans by default, and flushes on shutdown. Optional peers, zero cost when disabled.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -91,7 +91,7 @@
91
91
  "clean": "rm -rf dist coverage",
92
92
  "check:socket-gate": "node scripts/check-socket-gate.mjs",
93
93
  "check:spec-headers": "node scripts/check-spec-headers.mjs",
94
- "lint": "eslint src scripts test '*.config.ts' '*.config.mjs' '*.config.cjs' && pnpm check:socket-gate && pnpm check:spec-headers && node --test scripts/check-spec-headers.test.mjs",
94
+ "lint": "eslint src scripts test '*.config.ts' '*.config.mjs' '*.config.cjs' && pnpm check:socket-gate && pnpm check:spec-headers && node --test scripts/check-spec-headers.test.mjs scripts/check-dist-fresh.test.mjs",
95
95
  "lint:fix": "eslint src scripts test '*.config.ts' '*.config.mjs' '*.config.cjs' --fix",
96
96
  "mutation": "stryker run",
97
97
  "mutation:full": "node -e \"require('node:fs').rmSync('reports/stryker-incremental.json',{force:true,recursive:true})\" && stryker run",
@@ -99,7 +99,7 @@
99
99
  "prepare": "husky",
100
100
  "prepublishOnly": "pnpm clean && pnpm typecheck && pnpm lint && pnpm check:mutants && pnpm check:docs && pnpm test:cov && pnpm test:e2e && pnpm test:cov:all && pnpm build && pnpm check:published",
101
101
  "release": "npm publish --provenance --access public",
102
- "size": "node scripts/check-size.mjs",
102
+ "size": "node scripts/check-dist-fresh.mjs && node scripts/check-size.mjs",
103
103
  "test": "jest",
104
104
  "test:all": "pnpm test && pnpm test:e2e",
105
105
  "test:cov": "jest --coverage",