@bymax-one/nest-telemetry 1.0.9 → 1.0.10

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,7 +8,40 @@ 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
- ## [Unreleased]
11
+ ## [1.0.10] - 2026-11-21
12
+
13
+ ### Fixed
14
+
15
+ - **An option of the wrong kind is refused, and no longer read as something it is not.** The string `'false'`, a
16
+ number or an object for `instrumentations.sendLogs` was truthy and turned the export of log records on, which
17
+ sends data off the host; the string `'true'` for an `unsafe` flag was dropped without a word; a string for
18
+ `extraRedactedQueryParams` was spread into its characters and a number threw a `TypeError` out of the start.
19
+ `startTelemetry` now rejects with an error whose `code` is `BYMAX_TELEMETRY_OPTION_INVALID` and whose `option`
20
+ names the option, before any SDK is started. `shutdownTimeoutMs` keeps its documented fallback.
21
+ - **The settings of an `instrumentations.overrides` entry that decide what leaves the host are checked too.** An
22
+ override was spread over the library's configuration unchecked, so `{ disableLogSending: 0 }` for the pino
23
+ instrumentation turned log sending on and a non-boolean `enabled` replaced the one the library forces. Each
24
+ entry is now copied once; `enabled` and `disableLogSending` must be booleans, `redactedQueryParams` an array
25
+ of strings, every setting named `...Hook` a function, an entry holds at most 1000 settings, and a `__proto__` key is refused. The error names
26
+ `instrumentations.overrides[]` and never the instrumentation or the value.
27
+ - **Each option of a call is read once.** A getter could make a warning and the effect of the call disagree. A
28
+ call now reads each option once, checks its kind, and works from the copy.
29
+
30
+ ### Documentation
31
+
32
+ - **The README says a failed start starts no new SDK.** It said "no SDK started and no handle left", which is
33
+ wrong for a later call that finds an SDK already running; it now says that the failed start starts no new SDK
34
+ and that a first start leaves no handle.
35
+ - **The README lists the ranges of the peers that are not OpenTelemetry packages**, as `package.json` declares
36
+ them, and its CPU item no longer says "that handler".
37
+
38
+ ### Apply to a derived backend
39
+
40
+ A configuration that passed a value of the wrong kind used to be accepted and now fails at start with
41
+ `BYMAX_TELEMETRY_OPTION_INVALID`. Look for a string such as `'false'` in `instrumentations.sendLogs` or an `unsafe`
42
+ flag (read from an environment variable without converting it), a single string for `extraRedactedQueryParams`
43
+ (pass `['name']`), a non-boolean `enabled` or `disableLogSending`, a non-array `redactedQueryParams` or a non-function `...Hook` inside an `overrides` entry, and a list, map or entry of more than 1000 items. Nothing else changes: a plain value of
44
+ the documented kind behaves as before.
12
45
 
13
46
  ## [1.0.9] - 2026-11-20
14
47
 
@@ -411,6 +444,7 @@ First release.
411
444
  - Verification from the packed tarball: real `node --import` processes in a CommonJS and a native-ESM
412
445
  application, with planted secrets absent from the exported body and negative controls.
413
446
 
447
+ [1.0.10]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.10
414
448
  [1.0.9]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.9
415
449
  [1.0.8]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.8
416
450
  [1.0.7]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.7
package/README.md CHANGED
@@ -225,12 +225,14 @@ 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
- 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: the library has no error class of its own for a start, so an option whose getter throws (or a proxy that fails an operation) ends the start with that error, with no SDK started and no handle left.
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.
229
+
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.
229
231
 
230
232
  ### What is traced
231
233
 
232
234
  - **Load order matters only for modules your application loads itself.** The core `http` module is patched even when the preload runs after it. A client such as `ioredis` is patched only if the preload ran before the application required it. Measured: an application that required `ioredis` first exported no `ioredis` span.
233
- - **`ioredis` commands are traced only under an active span; node-redis commands are not.** The `ioredis` instrumentation defaults to `requireParentSpan: true`, so a command issued outside any request produces no span. The node-redis (`redis`) instrumentation defaults to `false`, so it traces a command with no request around it too. Measured with `redis` 5 and 6.
235
+ - **`ioredis` commands are traced only under an active span; node-redis commands are not.** The `ioredis` instrumentation defaults to `requireParentSpan: true`, so a command issued outside any request produces no span. The node-redis (`redis`) instrumentation defaults to `false`, so it traces a command with no request around it too. Measured as of 2026-11-13 with `redis` 5 and 6; the proofs in this repository run `redis` 6.
234
236
  - **`fs` instrumentation is off by default**, because it floods traces with disk activity that has no context. Turn it on with `instrumentations.fs`.
235
237
 
236
238
  ### Forwarding log records
@@ -281,18 +283,18 @@ Awaiting `shutdown()` or `shutdownTelemetry()` means the spans were exported, wh
281
283
 
282
284
  The wait is bounded. A collector that accepts a connection and never answers would otherwise hold shutdown for the exporter's own timeout, ten seconds by default, so a flush that has not finished within `shutdownTimeoutMs` (5 seconds unless set, at most 120 seconds) stops holding the caller: shutdown emits `BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT` and resolves. The flush keeps running in the background and a failure after the deadline is dropped. Spans still queued at that point may be lost.
283
285
 
284
- A start after a shutdown in the same process is refused: `startTelemetry` rejects, with an error that says to start once per process (in a test suite, once in a global setup), and the process emits `BYMAX_TELEMETRY_RESTART_UNSUPPORTED`. Auto-instrumented spans can never resume after a shutdown, because the modules the first start instrumented are already patched against its tracer provider; spans created through the API could, but a half-working restart is refused on purpose. Measured with an in-process HTTP request and one manual span per run: after a restart that released the API globals, the manual span was exported and the HTTP spans were not. The preload turns the refusal into a `BYMAX_TELEMETRY_START_FAILED` warning and the application still boots.
286
+ A start after a shutdown in the same process is refused: `startTelemetry` rejects, with an error that says to start once per process (in a test suite, once in a global setup), and the process emits `BYMAX_TELEMETRY_RESTART_UNSUPPORTED`. Auto-instrumented spans can never resume after a shutdown, because the modules the first start instrumented are already patched against its tracer provider; spans created through the API could, but a half-working restart is refused on purpose. Measured as of 2026-11-13, in runs that are not part of this repository, with an in-process HTTP request and one manual span per run: after a restart that released the API globals, the manual span was exported and the HTTP spans were not. The preload turns the refusal into a `BYMAX_TELEMETRY_START_FAILED` warning and the application still boots.
285
287
 
286
288
  ---
287
289
 
288
290
  ## 🏭 Production
289
291
 
290
- Every figure here was measured on one laptop, with Node 24 and a handler that does nothing but answer. Read them as orders of magnitude for your own measurement to confirm, not as promises.
292
+ Every measured figure here was taken on one laptop, with Node 24, as of 2026-11-13; no script in this repository reproduces them. Read them as orders of magnitude for your own measurement to confirm, not as promises.
291
293
 
292
- - **Sampling.** The default samples every trace. For high traffic set `OTEL_TRACES_SAMPLER=parentbased_traceidratio` and `OTEL_TRACES_SAMPLER_ARG=0.1`. Of 2,000 spans created in one run each, the default exported all of them, a ratio of `0.1` exported 210 and a ratio of `0.01` exported 25. A ratio sampler needs `OTEL_TRACES_SAMPLER_ARG` to be a number from 0 to 1. When it is unset, empty or only whitespace, not a number or outside that range, the SDK falls back to a ratio of 1 and samples every trace, noting it only on a diagnostic channel; the start warns once with `BYMAX_TELEMETRY_SAMPLER_ARG_INVALID`, naming the variable and, when a non-blank value was given, the value (a blank value is called blank, not unset, and is not repeated). The SDK matches the sampler name exactly: `always_on`, `always_off`, `traceidratio`, `parentbased_always_on`, `parentbased_always_off` and `parentbased_traceidratio`, in lower case and without surrounding whitespace. Any other value, `TraceIdRatio` included, is replaced by its default and samples every trace; when the value differs from one of those names only in letter case or surrounding whitespace, the start warns once with `BYMAX_TELEMETRY_SAMPLER_NAME_UNKNOWN`, naming the name that was meant and not repeating the value. A name that is not one of those up to case and whitespace, such as `xyz` or a misspelling like `always_offf`, is not warned about: it samples every trace as well, so check the spelling of the variable. It reads the process environment, as the SDK does, and not the `env` option.
294
+ - **Sampling.** The default samples every trace. For high traffic set `OTEL_TRACES_SAMPLER=parentbased_traceidratio` and `OTEL_TRACES_SAMPLER_ARG=0.1`. Of 2,000 spans created in one run each, the default exported all of them, a ratio of `0.1` exported 210 and a ratio of `0.01` exported 25. A ratio sampler needs `OTEL_TRACES_SAMPLER_ARG` to be a number from 0 to 1. When it is unset, empty or only whitespace, not a number or outside that range, the SDK falls back to a ratio of 1 and samples every trace, noting it only on a diagnostic channel; the start warns once with `BYMAX_TELEMETRY_SAMPLER_ARG_INVALID`, naming the variable and, when a non-blank value was given, the value (cut to 40 characters, with control, separator and invisible characters written as escapes) (a blank value is called blank, not unset, and is not repeated). The SDK matches the sampler name exactly: `always_on`, `always_off`, `traceidratio`, `parentbased_always_on`, `parentbased_always_off` and `parentbased_traceidratio`, in lower case and without surrounding whitespace. Any other value, `TraceIdRatio` included, is replaced by its default and samples every trace; when the value differs from one of those names only in letter case or surrounding whitespace, the start warns once with `BYMAX_TELEMETRY_SAMPLER_NAME_UNKNOWN`, naming the name that was meant and not repeating the value. A name that is not one of those up to case and whitespace, such as `xyz` or a misspelling like `always_offf`, is not warned about: it samples every trace as well, so check the spelling of the variable. It reads the process environment, as the SDK does, and not the `env` option.
293
295
  - **TLS to the collector.** Against a collector whose certificate Node does not trust, every export failed with `self-signed certificate`. Setting `OTEL_EXPORTER_OTLP_CERTIFICATE` to the CA file, or `NODE_EXTRA_CA_CERTS`, exported all 2,000 spans in the same setup.
294
296
  - **A collector that is down.** The batch is dropped and the library emits `BYMAX_TELEMETRY_EXPORT_FAILED`, at most once a minute. Shutdown stops waiting at `shutdownTimeoutMs`, 5 seconds by default. Before that deadline existed, shutdown against a closed port took 7,048 ms and 7,214 ms in two runs.
295
- - **CPU.** One process, 4 runs per mode, median CPU time per request: 25 µs without the library, 26 µs with it loaded and disabled, 58 µs with a healthy collector (range 35 to 66) and 43 µs with the collector down (range 26 to 65). The extra cost in that handler is roughly 10 to 40 µs per request, and a handler that does real I/O dilutes it. The same configuration varied by up to a factor of two between runs.
297
+ - **CPU.** One process, 4 runs per mode, median CPU time per request: 25 µs without the library, 26 µs with it loaded and disabled, 58 µs with a healthy collector (range 35 to 66) and 43 µs with the collector down (range 26 to 65). The extra cost is roughly 10 to 40 µs per request, and a handler that does real I/O dilutes it. The same configuration varied by up to a factor of two between runs.
296
298
  - **Memory.** After 10 seconds idle, RSS was 61 to 63 MB without the library and with it disabled, 83 to 95 MB with a healthy collector and 142 to 160 MB with the collector unreachable. Under sustained load with the collector unreachable, the default settings reached between about 195 and 310 MB in one 90-second run.
297
299
  - **Small containers.** `node --max-semi-space-size=8` is an optional V8 lever that shrinks the young generation. Under the same unreachable-collector load, RSS had a median of 138 MB (maximum 158) against about 195 to 310 MB for the default settings. The memory figures are one run each, so they are noisy, and a setting of 4 did not do better than 8 (RSS levelled at about 220 MB). At 1,000 requests per second against an unreachable collector, p99 latency over three runs each was 3.6 to 7.3 ms with the default settings and 4.8 to 6.8 ms with 8, so no cost showed at that load. The extra memory with the collector down is most likely churn from failed exports, which was not measured separately.
298
300
 
@@ -310,6 +312,8 @@ Every `@opentelemetry/*` package is an optional peer. The `0.x` packages break b
310
312
  | `@opentelemetry/resources` | `^3.1.0` |
311
313
  | `@opentelemetry/auto-instrumentations-node` | `^0.83.0` |
312
314
 
315
+ The optional peers that are not OpenTelemetry packages are `@bymax-one/nest-core` `^1.1.0`, `prom-client` `^15.0.0`, `@nestjs/common` `^11.0.16`, `@nestjs/core` `^11.1.18`, `reflect-metadata` `^0.2.0` and `rxjs` `^7.8.0`.
316
+
313
317
  A caret on a `0.x` version allows patch releases only, so each OpenTelemetry minor needs a release of this package to widen the range. That is a human decision: a weekly job runs the unit and end-to-end suites, the build and the tarball checks against the newest release of every OpenTelemetry package, ignoring the lockfile, and opens an issue when they fail. A range is widened in a pull request after the job passes against the new generation. Dependabot groups the OpenTelemetry packages, so they move as one set.
314
318
 
315
319
  ---
@@ -444,7 +448,7 @@ pnpm check:runtime # packed-tarball consumer proofs
444
448
  | `InstrumentationOptions` | type | `fs`, `sendLogs` and `overrides` |
445
449
  | `IncomingRequestTarget` | type | What an incoming-request predicate sees: the request `url` |
446
450
 
447
- `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, and the time grows exponentially with the length.
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.
448
452
 
449
453
  ### Register: `@bymax-one/nest-telemetry/register`
450
454
 
@@ -475,7 +479,7 @@ No exports. `node --import @bymax-one/nest-telemetry/register` registers the loa
475
479
 
476
480
  ## 🚫 What This Library Does NOT Do
477
481
 
478
- By design, the following are out of scope:
482
+ By design, the following are out of scope. The attribute names below are the ones the instrumentations recorded as of 2026-11-13; only the mysql2 behaviour has a canary in the proofs, so check the others against the versions you install:
479
483
 
480
484
  - ❌ **Redact secrets in the URL path** — only the query string is removed. A path such as `/reset/<token>` is exported as it is
481
485
  - ❌ **Redact SQL text with inline literals** — database instrumentations record the statement, and values written into it are exported. A value bound to a placeholder is not recorded by `instrumentation-mysql2` 0.71, measured with mysql2 2.3.3, 3.0.0, 3.9.0 and 3.24.6; a canary in the proofs fails if that stops being true
@@ -490,7 +494,7 @@ By design, the following are out of scope:
490
494
  - ❌ **Redact baggage**
491
495
  - ❌ **Redact request and response bodies, or HTTP headers** — they are not captured by default, and they are not redacted if you enable capturing them
492
496
  - ❌ **Redact attributes your own code sets**
493
- - ❌ **Redact log records forwarded through `OTEL_LOGS_EXPORTER`** — the library redacts spans, and a log record is exported as the logger produced it, so redact in the logger. Measured with `@bymax-one/nest-logger` 1.4.16, which redacts before it hands the record over: a password and a nested token never reached the collector, and the `[REDACTED]` marker did. A plain pino logger with no redaction exported its password
497
+ - ❌ **Redact log records forwarded through `OTEL_LOGS_EXPORTER`** — the library redacts spans, and a log record is exported as the logger produced it, so redact in the logger. Measured as of 2026-11-13, in a run that is not part of this repository, with `@bymax-one/nest-logger` 1.4.16, which redacts before it hands the record over: a password and a nested token never reached the collector, and the `[REDACTED]` marker did. A plain pino logger with no redaction exported its password
494
498
  - ❌ **Choose a sampler** — configure `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
495
499
  - ❌ **Run a collector or a backend** — point `OTEL_EXPORTER_OTLP_ENDPOINT` at one
496
500
  - ❌ **Decide your span names** — those come from the instrumentations and from your code
@@ -95,6 +95,107 @@ function describeFailure(error) {
95
95
  }
96
96
  }
97
97
 
98
+ // src/sdk/option-kinds.ts
99
+ var MAX_OPTION_ENTRIES = 1e3;
100
+ var TelemetryOptionError = class extends Error {
101
+ /**
102
+ * @param option - The option that was refused.
103
+ * @param expected - What the option must be.
104
+ */
105
+ constructor(option, expected) {
106
+ super(`The ${option} option must be ${expected}, so the start was refused.`);
107
+ /** The stable code of this error. */
108
+ this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
109
+ this.name = "TelemetryOptionError";
110
+ this.option = option;
111
+ }
112
+ };
113
+ function isGiven(value) {
114
+ return value !== void 0 && value !== null;
115
+ }
116
+ function requireBoolean(option, value) {
117
+ if (!isGiven(value)) return void 0;
118
+ if (typeof value !== "boolean") throw new TelemetryOptionError(option, "a boolean");
119
+ return value;
120
+ }
121
+ function requireString(option, value) {
122
+ if (!isGiven(value)) return void 0;
123
+ if (typeof value !== "string") throw new TelemetryOptionError(option, "a string");
124
+ return value;
125
+ }
126
+ function requireFunction(option, value) {
127
+ if (!isGiven(value)) return void 0;
128
+ if (typeof value !== "function") throw new TelemetryOptionError(option, "a function");
129
+ return value;
130
+ }
131
+ function requireObject(option, value) {
132
+ if (value === void 0 || value === null) return void 0;
133
+ if (typeof value !== "object" || Array.isArray(value)) {
134
+ throw new TelemetryOptionError(option, "an object");
135
+ }
136
+ return value;
137
+ }
138
+ function settleStringList(option, value) {
139
+ if (!isGiven(value)) return void 0;
140
+ if (!Array.isArray(value)) throw new TelemetryOptionError(option, "an array of strings");
141
+ const length = value.length;
142
+ if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
143
+ throw new TelemetryOptionError(option, "an array of strings");
144
+ }
145
+ if (length > MAX_OPTION_ENTRIES) {
146
+ throw new TelemetryOptionError(option, `an array of at most ${MAX_OPTION_ENTRIES} strings`);
147
+ }
148
+ const copy = [];
149
+ 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);
153
+ }
154
+ return copy;
155
+ }
156
+ var OVERRIDE_PATH = "instrumentations.overrides[]";
157
+ function refuseProtoKey(key) {
158
+ if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
159
+ }
160
+ function settleOverrideEntry(entry) {
161
+ const settings = Object.entries(entry);
162
+ if (settings.length > MAX_OPTION_ENTRIES) {
163
+ throw new TelemetryOptionError(
164
+ OVERRIDE_PATH,
165
+ `an object of at most ${MAX_OPTION_ENTRIES} settings`
166
+ );
167
+ }
168
+ const copy = {};
169
+ for (const [key, setting] of settings) {
170
+ refuseProtoKey(key);
171
+ let settled = setting;
172
+ if (key === "enabled" || key === "disableLogSending") {
173
+ settled = requireBoolean(`${OVERRIDE_PATH}.${key}`, setting);
174
+ } else if (key === "redactedQueryParams") {
175
+ settled = settleStringList(`${OVERRIDE_PATH}.${key}`, setting);
176
+ } else if (key.endsWith("Hook")) {
177
+ settled = requireFunction(`${OVERRIDE_PATH}.<a hook>`, setting);
178
+ }
179
+ if (isGiven(settled)) copy[key] = settled;
180
+ }
181
+ return copy;
182
+ }
183
+ function settleOverrides(option, value) {
184
+ const map = requireObject(option, value);
185
+ if (map === void 0) return void 0;
186
+ const entries = Object.entries(map);
187
+ if (entries.length > MAX_OPTION_ENTRIES) {
188
+ throw new TelemetryOptionError(option, `an object of at most ${MAX_OPTION_ENTRIES} entries`);
189
+ }
190
+ const copy = {};
191
+ for (const [name, entry] of entries) {
192
+ refuseProtoKey(name);
193
+ const config = requireObject(option, entry);
194
+ if (config !== void 0) copy[name] = settleOverrideEntry(config);
195
+ }
196
+ return copy;
197
+ }
198
+
98
199
  // src/sdk/redaction.ts
99
200
  var REDACTED_QUERY_VALUE = "[redacted]";
100
201
  var URL_QUERY_ATTRIBUTE = "url.query";
@@ -206,13 +307,13 @@ function readEachOption(options) {
206
307
  env: options.env
207
308
  };
208
309
  }
209
- function definedEntries(config) {
210
- return Object.fromEntries(Object.entries(config).filter(([, value]) => isPresent(value)));
211
- }
212
310
  function nonBlank(value) {
213
311
  const trimmed = value?.trim();
214
312
  return trimmed === "" ? void 0 : trimmed;
215
313
  }
314
+ function settleService(options) {
315
+ return { serviceName: options.serviceName, serviceVersion: options.serviceVersion };
316
+ }
216
317
  function buildResourceAttributes(options, env) {
217
318
  const attributes = {};
218
319
  const name = env.serviceName ?? nonBlank(options.serviceName);
@@ -222,25 +323,28 @@ function buildResourceAttributes(options, env) {
222
323
  return attributes;
223
324
  }
224
325
  function settleUnsafe(unsafe) {
326
+ const flags = requireObject("unsafe", unsafe);
327
+ const flag = (name) => requireBoolean(`unsafe.${name}`, flags?.[name]) === true;
225
328
  return {
226
- disableUrlRedaction: unsafe?.disableUrlRedaction === true,
227
- disableRedisArgumentRedaction: unsafe?.disableRedisArgumentRedaction === true,
228
- exportProcessCommandArgs: unsafe?.exportProcessCommandArgs === true,
229
- exportHostId: unsafe?.exportHostId === true
329
+ disableUrlRedaction: flag("disableUrlRedaction"),
330
+ disableRedisArgumentRedaction: flag("disableRedisArgumentRedaction"),
331
+ exportProcessCommandArgs: flag("exportProcessCommandArgs"),
332
+ exportHostId: flag("exportHostId")
230
333
  };
231
334
  }
232
335
  function settleInstrumentations(instrumentations) {
336
+ const read = requireObject("instrumentations", instrumentations);
233
337
  return {
234
- fs: instrumentations?.fs,
235
- sendLogs: instrumentations?.sendLogs,
236
- overrides: instrumentations?.overrides
338
+ fs: requireBoolean("instrumentations.fs", read?.fs),
339
+ sendLogs: requireBoolean("instrumentations.sendLogs", read?.sendLogs),
340
+ overrides: settleOverrides("instrumentations.overrides", read?.overrides)
237
341
  };
238
342
  }
239
343
  function buildInstrumentationConfig(options, signals) {
240
344
  const instrumentations = settleInstrumentations(options.instrumentations);
241
345
  const overrides = {};
242
346
  for (const [name, config] of Object.entries(instrumentations.overrides ?? {})) {
243
- if (isPresent(config)) overrides[name] = definedEntries(config);
347
+ overrides[name] = config;
244
348
  }
245
349
  const redactRedis = options.unsafe?.disableRedisArgumentRedaction !== true;
246
350
  const disableLogSending = !(instrumentations.sendLogs ?? signals.sendLogs);
@@ -513,6 +617,26 @@ function selectResourceDetectors(selection, detectors, keeps) {
513
617
  }
514
618
  return [...new Set(chosen)].map((name) => available[name]);
515
619
  }
620
+
621
+ // src/sdk/settle-options.ts
622
+ function settleOptions(options) {
623
+ const read = readEachOption(options);
624
+ const settled = {
625
+ enabled: requireBoolean("enabled", read.enabled),
626
+ serviceName: requireString("serviceName", read.serviceName),
627
+ serviceVersion: requireString("serviceVersion", read.serviceVersion),
628
+ ignoreIncomingRequest: requireFunction("ignoreIncomingRequest", read.ignoreIncomingRequest),
629
+ instrumentations: isGiven(read.instrumentations) ? settleInstrumentations(read.instrumentations) : void 0,
630
+ extraRedactedQueryParams: settleStringList(
631
+ "extraRedactedQueryParams",
632
+ read.extraRedactedQueryParams
633
+ ),
634
+ unsafe: isGiven(read.unsafe) ? settleUnsafe(read.unsafe) : void 0,
635
+ shutdownTimeoutMs: read.shutdownTimeoutMs,
636
+ env: requireObject("env", read.env)
637
+ };
638
+ return Object.fromEntries(Object.entries(settled).filter(([, value]) => isGiven(value)));
639
+ }
516
640
  var TRANSPORT = "@opentelemetry/winston-transport";
517
641
  var BUNDLE = "@opentelemetry/auto-instrumentations-node";
518
642
  var INSTRUMENTATION = "@opentelemetry/instrumentation-winston";
@@ -548,9 +672,10 @@ var DISABLED_HANDLE = {
548
672
  shutdown: () => Promise.resolve()
549
673
  };
550
674
  async function startTelemetry(options = {}) {
551
- const env = readTelemetryEnvironment(options.env ?? void 0);
552
- if (options.enabled === false || env.sdkDisabled) {
553
- if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(options);
675
+ const settled = settleOptions(options);
676
+ const env = readTelemetryEnvironment(settled.env);
677
+ if (settled.enabled === false || env.sdkDisabled) {
678
+ if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(settled);
554
679
  return DISABLED_HANDLE;
555
680
  }
556
681
  let running = currentHandle();
@@ -559,12 +684,12 @@ async function startTelemetry(options = {}) {
559
684
  running = currentHandle();
560
685
  }
561
686
  if (running !== void 0) {
562
- warnAboutIgnoredOptions(options);
687
+ warnAboutIgnoredOptions(settled);
563
688
  return running;
564
689
  }
565
690
  const joined = pendingStart();
566
691
  if (joined !== void 0) {
567
- warnAboutIgnoredOptions(options);
692
+ warnAboutIgnoredOptions(settled);
568
693
  return joined;
569
694
  }
570
695
  if (hasStopped()) {
@@ -574,7 +699,7 @@ async function startTelemetry(options = {}) {
574
699
  });
575
700
  throw new Error(RESTART_MESSAGE);
576
701
  }
577
- const start = boot(options, env).finally(clearPendingStart);
702
+ const start = boot(settled, env).finally(clearPendingStart);
578
703
  setPendingStart(start);
579
704
  return start;
580
705
  }
@@ -591,10 +716,10 @@ async function loadPackages() {
591
716
  function buildSdk(packages, options, env, read) {
592
717
  const { sdkNode, sdkTrace, autoInstrumentations, exporter, resources } = packages;
593
718
  const signals = planSignals(env);
594
- const { instrumentations, unsafe } = read;
719
+ const { instrumentations, unsafe, service } = read;
595
720
  return new sdkNode.NodeSDK({
596
721
  ...signals.overrides,
597
- resource: resources.resourceFromAttributes(buildResourceAttributes(options, env)),
722
+ resource: resources.resourceFromAttributes(buildResourceAttributes(service, env)),
598
723
  resourceDetectors: selectResourceDetectors(
599
724
  env.resourceDetectors,
600
725
  {
@@ -635,14 +760,15 @@ function buildSdk(packages, options, env, read) {
635
760
  async function boot(options, env) {
636
761
  const unsafe = settleUnsafe(options.unsafe);
637
762
  const instrumentations = settleInstrumentations(options.instrumentations);
763
+ const service = settleService(options);
638
764
  warnAboutUnsafeOptions({ unsafe });
639
- warnAboutMissingServiceName(options, env);
765
+ warnAboutMissingServiceName(service, env);
640
766
  warnAboutOversizedTimers(env);
641
767
  warnAboutSamplerName(readSamplerNearMiss());
642
768
  warnAboutSamplerRatio(readRatioSampler());
643
769
  warnAboutMissingWinstonTransport(instrumentations.sendLogs ?? planSignals(env).sendLogs);
644
770
  const shutdownTimeoutMs = options.shutdownTimeoutMs;
645
- const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe });
771
+ const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe, service });
646
772
  sdk.start();
647
773
  const handle = createHandle(() => sdk.shutdown(), shutdownTimeoutMs);
648
774
  registerHandle(handle);
@@ -166,6 +166,107 @@ async function shutdownTelemetry() {
166
166
  await currentHandle()?.shutdown();
167
167
  }
168
168
 
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
+
169
270
  // src/sdk/assembly.ts
170
271
  var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
171
272
  var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
@@ -206,13 +307,13 @@ function readEachOption(options) {
206
307
  env: options.env
207
308
  };
208
309
  }
209
- function definedEntries(config) {
210
- return Object.fromEntries(Object.entries(config).filter(([, value]) => isPresent(value)));
211
- }
212
310
  function nonBlank(value) {
213
311
  const trimmed = value?.trim();
214
312
  return trimmed === "" ? void 0 : trimmed;
215
313
  }
314
+ function settleService(options) {
315
+ return { serviceName: options.serviceName, serviceVersion: options.serviceVersion };
316
+ }
216
317
  function buildResourceAttributes(options, env) {
217
318
  const attributes = {};
218
319
  const name = env.serviceName ?? nonBlank(options.serviceName);
@@ -222,25 +323,28 @@ function buildResourceAttributes(options, env) {
222
323
  return attributes;
223
324
  }
224
325
  function settleUnsafe(unsafe) {
326
+ const flags = requireObject("unsafe", unsafe);
327
+ const flag = (name) => requireBoolean(`unsafe.${name}`, flags?.[name]) === true;
225
328
  return {
226
- disableUrlRedaction: unsafe?.disableUrlRedaction === true,
227
- disableRedisArgumentRedaction: unsafe?.disableRedisArgumentRedaction === true,
228
- exportProcessCommandArgs: unsafe?.exportProcessCommandArgs === true,
229
- exportHostId: unsafe?.exportHostId === true
329
+ disableUrlRedaction: flag("disableUrlRedaction"),
330
+ disableRedisArgumentRedaction: flag("disableRedisArgumentRedaction"),
331
+ exportProcessCommandArgs: flag("exportProcessCommandArgs"),
332
+ exportHostId: flag("exportHostId")
230
333
  };
231
334
  }
232
335
  function settleInstrumentations(instrumentations) {
336
+ const read = requireObject("instrumentations", instrumentations);
233
337
  return {
234
- fs: instrumentations?.fs,
235
- sendLogs: instrumentations?.sendLogs,
236
- overrides: instrumentations?.overrides
338
+ fs: requireBoolean("instrumentations.fs", read?.fs),
339
+ sendLogs: requireBoolean("instrumentations.sendLogs", read?.sendLogs),
340
+ overrides: settleOverrides("instrumentations.overrides", read?.overrides)
237
341
  };
238
342
  }
239
343
  function buildInstrumentationConfig(options, signals) {
240
344
  const instrumentations = settleInstrumentations(options.instrumentations);
241
345
  const overrides = {};
242
346
  for (const [name, config] of Object.entries(instrumentations.overrides ?? {})) {
243
- if (isPresent(config)) overrides[name] = definedEntries(config);
347
+ overrides[name] = config;
244
348
  }
245
349
  const redactRedis = options.unsafe?.disableRedisArgumentRedaction !== true;
246
350
  const disableLogSending = !(instrumentations.sendLogs ?? signals.sendLogs);
@@ -522,6 +626,26 @@ function selectResourceDetectors(selection, detectors, keeps) {
522
626
  }
523
627
  return [...new Set(chosen)].map((name) => available[name]);
524
628
  }
629
+
630
+ // src/sdk/settle-options.ts
631
+ function settleOptions(options) {
632
+ const read = readEachOption(options);
633
+ const settled = {
634
+ enabled: requireBoolean("enabled", read.enabled),
635
+ serviceName: requireString("serviceName", read.serviceName),
636
+ serviceVersion: requireString("serviceVersion", read.serviceVersion),
637
+ ignoreIncomingRequest: requireFunction("ignoreIncomingRequest", read.ignoreIncomingRequest),
638
+ instrumentations: isGiven(read.instrumentations) ? settleInstrumentations(read.instrumentations) : void 0,
639
+ extraRedactedQueryParams: settleStringList(
640
+ "extraRedactedQueryParams",
641
+ read.extraRedactedQueryParams
642
+ ),
643
+ unsafe: isGiven(read.unsafe) ? settleUnsafe(read.unsafe) : void 0,
644
+ shutdownTimeoutMs: read.shutdownTimeoutMs,
645
+ env: requireObject("env", read.env)
646
+ };
647
+ return Object.fromEntries(Object.entries(settled).filter(([, value]) => isGiven(value)));
648
+ }
525
649
  var TRANSPORT = "@opentelemetry/winston-transport";
526
650
  var BUNDLE = "@opentelemetry/auto-instrumentations-node";
527
651
  var INSTRUMENTATION = "@opentelemetry/instrumentation-winston";
@@ -557,9 +681,10 @@ var DISABLED_HANDLE = {
557
681
  shutdown: () => Promise.resolve()
558
682
  };
559
683
  async function startTelemetry(options = {}) {
560
- const env = readTelemetryEnvironment(options.env ?? void 0);
561
- if (options.enabled === false || env.sdkDisabled) {
562
- if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(options);
684
+ const settled = settleOptions(options);
685
+ const env = readTelemetryEnvironment(settled.env);
686
+ if (settled.enabled === false || env.sdkDisabled) {
687
+ if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(settled);
563
688
  return DISABLED_HANDLE;
564
689
  }
565
690
  let running = currentHandle();
@@ -568,12 +693,12 @@ async function startTelemetry(options = {}) {
568
693
  running = currentHandle();
569
694
  }
570
695
  if (running !== void 0) {
571
- warnAboutIgnoredOptions(options);
696
+ warnAboutIgnoredOptions(settled);
572
697
  return running;
573
698
  }
574
699
  const joined = pendingStart();
575
700
  if (joined !== void 0) {
576
- warnAboutIgnoredOptions(options);
701
+ warnAboutIgnoredOptions(settled);
577
702
  return joined;
578
703
  }
579
704
  if (hasStopped()) {
@@ -583,7 +708,7 @@ async function startTelemetry(options = {}) {
583
708
  });
584
709
  throw new Error(RESTART_MESSAGE);
585
710
  }
586
- const start = boot(options, env).finally(clearPendingStart);
711
+ const start = boot(settled, env).finally(clearPendingStart);
587
712
  setPendingStart(start);
588
713
  return start;
589
714
  }
@@ -600,10 +725,10 @@ async function loadPackages() {
600
725
  function buildSdk(packages, options, env, read) {
601
726
  const { sdkNode, sdkTrace, autoInstrumentations, exporter, resources } = packages;
602
727
  const signals = planSignals(env);
603
- const { instrumentations, unsafe } = read;
728
+ const { instrumentations, unsafe, service } = read;
604
729
  return new sdkNode.NodeSDK({
605
730
  ...signals.overrides,
606
- resource: resources.resourceFromAttributes(buildResourceAttributes(options, env)),
731
+ resource: resources.resourceFromAttributes(buildResourceAttributes(service, env)),
607
732
  resourceDetectors: selectResourceDetectors(
608
733
  env.resourceDetectors,
609
734
  {
@@ -644,14 +769,15 @@ function buildSdk(packages, options, env, read) {
644
769
  async function boot(options, env) {
645
770
  const unsafe = settleUnsafe(options.unsafe);
646
771
  const instrumentations = settleInstrumentations(options.instrumentations);
772
+ const service = settleService(options);
647
773
  warnAboutUnsafeOptions({ unsafe });
648
- warnAboutMissingServiceName(options, env);
774
+ warnAboutMissingServiceName(service, env);
649
775
  warnAboutOversizedTimers(env);
650
776
  warnAboutSamplerName(readSamplerNearMiss());
651
777
  warnAboutSamplerRatio(readRatioSampler());
652
778
  warnAboutMissingWinstonTransport(instrumentations.sendLogs ?? planSignals(env).sendLogs);
653
779
  const shutdownTimeoutMs = options.shutdownTimeoutMs;
654
- const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe });
780
+ const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe, service });
655
781
  sdk.start();
656
782
  const handle = createHandle(() => sdk.shutdown(), shutdownTimeoutMs);
657
783
  registerHandle(handle);
@@ -164,6 +164,107 @@ async function shutdownTelemetry() {
164
164
  await currentHandle()?.shutdown();
165
165
  }
166
166
 
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
+
167
268
  // src/sdk/assembly.ts
168
269
  var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
169
270
  var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
@@ -204,13 +305,13 @@ function readEachOption(options) {
204
305
  env: options.env
205
306
  };
206
307
  }
207
- function definedEntries(config) {
208
- return Object.fromEntries(Object.entries(config).filter(([, value]) => isPresent(value)));
209
- }
210
308
  function nonBlank(value) {
211
309
  const trimmed = value?.trim();
212
310
  return trimmed === "" ? void 0 : trimmed;
213
311
  }
312
+ function settleService(options) {
313
+ return { serviceName: options.serviceName, serviceVersion: options.serviceVersion };
314
+ }
214
315
  function buildResourceAttributes(options, env) {
215
316
  const attributes = {};
216
317
  const name = env.serviceName ?? nonBlank(options.serviceName);
@@ -220,25 +321,28 @@ function buildResourceAttributes(options, env) {
220
321
  return attributes;
221
322
  }
222
323
  function settleUnsafe(unsafe) {
324
+ const flags = requireObject("unsafe", unsafe);
325
+ const flag = (name) => requireBoolean(`unsafe.${name}`, flags?.[name]) === true;
223
326
  return {
224
- disableUrlRedaction: unsafe?.disableUrlRedaction === true,
225
- disableRedisArgumentRedaction: unsafe?.disableRedisArgumentRedaction === true,
226
- exportProcessCommandArgs: unsafe?.exportProcessCommandArgs === true,
227
- exportHostId: unsafe?.exportHostId === true
327
+ disableUrlRedaction: flag("disableUrlRedaction"),
328
+ disableRedisArgumentRedaction: flag("disableRedisArgumentRedaction"),
329
+ exportProcessCommandArgs: flag("exportProcessCommandArgs"),
330
+ exportHostId: flag("exportHostId")
228
331
  };
229
332
  }
230
333
  function settleInstrumentations(instrumentations) {
334
+ const read = requireObject("instrumentations", instrumentations);
231
335
  return {
232
- fs: instrumentations?.fs,
233
- sendLogs: instrumentations?.sendLogs,
234
- overrides: instrumentations?.overrides
336
+ fs: requireBoolean("instrumentations.fs", read?.fs),
337
+ sendLogs: requireBoolean("instrumentations.sendLogs", read?.sendLogs),
338
+ overrides: settleOverrides("instrumentations.overrides", read?.overrides)
235
339
  };
236
340
  }
237
341
  function buildInstrumentationConfig(options, signals) {
238
342
  const instrumentations = settleInstrumentations(options.instrumentations);
239
343
  const overrides = {};
240
344
  for (const [name, config] of Object.entries(instrumentations.overrides ?? {})) {
241
- if (isPresent(config)) overrides[name] = definedEntries(config);
345
+ overrides[name] = config;
242
346
  }
243
347
  const redactRedis = options.unsafe?.disableRedisArgumentRedaction !== true;
244
348
  const disableLogSending = !(instrumentations.sendLogs ?? signals.sendLogs);
@@ -520,6 +624,26 @@ function selectResourceDetectors(selection, detectors, keeps) {
520
624
  }
521
625
  return [...new Set(chosen)].map((name) => available[name]);
522
626
  }
627
+
628
+ // src/sdk/settle-options.ts
629
+ function settleOptions(options) {
630
+ const read = readEachOption(options);
631
+ const settled = {
632
+ enabled: requireBoolean("enabled", read.enabled),
633
+ serviceName: requireString("serviceName", read.serviceName),
634
+ serviceVersion: requireString("serviceVersion", read.serviceVersion),
635
+ ignoreIncomingRequest: requireFunction("ignoreIncomingRequest", read.ignoreIncomingRequest),
636
+ instrumentations: isGiven(read.instrumentations) ? settleInstrumentations(read.instrumentations) : void 0,
637
+ extraRedactedQueryParams: settleStringList(
638
+ "extraRedactedQueryParams",
639
+ read.extraRedactedQueryParams
640
+ ),
641
+ unsafe: isGiven(read.unsafe) ? settleUnsafe(read.unsafe) : void 0,
642
+ shutdownTimeoutMs: read.shutdownTimeoutMs,
643
+ env: requireObject("env", read.env)
644
+ };
645
+ return Object.fromEntries(Object.entries(settled).filter(([, value]) => isGiven(value)));
646
+ }
523
647
  var TRANSPORT = "@opentelemetry/winston-transport";
524
648
  var BUNDLE = "@opentelemetry/auto-instrumentations-node";
525
649
  var INSTRUMENTATION = "@opentelemetry/instrumentation-winston";
@@ -555,9 +679,10 @@ var DISABLED_HANDLE = {
555
679
  shutdown: () => Promise.resolve()
556
680
  };
557
681
  async function startTelemetry(options = {}) {
558
- const env = readTelemetryEnvironment(options.env ?? void 0);
559
- if (options.enabled === false || env.sdkDisabled) {
560
- if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(options);
682
+ const settled = settleOptions(options);
683
+ const env = readTelemetryEnvironment(settled.env);
684
+ if (settled.enabled === false || env.sdkDisabled) {
685
+ if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(settled);
561
686
  return DISABLED_HANDLE;
562
687
  }
563
688
  let running = currentHandle();
@@ -566,12 +691,12 @@ async function startTelemetry(options = {}) {
566
691
  running = currentHandle();
567
692
  }
568
693
  if (running !== void 0) {
569
- warnAboutIgnoredOptions(options);
694
+ warnAboutIgnoredOptions(settled);
570
695
  return running;
571
696
  }
572
697
  const joined = pendingStart();
573
698
  if (joined !== void 0) {
574
- warnAboutIgnoredOptions(options);
699
+ warnAboutIgnoredOptions(settled);
575
700
  return joined;
576
701
  }
577
702
  if (hasStopped()) {
@@ -581,7 +706,7 @@ async function startTelemetry(options = {}) {
581
706
  });
582
707
  throw new Error(RESTART_MESSAGE);
583
708
  }
584
- const start = boot(options, env).finally(clearPendingStart);
709
+ const start = boot(settled, env).finally(clearPendingStart);
585
710
  setPendingStart(start);
586
711
  return start;
587
712
  }
@@ -598,10 +723,10 @@ async function loadPackages() {
598
723
  function buildSdk(packages, options, env, read) {
599
724
  const { sdkNode, sdkTrace, autoInstrumentations, exporter, resources } = packages;
600
725
  const signals = planSignals(env);
601
- const { instrumentations, unsafe } = read;
726
+ const { instrumentations, unsafe, service } = read;
602
727
  return new sdkNode.NodeSDK({
603
728
  ...signals.overrides,
604
- resource: resources.resourceFromAttributes(buildResourceAttributes(options, env)),
729
+ resource: resources.resourceFromAttributes(buildResourceAttributes(service, env)),
605
730
  resourceDetectors: selectResourceDetectors(
606
731
  env.resourceDetectors,
607
732
  {
@@ -642,14 +767,15 @@ function buildSdk(packages, options, env, read) {
642
767
  async function boot(options, env) {
643
768
  const unsafe = settleUnsafe(options.unsafe);
644
769
  const instrumentations = settleInstrumentations(options.instrumentations);
770
+ const service = settleService(options);
645
771
  warnAboutUnsafeOptions({ unsafe });
646
- warnAboutMissingServiceName(options, env);
772
+ warnAboutMissingServiceName(service, env);
647
773
  warnAboutOversizedTimers(env);
648
774
  warnAboutSamplerName(readSamplerNearMiss());
649
775
  warnAboutSamplerRatio(readRatioSampler());
650
776
  warnAboutMissingWinstonTransport(instrumentations.sendLogs ?? planSignals(env).sendLogs);
651
777
  const shutdownTimeoutMs = options.shutdownTimeoutMs;
652
- const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe });
778
+ const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe, service });
653
779
  sdk.start();
654
780
  const handle = createHandle(() => sdk.shutdown(), shutdownTimeoutMs);
655
781
  registerHandle(handle);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-telemetry",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
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",