@bymax-one/nest-telemetry 1.0.9 → 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 +61 -1
- package/README.md +13 -9
- package/dist/register/index.mjs +169 -21
- package/dist/sdk/index.cjs +200 -22
- package/dist/sdk/index.d.cts +0 -5
- package/dist/sdk/index.d.ts +0 -5
- package/dist/sdk/index.mjs +200 -22
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,65 @@ 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
|
-
## [
|
|
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
|
+
|
|
36
|
+
## [1.0.10] - 2026-11-21
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- **An option of the wrong kind is refused, and no longer read as something it is not.** The string `'false'`, a
|
|
41
|
+
number or an object for `instrumentations.sendLogs` was truthy and turned the export of log records on, which
|
|
42
|
+
sends data off the host; the string `'true'` for an `unsafe` flag was dropped without a word; a string for
|
|
43
|
+
`extraRedactedQueryParams` was spread into its characters and a number threw a `TypeError` out of the start.
|
|
44
|
+
`startTelemetry` now rejects with an error whose `code` is `BYMAX_TELEMETRY_OPTION_INVALID` and whose `option`
|
|
45
|
+
names the option, before any SDK is started. `shutdownTimeoutMs` keeps its documented fallback.
|
|
46
|
+
- **The settings of an `instrumentations.overrides` entry that decide what leaves the host are checked too.** An
|
|
47
|
+
override was spread over the library's configuration unchecked, so `{ disableLogSending: 0 }` for the pino
|
|
48
|
+
instrumentation turned log sending on and a non-boolean `enabled` replaced the one the library forces. Each
|
|
49
|
+
entry is now copied once; `enabled` and `disableLogSending` must be booleans, `redactedQueryParams` an array
|
|
50
|
+
of strings, every setting named `...Hook` a function, an entry holds at most 1000 settings, and a `__proto__` key is refused. The error names
|
|
51
|
+
`instrumentations.overrides[]` and never the instrumentation or the value.
|
|
52
|
+
- **Each option of a call is read once.** A getter could make a warning and the effect of the call disagree. A
|
|
53
|
+
call now reads each option once, checks its kind, and works from the copy.
|
|
54
|
+
|
|
55
|
+
### Documentation
|
|
56
|
+
|
|
57
|
+
- **The README says a failed start starts no new SDK.** It said "no SDK started and no handle left", which is
|
|
58
|
+
wrong for a later call that finds an SDK already running; it now says that the failed start starts no new SDK
|
|
59
|
+
and that a first start leaves no handle.
|
|
60
|
+
- **The README lists the ranges of the peers that are not OpenTelemetry packages**, as `package.json` declares
|
|
61
|
+
them, and its CPU item no longer says "that handler".
|
|
62
|
+
|
|
63
|
+
### Apply to a derived backend
|
|
64
|
+
|
|
65
|
+
A configuration that passed a value of the wrong kind used to be accepted and now fails at start with
|
|
66
|
+
`BYMAX_TELEMETRY_OPTION_INVALID`. Look for a string such as `'false'` in `instrumentations.sendLogs` or an `unsafe`
|
|
67
|
+
flag (read from an environment variable without converting it), a single string for `extraRedactedQueryParams`
|
|
68
|
+
(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
|
|
69
|
+
the documented kind behaves as before.
|
|
12
70
|
|
|
13
71
|
## [1.0.9] - 2026-11-20
|
|
14
72
|
|
|
@@ -411,6 +469,8 @@ First release.
|
|
|
411
469
|
- Verification from the packed tarball: real `node --import` processes in a CommonJS and a native-ESM
|
|
412
470
|
application, with planted secrets absent from the exported body and negative controls.
|
|
413
471
|
|
|
472
|
+
[1.0.11]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.11
|
|
473
|
+
[1.0.10]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.10
|
|
414
474
|
[1.0.9]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.9
|
|
415
475
|
[1.0.8]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.8
|
|
416
476
|
[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
|
-
|
|
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
|
+
|
|
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
|
|
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
|
|
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` 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.
|
|
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
|
package/dist/register/index.mjs
CHANGED
|
@@ -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,6 +95,128 @@ function describeFailure(error) {
|
|
|
94
95
|
return code;
|
|
95
96
|
}
|
|
96
97
|
}
|
|
98
|
+
var isIndex = (key) => String(Number(key) >>> 0) === key && key !== "4294967295";
|
|
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
|
+
* @param cause - The error of the host's own value that made the option unusable.
|
|
105
|
+
*/
|
|
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
|
+
);
|
|
111
|
+
/** The stable code of this error. */
|
|
112
|
+
this.code = "BYMAX_TELEMETRY_OPTION_INVALID";
|
|
113
|
+
this.name = "TelemetryOptionError";
|
|
114
|
+
this.option = option;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function isGiven(value) {
|
|
118
|
+
return value !== void 0 && value !== null;
|
|
119
|
+
}
|
|
120
|
+
function requireBoolean(option, value) {
|
|
121
|
+
if (!isGiven(value)) return void 0;
|
|
122
|
+
if (typeof value !== "boolean") throw new TelemetryOptionError(option, "a boolean");
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function requireString(option, value) {
|
|
126
|
+
if (!isGiven(value)) return void 0;
|
|
127
|
+
if (typeof value !== "string") throw new TelemetryOptionError(option, "a string");
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
function requireFunction(option, value) {
|
|
131
|
+
if (!isGiven(value)) return void 0;
|
|
132
|
+
if (typeof value !== "function") throw new TelemetryOptionError(option, "a function");
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
function requireObject(option, value) {
|
|
136
|
+
if (value === void 0 || value === null) return void 0;
|
|
137
|
+
if (typeof value !== "object" || Array.isArray(value) || isOtherKind(value)) {
|
|
138
|
+
throw new TelemetryOptionError(option, "an object");
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
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) {
|
|
146
|
+
if (!isGiven(value)) return void 0;
|
|
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);
|
|
154
|
+
if (typeof length !== "number" || !Number.isInteger(length) || length < 0) {
|
|
155
|
+
throw new TelemetryOptionError(option, expected);
|
|
156
|
+
}
|
|
157
|
+
if (length > MAX_OPTION_ENTRIES) {
|
|
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);
|
|
162
|
+
}
|
|
163
|
+
const copy = [];
|
|
164
|
+
for (let index = 0; index < length; index++) {
|
|
165
|
+
const taken = take(host(() => list[index]));
|
|
166
|
+
if (taken === void 0) throw new TelemetryOptionError(option, expected);
|
|
167
|
+
copy.push(taken);
|
|
168
|
+
}
|
|
169
|
+
return copy;
|
|
170
|
+
}
|
|
171
|
+
function settleStringList(option, value) {
|
|
172
|
+
return copyByIndex(
|
|
173
|
+
option,
|
|
174
|
+
value,
|
|
175
|
+
"strings",
|
|
176
|
+
(entry) => typeof entry === "string" ? entry : void 0);
|
|
177
|
+
}
|
|
178
|
+
var OVERRIDE_PATH = "instrumentations.overrides[]";
|
|
179
|
+
function refuseProtoKey(key) {
|
|
180
|
+
if (key === "__proto__") throw new TelemetryOptionError(OVERRIDE_PATH, "free of a __proto__ key");
|
|
181
|
+
}
|
|
182
|
+
function settleOverrideEntry(entry) {
|
|
183
|
+
const settings = Object.entries(entry);
|
|
184
|
+
if (settings.length > MAX_OPTION_ENTRIES) {
|
|
185
|
+
throw new TelemetryOptionError(
|
|
186
|
+
OVERRIDE_PATH,
|
|
187
|
+
`an object of at most ${MAX_OPTION_ENTRIES} settings`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const copy = {};
|
|
191
|
+
for (const [key, setting] of settings) {
|
|
192
|
+
refuseProtoKey(key);
|
|
193
|
+
let settled = setting;
|
|
194
|
+
if (key === "enabled" || key === "disableLogSending") {
|
|
195
|
+
settled = requireBoolean(`${OVERRIDE_PATH}.${key}`, setting);
|
|
196
|
+
} else if (key === "redactedQueryParams") {
|
|
197
|
+
settled = settleStringList(`${OVERRIDE_PATH}.${key}`, setting);
|
|
198
|
+
} else if (key.endsWith("Hook")) {
|
|
199
|
+
settled = requireFunction(`${OVERRIDE_PATH}.<a hook>`, setting);
|
|
200
|
+
}
|
|
201
|
+
if (isGiven(settled)) copy[key] = settled;
|
|
202
|
+
}
|
|
203
|
+
return copy;
|
|
204
|
+
}
|
|
205
|
+
function settleOverrides(option, value) {
|
|
206
|
+
const map = requireObject(option, value);
|
|
207
|
+
if (map === void 0) return void 0;
|
|
208
|
+
const entries = Object.entries(map);
|
|
209
|
+
if (entries.length > MAX_OPTION_ENTRIES) {
|
|
210
|
+
throw new TelemetryOptionError(option, `an object of at most ${MAX_OPTION_ENTRIES} entries`);
|
|
211
|
+
}
|
|
212
|
+
const copy = {};
|
|
213
|
+
for (const [name, entry] of entries) {
|
|
214
|
+
refuseProtoKey(name);
|
|
215
|
+
const config = requireObject(option, entry);
|
|
216
|
+
if (config !== void 0) copy[name] = settleOverrideEntry(config);
|
|
217
|
+
}
|
|
218
|
+
return copy;
|
|
219
|
+
}
|
|
97
220
|
|
|
98
221
|
// src/sdk/redaction.ts
|
|
99
222
|
var REDACTED_QUERY_VALUE = "[redacted]";
|
|
@@ -206,13 +329,13 @@ function readEachOption(options) {
|
|
|
206
329
|
env: options.env
|
|
207
330
|
};
|
|
208
331
|
}
|
|
209
|
-
function definedEntries(config) {
|
|
210
|
-
return Object.fromEntries(Object.entries(config).filter(([, value]) => isPresent(value)));
|
|
211
|
-
}
|
|
212
332
|
function nonBlank(value) {
|
|
213
333
|
const trimmed = value?.trim();
|
|
214
334
|
return trimmed === "" ? void 0 : trimmed;
|
|
215
335
|
}
|
|
336
|
+
function settleService(options) {
|
|
337
|
+
return { serviceName: options.serviceName, serviceVersion: options.serviceVersion };
|
|
338
|
+
}
|
|
216
339
|
function buildResourceAttributes(options, env) {
|
|
217
340
|
const attributes = {};
|
|
218
341
|
const name = env.serviceName ?? nonBlank(options.serviceName);
|
|
@@ -222,25 +345,28 @@ function buildResourceAttributes(options, env) {
|
|
|
222
345
|
return attributes;
|
|
223
346
|
}
|
|
224
347
|
function settleUnsafe(unsafe) {
|
|
348
|
+
const flags = requireObject("unsafe", unsafe);
|
|
349
|
+
const flag = (name) => requireBoolean(`unsafe.${name}`, flags?.[name]) === true;
|
|
225
350
|
return {
|
|
226
|
-
disableUrlRedaction:
|
|
227
|
-
disableRedisArgumentRedaction:
|
|
228
|
-
exportProcessCommandArgs:
|
|
229
|
-
exportHostId:
|
|
351
|
+
disableUrlRedaction: flag("disableUrlRedaction"),
|
|
352
|
+
disableRedisArgumentRedaction: flag("disableRedisArgumentRedaction"),
|
|
353
|
+
exportProcessCommandArgs: flag("exportProcessCommandArgs"),
|
|
354
|
+
exportHostId: flag("exportHostId")
|
|
230
355
|
};
|
|
231
356
|
}
|
|
232
357
|
function settleInstrumentations(instrumentations) {
|
|
358
|
+
const read = requireObject("instrumentations", instrumentations);
|
|
233
359
|
return {
|
|
234
|
-
fs: instrumentations?.fs,
|
|
235
|
-
sendLogs: instrumentations?.sendLogs,
|
|
236
|
-
overrides: instrumentations?.overrides
|
|
360
|
+
fs: requireBoolean("instrumentations.fs", read?.fs),
|
|
361
|
+
sendLogs: requireBoolean("instrumentations.sendLogs", read?.sendLogs),
|
|
362
|
+
overrides: settleOverrides("instrumentations.overrides", read?.overrides)
|
|
237
363
|
};
|
|
238
364
|
}
|
|
239
365
|
function buildInstrumentationConfig(options, signals) {
|
|
240
366
|
const instrumentations = settleInstrumentations(options.instrumentations);
|
|
241
367
|
const overrides = {};
|
|
242
368
|
for (const [name, config] of Object.entries(instrumentations.overrides ?? {})) {
|
|
243
|
-
|
|
369
|
+
overrides[name] = config;
|
|
244
370
|
}
|
|
245
371
|
const redactRedis = options.unsafe?.disableRedisArgumentRedaction !== true;
|
|
246
372
|
const disableLogSending = !(instrumentations.sendLogs ?? signals.sendLogs);
|
|
@@ -513,6 +639,26 @@ function selectResourceDetectors(selection, detectors, keeps) {
|
|
|
513
639
|
}
|
|
514
640
|
return [...new Set(chosen)].map((name) => available[name]);
|
|
515
641
|
}
|
|
642
|
+
|
|
643
|
+
// src/sdk/settle-options.ts
|
|
644
|
+
function settleOptions(options) {
|
|
645
|
+
const read = readEachOption(options);
|
|
646
|
+
const settled = {
|
|
647
|
+
enabled: requireBoolean("enabled", read.enabled),
|
|
648
|
+
serviceName: requireString("serviceName", read.serviceName),
|
|
649
|
+
serviceVersion: requireString("serviceVersion", read.serviceVersion),
|
|
650
|
+
ignoreIncomingRequest: requireFunction("ignoreIncomingRequest", read.ignoreIncomingRequest),
|
|
651
|
+
instrumentations: isGiven(read.instrumentations) ? settleInstrumentations(read.instrumentations) : void 0,
|
|
652
|
+
extraRedactedQueryParams: settleStringList(
|
|
653
|
+
"extraRedactedQueryParams",
|
|
654
|
+
read.extraRedactedQueryParams
|
|
655
|
+
),
|
|
656
|
+
unsafe: isGiven(read.unsafe) ? settleUnsafe(read.unsafe) : void 0,
|
|
657
|
+
shutdownTimeoutMs: read.shutdownTimeoutMs,
|
|
658
|
+
env: requireObject("env", read.env)
|
|
659
|
+
};
|
|
660
|
+
return Object.fromEntries(Object.entries(settled).filter(([, value]) => isGiven(value)));
|
|
661
|
+
}
|
|
516
662
|
var TRANSPORT = "@opentelemetry/winston-transport";
|
|
517
663
|
var BUNDLE = "@opentelemetry/auto-instrumentations-node";
|
|
518
664
|
var INSTRUMENTATION = "@opentelemetry/instrumentation-winston";
|
|
@@ -548,9 +694,10 @@ var DISABLED_HANDLE = {
|
|
|
548
694
|
shutdown: () => Promise.resolve()
|
|
549
695
|
};
|
|
550
696
|
async function startTelemetry(options = {}) {
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
697
|
+
const settled = settleOptions(options);
|
|
698
|
+
const env = readTelemetryEnvironment(settled.env);
|
|
699
|
+
if (settled.enabled === false || env.sdkDisabled) {
|
|
700
|
+
if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(settled);
|
|
554
701
|
return DISABLED_HANDLE;
|
|
555
702
|
}
|
|
556
703
|
let running = currentHandle();
|
|
@@ -559,12 +706,12 @@ async function startTelemetry(options = {}) {
|
|
|
559
706
|
running = currentHandle();
|
|
560
707
|
}
|
|
561
708
|
if (running !== void 0) {
|
|
562
|
-
warnAboutIgnoredOptions(
|
|
709
|
+
warnAboutIgnoredOptions(settled);
|
|
563
710
|
return running;
|
|
564
711
|
}
|
|
565
712
|
const joined = pendingStart();
|
|
566
713
|
if (joined !== void 0) {
|
|
567
|
-
warnAboutIgnoredOptions(
|
|
714
|
+
warnAboutIgnoredOptions(settled);
|
|
568
715
|
return joined;
|
|
569
716
|
}
|
|
570
717
|
if (hasStopped()) {
|
|
@@ -574,7 +721,7 @@ async function startTelemetry(options = {}) {
|
|
|
574
721
|
});
|
|
575
722
|
throw new Error(RESTART_MESSAGE);
|
|
576
723
|
}
|
|
577
|
-
const start = boot(
|
|
724
|
+
const start = boot(settled, env).finally(clearPendingStart);
|
|
578
725
|
setPendingStart(start);
|
|
579
726
|
return start;
|
|
580
727
|
}
|
|
@@ -591,10 +738,10 @@ async function loadPackages() {
|
|
|
591
738
|
function buildSdk(packages, options, env, read) {
|
|
592
739
|
const { sdkNode, sdkTrace, autoInstrumentations, exporter, resources } = packages;
|
|
593
740
|
const signals = planSignals(env);
|
|
594
|
-
const { instrumentations, unsafe } = read;
|
|
741
|
+
const { instrumentations, unsafe, service } = read;
|
|
595
742
|
return new sdkNode.NodeSDK({
|
|
596
743
|
...signals.overrides,
|
|
597
|
-
resource: resources.resourceFromAttributes(buildResourceAttributes(
|
|
744
|
+
resource: resources.resourceFromAttributes(buildResourceAttributes(service, env)),
|
|
598
745
|
resourceDetectors: selectResourceDetectors(
|
|
599
746
|
env.resourceDetectors,
|
|
600
747
|
{
|
|
@@ -635,14 +782,15 @@ function buildSdk(packages, options, env, read) {
|
|
|
635
782
|
async function boot(options, env) {
|
|
636
783
|
const unsafe = settleUnsafe(options.unsafe);
|
|
637
784
|
const instrumentations = settleInstrumentations(options.instrumentations);
|
|
785
|
+
const service = settleService(options);
|
|
638
786
|
warnAboutUnsafeOptions({ unsafe });
|
|
639
|
-
warnAboutMissingServiceName(
|
|
787
|
+
warnAboutMissingServiceName(service, env);
|
|
640
788
|
warnAboutOversizedTimers(env);
|
|
641
789
|
warnAboutSamplerName(readSamplerNearMiss());
|
|
642
790
|
warnAboutSamplerRatio(readRatioSampler());
|
|
643
791
|
warnAboutMissingWinstonTransport(instrumentations.sendLogs ?? planSignals(env).sendLogs);
|
|
644
792
|
const shutdownTimeoutMs = options.shutdownTimeoutMs;
|
|
645
|
-
const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe });
|
|
793
|
+
const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe, service });
|
|
646
794
|
sdk.start();
|
|
647
795
|
const handle = createHandle(() => sdk.shutdown(), shutdownTimeoutMs);
|
|
648
796
|
registerHandle(handle);
|
package/dist/sdk/index.cjs
CHANGED
|
@@ -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
|
|
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) => {
|
|
@@ -206,13 +359,13 @@ function readEachOption(options) {
|
|
|
206
359
|
env: options.env
|
|
207
360
|
};
|
|
208
361
|
}
|
|
209
|
-
function definedEntries(config) {
|
|
210
|
-
return Object.fromEntries(Object.entries(config).filter(([, value]) => isPresent(value)));
|
|
211
|
-
}
|
|
212
362
|
function nonBlank(value) {
|
|
213
363
|
const trimmed = value?.trim();
|
|
214
364
|
return trimmed === "" ? void 0 : trimmed;
|
|
215
365
|
}
|
|
366
|
+
function settleService(options) {
|
|
367
|
+
return { serviceName: options.serviceName, serviceVersion: options.serviceVersion };
|
|
368
|
+
}
|
|
216
369
|
function buildResourceAttributes(options, env) {
|
|
217
370
|
const attributes = {};
|
|
218
371
|
const name = env.serviceName ?? nonBlank(options.serviceName);
|
|
@@ -222,25 +375,28 @@ function buildResourceAttributes(options, env) {
|
|
|
222
375
|
return attributes;
|
|
223
376
|
}
|
|
224
377
|
function settleUnsafe(unsafe) {
|
|
378
|
+
const flags = requireObject("unsafe", unsafe);
|
|
379
|
+
const flag = (name) => requireBoolean(`unsafe.${name}`, flags?.[name]) === true;
|
|
225
380
|
return {
|
|
226
|
-
disableUrlRedaction:
|
|
227
|
-
disableRedisArgumentRedaction:
|
|
228
|
-
exportProcessCommandArgs:
|
|
229
|
-
exportHostId:
|
|
381
|
+
disableUrlRedaction: flag("disableUrlRedaction"),
|
|
382
|
+
disableRedisArgumentRedaction: flag("disableRedisArgumentRedaction"),
|
|
383
|
+
exportProcessCommandArgs: flag("exportProcessCommandArgs"),
|
|
384
|
+
exportHostId: flag("exportHostId")
|
|
230
385
|
};
|
|
231
386
|
}
|
|
232
387
|
function settleInstrumentations(instrumentations) {
|
|
388
|
+
const read = requireObject("instrumentations", instrumentations);
|
|
233
389
|
return {
|
|
234
|
-
fs: instrumentations?.fs,
|
|
235
|
-
sendLogs: instrumentations?.sendLogs,
|
|
236
|
-
overrides: instrumentations?.overrides
|
|
390
|
+
fs: requireBoolean("instrumentations.fs", read?.fs),
|
|
391
|
+
sendLogs: requireBoolean("instrumentations.sendLogs", read?.sendLogs),
|
|
392
|
+
overrides: settleOverrides("instrumentations.overrides", read?.overrides)
|
|
237
393
|
};
|
|
238
394
|
}
|
|
239
395
|
function buildInstrumentationConfig(options, signals) {
|
|
240
396
|
const instrumentations = settleInstrumentations(options.instrumentations);
|
|
241
397
|
const overrides = {};
|
|
242
398
|
for (const [name, config] of Object.entries(instrumentations.overrides ?? {})) {
|
|
243
|
-
|
|
399
|
+
overrides[name] = config;
|
|
244
400
|
}
|
|
245
401
|
const redactRedis = options.unsafe?.disableRedisArgumentRedaction !== true;
|
|
246
402
|
const disableLogSending = !(instrumentations.sendLogs ?? signals.sendLogs);
|
|
@@ -522,6 +678,26 @@ function selectResourceDetectors(selection, detectors, keeps) {
|
|
|
522
678
|
}
|
|
523
679
|
return [...new Set(chosen)].map((name) => available[name]);
|
|
524
680
|
}
|
|
681
|
+
|
|
682
|
+
// src/sdk/settle-options.ts
|
|
683
|
+
function settleOptions(options) {
|
|
684
|
+
const read = readEachOption(options);
|
|
685
|
+
const settled = {
|
|
686
|
+
enabled: requireBoolean("enabled", read.enabled),
|
|
687
|
+
serviceName: requireString("serviceName", read.serviceName),
|
|
688
|
+
serviceVersion: requireString("serviceVersion", read.serviceVersion),
|
|
689
|
+
ignoreIncomingRequest: requireFunction("ignoreIncomingRequest", read.ignoreIncomingRequest),
|
|
690
|
+
instrumentations: isGiven(read.instrumentations) ? settleInstrumentations(read.instrumentations) : void 0,
|
|
691
|
+
extraRedactedQueryParams: settleStringList(
|
|
692
|
+
"extraRedactedQueryParams",
|
|
693
|
+
read.extraRedactedQueryParams
|
|
694
|
+
),
|
|
695
|
+
unsafe: isGiven(read.unsafe) ? settleUnsafe(read.unsafe) : void 0,
|
|
696
|
+
shutdownTimeoutMs: read.shutdownTimeoutMs,
|
|
697
|
+
env: requireObject("env", read.env)
|
|
698
|
+
};
|
|
699
|
+
return Object.fromEntries(Object.entries(settled).filter(([, value]) => isGiven(value)));
|
|
700
|
+
}
|
|
525
701
|
var TRANSPORT = "@opentelemetry/winston-transport";
|
|
526
702
|
var BUNDLE = "@opentelemetry/auto-instrumentations-node";
|
|
527
703
|
var INSTRUMENTATION = "@opentelemetry/instrumentation-winston";
|
|
@@ -557,9 +733,10 @@ var DISABLED_HANDLE = {
|
|
|
557
733
|
shutdown: () => Promise.resolve()
|
|
558
734
|
};
|
|
559
735
|
async function startTelemetry(options = {}) {
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
736
|
+
const settled = settleOptions(options);
|
|
737
|
+
const env = readTelemetryEnvironment(settled.env);
|
|
738
|
+
if (settled.enabled === false || env.sdkDisabled) {
|
|
739
|
+
if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(settled);
|
|
563
740
|
return DISABLED_HANDLE;
|
|
564
741
|
}
|
|
565
742
|
let running = currentHandle();
|
|
@@ -568,12 +745,12 @@ async function startTelemetry(options = {}) {
|
|
|
568
745
|
running = currentHandle();
|
|
569
746
|
}
|
|
570
747
|
if (running !== void 0) {
|
|
571
|
-
warnAboutIgnoredOptions(
|
|
748
|
+
warnAboutIgnoredOptions(settled);
|
|
572
749
|
return running;
|
|
573
750
|
}
|
|
574
751
|
const joined = pendingStart();
|
|
575
752
|
if (joined !== void 0) {
|
|
576
|
-
warnAboutIgnoredOptions(
|
|
753
|
+
warnAboutIgnoredOptions(settled);
|
|
577
754
|
return joined;
|
|
578
755
|
}
|
|
579
756
|
if (hasStopped()) {
|
|
@@ -583,7 +760,7 @@ async function startTelemetry(options = {}) {
|
|
|
583
760
|
});
|
|
584
761
|
throw new Error(RESTART_MESSAGE);
|
|
585
762
|
}
|
|
586
|
-
const start = boot(
|
|
763
|
+
const start = boot(settled, env).finally(clearPendingStart);
|
|
587
764
|
setPendingStart(start);
|
|
588
765
|
return start;
|
|
589
766
|
}
|
|
@@ -600,10 +777,10 @@ async function loadPackages() {
|
|
|
600
777
|
function buildSdk(packages, options, env, read) {
|
|
601
778
|
const { sdkNode, sdkTrace, autoInstrumentations, exporter, resources } = packages;
|
|
602
779
|
const signals = planSignals(env);
|
|
603
|
-
const { instrumentations, unsafe } = read;
|
|
780
|
+
const { instrumentations, unsafe, service } = read;
|
|
604
781
|
return new sdkNode.NodeSDK({
|
|
605
782
|
...signals.overrides,
|
|
606
|
-
resource: resources.resourceFromAttributes(buildResourceAttributes(
|
|
783
|
+
resource: resources.resourceFromAttributes(buildResourceAttributes(service, env)),
|
|
607
784
|
resourceDetectors: selectResourceDetectors(
|
|
608
785
|
env.resourceDetectors,
|
|
609
786
|
{
|
|
@@ -644,14 +821,15 @@ function buildSdk(packages, options, env, read) {
|
|
|
644
821
|
async function boot(options, env) {
|
|
645
822
|
const unsafe = settleUnsafe(options.unsafe);
|
|
646
823
|
const instrumentations = settleInstrumentations(options.instrumentations);
|
|
824
|
+
const service = settleService(options);
|
|
647
825
|
warnAboutUnsafeOptions({ unsafe });
|
|
648
|
-
warnAboutMissingServiceName(
|
|
826
|
+
warnAboutMissingServiceName(service, env);
|
|
649
827
|
warnAboutOversizedTimers(env);
|
|
650
828
|
warnAboutSamplerName(readSamplerNearMiss());
|
|
651
829
|
warnAboutSamplerRatio(readRatioSampler());
|
|
652
830
|
warnAboutMissingWinstonTransport(instrumentations.sendLogs ?? planSignals(env).sendLogs);
|
|
653
831
|
const shutdownTimeoutMs = options.shutdownTimeoutMs;
|
|
654
|
-
const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe });
|
|
832
|
+
const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe, service });
|
|
655
833
|
sdk.start();
|
|
656
834
|
const handle = createHandle(() => sdk.shutdown(), shutdownTimeoutMs);
|
|
657
835
|
registerHandle(handle);
|
package/dist/sdk/index.d.cts
CHANGED
|
@@ -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
|
*
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -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
|
|
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) => {
|
|
@@ -204,13 +357,13 @@ function readEachOption(options) {
|
|
|
204
357
|
env: options.env
|
|
205
358
|
};
|
|
206
359
|
}
|
|
207
|
-
function definedEntries(config) {
|
|
208
|
-
return Object.fromEntries(Object.entries(config).filter(([, value]) => isPresent(value)));
|
|
209
|
-
}
|
|
210
360
|
function nonBlank(value) {
|
|
211
361
|
const trimmed = value?.trim();
|
|
212
362
|
return trimmed === "" ? void 0 : trimmed;
|
|
213
363
|
}
|
|
364
|
+
function settleService(options) {
|
|
365
|
+
return { serviceName: options.serviceName, serviceVersion: options.serviceVersion };
|
|
366
|
+
}
|
|
214
367
|
function buildResourceAttributes(options, env) {
|
|
215
368
|
const attributes = {};
|
|
216
369
|
const name = env.serviceName ?? nonBlank(options.serviceName);
|
|
@@ -220,25 +373,28 @@ function buildResourceAttributes(options, env) {
|
|
|
220
373
|
return attributes;
|
|
221
374
|
}
|
|
222
375
|
function settleUnsafe(unsafe) {
|
|
376
|
+
const flags = requireObject("unsafe", unsafe);
|
|
377
|
+
const flag = (name) => requireBoolean(`unsafe.${name}`, flags?.[name]) === true;
|
|
223
378
|
return {
|
|
224
|
-
disableUrlRedaction:
|
|
225
|
-
disableRedisArgumentRedaction:
|
|
226
|
-
exportProcessCommandArgs:
|
|
227
|
-
exportHostId:
|
|
379
|
+
disableUrlRedaction: flag("disableUrlRedaction"),
|
|
380
|
+
disableRedisArgumentRedaction: flag("disableRedisArgumentRedaction"),
|
|
381
|
+
exportProcessCommandArgs: flag("exportProcessCommandArgs"),
|
|
382
|
+
exportHostId: flag("exportHostId")
|
|
228
383
|
};
|
|
229
384
|
}
|
|
230
385
|
function settleInstrumentations(instrumentations) {
|
|
386
|
+
const read = requireObject("instrumentations", instrumentations);
|
|
231
387
|
return {
|
|
232
|
-
fs: instrumentations?.fs,
|
|
233
|
-
sendLogs: instrumentations?.sendLogs,
|
|
234
|
-
overrides: instrumentations?.overrides
|
|
388
|
+
fs: requireBoolean("instrumentations.fs", read?.fs),
|
|
389
|
+
sendLogs: requireBoolean("instrumentations.sendLogs", read?.sendLogs),
|
|
390
|
+
overrides: settleOverrides("instrumentations.overrides", read?.overrides)
|
|
235
391
|
};
|
|
236
392
|
}
|
|
237
393
|
function buildInstrumentationConfig(options, signals) {
|
|
238
394
|
const instrumentations = settleInstrumentations(options.instrumentations);
|
|
239
395
|
const overrides = {};
|
|
240
396
|
for (const [name, config] of Object.entries(instrumentations.overrides ?? {})) {
|
|
241
|
-
|
|
397
|
+
overrides[name] = config;
|
|
242
398
|
}
|
|
243
399
|
const redactRedis = options.unsafe?.disableRedisArgumentRedaction !== true;
|
|
244
400
|
const disableLogSending = !(instrumentations.sendLogs ?? signals.sendLogs);
|
|
@@ -520,6 +676,26 @@ function selectResourceDetectors(selection, detectors, keeps) {
|
|
|
520
676
|
}
|
|
521
677
|
return [...new Set(chosen)].map((name) => available[name]);
|
|
522
678
|
}
|
|
679
|
+
|
|
680
|
+
// src/sdk/settle-options.ts
|
|
681
|
+
function settleOptions(options) {
|
|
682
|
+
const read = readEachOption(options);
|
|
683
|
+
const settled = {
|
|
684
|
+
enabled: requireBoolean("enabled", read.enabled),
|
|
685
|
+
serviceName: requireString("serviceName", read.serviceName),
|
|
686
|
+
serviceVersion: requireString("serviceVersion", read.serviceVersion),
|
|
687
|
+
ignoreIncomingRequest: requireFunction("ignoreIncomingRequest", read.ignoreIncomingRequest),
|
|
688
|
+
instrumentations: isGiven(read.instrumentations) ? settleInstrumentations(read.instrumentations) : void 0,
|
|
689
|
+
extraRedactedQueryParams: settleStringList(
|
|
690
|
+
"extraRedactedQueryParams",
|
|
691
|
+
read.extraRedactedQueryParams
|
|
692
|
+
),
|
|
693
|
+
unsafe: isGiven(read.unsafe) ? settleUnsafe(read.unsafe) : void 0,
|
|
694
|
+
shutdownTimeoutMs: read.shutdownTimeoutMs,
|
|
695
|
+
env: requireObject("env", read.env)
|
|
696
|
+
};
|
|
697
|
+
return Object.fromEntries(Object.entries(settled).filter(([, value]) => isGiven(value)));
|
|
698
|
+
}
|
|
523
699
|
var TRANSPORT = "@opentelemetry/winston-transport";
|
|
524
700
|
var BUNDLE = "@opentelemetry/auto-instrumentations-node";
|
|
525
701
|
var INSTRUMENTATION = "@opentelemetry/instrumentation-winston";
|
|
@@ -555,9 +731,10 @@ var DISABLED_HANDLE = {
|
|
|
555
731
|
shutdown: () => Promise.resolve()
|
|
556
732
|
};
|
|
557
733
|
async function startTelemetry(options = {}) {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
734
|
+
const settled = settleOptions(options);
|
|
735
|
+
const env = readTelemetryEnvironment(settled.env);
|
|
736
|
+
if (settled.enabled === false || env.sdkDisabled) {
|
|
737
|
+
if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(settled);
|
|
561
738
|
return DISABLED_HANDLE;
|
|
562
739
|
}
|
|
563
740
|
let running = currentHandle();
|
|
@@ -566,12 +743,12 @@ async function startTelemetry(options = {}) {
|
|
|
566
743
|
running = currentHandle();
|
|
567
744
|
}
|
|
568
745
|
if (running !== void 0) {
|
|
569
|
-
warnAboutIgnoredOptions(
|
|
746
|
+
warnAboutIgnoredOptions(settled);
|
|
570
747
|
return running;
|
|
571
748
|
}
|
|
572
749
|
const joined = pendingStart();
|
|
573
750
|
if (joined !== void 0) {
|
|
574
|
-
warnAboutIgnoredOptions(
|
|
751
|
+
warnAboutIgnoredOptions(settled);
|
|
575
752
|
return joined;
|
|
576
753
|
}
|
|
577
754
|
if (hasStopped()) {
|
|
@@ -581,7 +758,7 @@ async function startTelemetry(options = {}) {
|
|
|
581
758
|
});
|
|
582
759
|
throw new Error(RESTART_MESSAGE);
|
|
583
760
|
}
|
|
584
|
-
const start = boot(
|
|
761
|
+
const start = boot(settled, env).finally(clearPendingStart);
|
|
585
762
|
setPendingStart(start);
|
|
586
763
|
return start;
|
|
587
764
|
}
|
|
@@ -598,10 +775,10 @@ async function loadPackages() {
|
|
|
598
775
|
function buildSdk(packages, options, env, read) {
|
|
599
776
|
const { sdkNode, sdkTrace, autoInstrumentations, exporter, resources } = packages;
|
|
600
777
|
const signals = planSignals(env);
|
|
601
|
-
const { instrumentations, unsafe } = read;
|
|
778
|
+
const { instrumentations, unsafe, service } = read;
|
|
602
779
|
return new sdkNode.NodeSDK({
|
|
603
780
|
...signals.overrides,
|
|
604
|
-
resource: resources.resourceFromAttributes(buildResourceAttributes(
|
|
781
|
+
resource: resources.resourceFromAttributes(buildResourceAttributes(service, env)),
|
|
605
782
|
resourceDetectors: selectResourceDetectors(
|
|
606
783
|
env.resourceDetectors,
|
|
607
784
|
{
|
|
@@ -642,14 +819,15 @@ function buildSdk(packages, options, env, read) {
|
|
|
642
819
|
async function boot(options, env) {
|
|
643
820
|
const unsafe = settleUnsafe(options.unsafe);
|
|
644
821
|
const instrumentations = settleInstrumentations(options.instrumentations);
|
|
822
|
+
const service = settleService(options);
|
|
645
823
|
warnAboutUnsafeOptions({ unsafe });
|
|
646
|
-
warnAboutMissingServiceName(
|
|
824
|
+
warnAboutMissingServiceName(service, env);
|
|
647
825
|
warnAboutOversizedTimers(env);
|
|
648
826
|
warnAboutSamplerName(readSamplerNearMiss());
|
|
649
827
|
warnAboutSamplerRatio(readRatioSampler());
|
|
650
828
|
warnAboutMissingWinstonTransport(instrumentations.sendLogs ?? planSignals(env).sendLogs);
|
|
651
829
|
const shutdownTimeoutMs = options.shutdownTimeoutMs;
|
|
652
|
-
const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe });
|
|
830
|
+
const sdk = buildSdk(await loadPackages(), options, env, { instrumentations, unsafe, service });
|
|
653
831
|
sdk.start();
|
|
654
832
|
const handle = createHandle(() => sdk.shutdown(), shutdownTimeoutMs);
|
|
655
833
|
registerHandle(handle);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-telemetry",
|
|
3
|
-
"version": "1.0.
|
|
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",
|