@bymax-one/nest-telemetry 1.0.1 → 1.0.2
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 +59 -0
- package/README.md +49 -35
- package/dist/nest/index.cjs +1 -0
- package/dist/nest/index.d.cts +3 -3
- package/dist/nest/index.d.ts +3 -3
- package/dist/nest/index.mjs +2 -1
- package/dist/register/index.mjs +31 -8
- package/dist/sdk/index.cjs +31 -8
- package/dist/sdk/index.mjs +31 -8
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,64 @@ The `release.yml` workflow extracts the section matching the pushed `vX.Y.Z` tag
|
|
|
8
8
|
as the GitHub Release body, so each released version needs a matching `## [X.Y.Z]`
|
|
9
9
|
heading here.
|
|
10
10
|
|
|
11
|
+
## [1.0.2] - 2026-11-13
|
|
12
|
+
|
|
13
|
+
### Security
|
|
14
|
+
|
|
15
|
+
- **node-redis command arguments and keys no longer reach `db.query.text`.** The command-name serializer
|
|
16
|
+
was applied to `instrumentation-ioredis` only, so `instrumentation-redis` kept the default one: an
|
|
17
|
+
`EVAL` argument and a key were exported on node-redis 3.1.2, 4.7.1, 5.12.2 and 6.3.1. Both
|
|
18
|
+
instrumentations now export the command name only, behind the same
|
|
19
|
+
`unsafe.disableRedisArgumentRedaction`, and a host override cannot replace the serializer of either.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `OTEL_SDK_DISABLED` is read as the SDK reads it, trimmed. A value such as `"true "` or `" TRUE"`
|
|
24
|
+
made the library load the loader hook and every OpenTelemetry package and report `enabled: true`,
|
|
25
|
+
while the SDK itself did nothing.
|
|
26
|
+
- A later `startTelemetry` call against a running SDK no longer drops its options silently: see the
|
|
27
|
+
warning below.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- `BYMAX_TELEMETRY_OPTIONS_IGNORED`: a `startTelemetry` call reached an SDK that was already running, so its
|
|
32
|
+
options were ignored, or `enabled: false` did not stop it. Any defined option counts, `env` included, and a
|
|
33
|
+
call that passes none stays silent.
|
|
34
|
+
- `BYMAX_TELEMETRY_RESTART_UNSUPPORTED`: see below.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- **A start after a shutdown in the same process is refused.** `startTelemetry` rejects with an error that
|
|
39
|
+
says to start once per process, and once in a global setup for a test suite, and the process emits
|
|
40
|
+
`BYMAX_TELEMETRY_RESTART_UNSUPPORTED`; the preload turns it into its start-failed warning. Auto-instrumented
|
|
41
|
+
spans can never resume after a shutdown in the same process, because the modules are already patched;
|
|
42
|
+
spans created through the API could, but a half-working restart is refused on purpose. Before, the second
|
|
43
|
+
start reported `enabled: true` and exported nothing. A test suite that started one SDK per case now has to
|
|
44
|
+
start once.
|
|
45
|
+
- The README names both Redis clients, says which one needs an active span, states what was measured about
|
|
46
|
+
mysql2 bound values, and lists the identifiers the library does not redact. A canary in the runtime proofs
|
|
47
|
+
fails if a bound mysql2 value ever reaches `db.query.text`.
|
|
48
|
+
|
|
49
|
+
### Shutdown order of `TelemetryModule`
|
|
50
|
+
|
|
51
|
+
`TelemetryModule` is now global, so its shutdown hook runs among the last. A span that another global module
|
|
52
|
+
ends in its own shutdown hook, such as a queue drain, is now exported when `TelemetryModule` is listed first in
|
|
53
|
+
the application module's imports, and was dropped before. Nest closes global modules in the reverse of the
|
|
54
|
+
order it registers them, so list it before any module that is global or imports a global module. Applications
|
|
55
|
+
that provided `TelemetryShutdownHook` in a module of their own to get this order can import the module.
|
|
56
|
+
|
|
57
|
+
### Apply to a derived backend
|
|
58
|
+
|
|
59
|
+
The declarations did not change; four behaviours did, and a derived backend acts on them:
|
|
60
|
+
|
|
61
|
+
1. A start after a shutdown in the same process now throws. Start telemetry once per process, and in a
|
|
62
|
+
test suite start it once in a global setup.
|
|
63
|
+
2. `TelemetryModule` is global. List it **first** in the application module's imports, so its flush runs
|
|
64
|
+
last; a module of your own that only provided `TelemetryShutdownHook` to get that order can import it.
|
|
65
|
+
3. `OTEL_SDK_DISABLED` is trimmed as the SDK trims it, so a padded `" true "` now really disables.
|
|
66
|
+
4. node-redis spans now carry the command name only. A dashboard or alert that matched node-redis
|
|
67
|
+
arguments or keys in `db.query.text` has to change.
|
|
68
|
+
|
|
11
69
|
## [1.0.1] - 2026-11-12
|
|
12
70
|
|
|
13
71
|
Documentation only; the built files are the same as in 1.0.0.
|
|
@@ -55,5 +113,6 @@ First release.
|
|
|
55
113
|
- Verification from the packed tarball: real `node --import` processes in a CommonJS and a native-ESM
|
|
56
114
|
application, with planted secrets absent from the exported body and negative controls.
|
|
57
115
|
|
|
116
|
+
[1.0.2]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.2
|
|
58
117
|
[1.0.1]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.1
|
|
59
118
|
[1.0.0]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ Install it with the OpenTelemetry peers you use: the command is in [Quick Start]
|
|
|
71
71
|
|
|
72
72
|
- ✅ **Span-end query redaction** — `url.query` is replaced and the query is cut from `url.full`, `http.url` and `http.target`, on spans from any instrumentation
|
|
73
73
|
- ✅ **Outgoing-URL credential list** — A list of credential-bearing parameters, checked in a test against the SDK's own default list; a host can add names and never drop them
|
|
74
|
-
- ✅ **Redis commands reduced to their name** — `
|
|
74
|
+
- ✅ **Redis commands reduced to their name** — for `ioredis` and node-redis (`redis`), arguments and keys never leave the process, `EVAL` and `EVALSHA` payloads included
|
|
75
75
|
- ✅ **Command line kept out of the resource** — `process.command_args` and `process.command_line` are dropped
|
|
76
76
|
- ✅ **Explicit, loud opt-outs** — Each off switch is a literal `unsafe.*: true` and emits a `SecurityWarning`
|
|
77
77
|
|
|
@@ -128,6 +128,8 @@ import { TelemetryModule } from '@bymax-one/nest-telemetry/nest'
|
|
|
128
128
|
export class AppModule {}
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
`TelemetryModule` is global, and Nest closes global modules last, in the reverse of the order it registers them. List it **first** in the application module's imports, before any module that is global or that imports a global module, so it closes after them: a span that another global module, such as a queue drain or a database module, ends in its own shutdown hook is exported only if `TelemetryModule` was registered first. Measured with Nest 11: listed first, the span arrives whether the other global module is imported directly or through a feature module; listed after a feature module that imports a global module, or after the global module itself, the span is dropped.
|
|
132
|
+
|
|
131
133
|
Things to know before you rely on it:
|
|
132
134
|
|
|
133
135
|
1. **Traces only, by default.** Metrics and logs stay off unless `OTEL_METRICS_EXPORTER` or `OTEL_LOGS_EXPORTER` names an exporter. This departs from the OpenTelemetry default, which exports both through OTLP, and it does so on purpose: otherwise a host that already ships metrics and logs another way would send them twice.
|
|
@@ -153,7 +155,7 @@ const telemetry = await startTelemetry({
|
|
|
153
155
|
await telemetry.shutdown()
|
|
154
156
|
```
|
|
155
157
|
|
|
156
|
-
This package installs no signal handler and shows none, because handling signals belongs to the application: a `SIGTERM` listener replaces Node's default termination, so it has to end the process itself once its work is done. `startTelemetry` resolves to a handle with `enabled` and `shutdown()`. Starting twice returns the handle already running, including across two copies of the module (an ES-module preload and a CommonJS application share the handle through `globalThis`).
|
|
158
|
+
This package installs no signal handler and shows none, because handling signals belongs to the application: a `SIGTERM` listener replaces Node's default termination, so it has to end the process itself once its work is done. `startTelemetry` resolves to a handle with `enabled` and `shutdown()`. Starting twice returns the handle already running, including across two copies of the module (an ES-module preload and a CommonJS application share the handle through `globalThis`). A later call that passes options is told they were ignored, and `enabled: false` against a running SDK is told it does not stop it: `shutdownTelemetry()` does.
|
|
157
159
|
|
|
158
160
|
---
|
|
159
161
|
|
|
@@ -184,7 +186,7 @@ The library reads these in one source file, and a test fails if any other file n
|
|
|
184
186
|
|
|
185
187
|
| Variable | Effect |
|
|
186
188
|
| ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
187
|
-
| `OTEL_SDK_DISABLED` | `true`
|
|
189
|
+
| `OTEL_SDK_DISABLED` | `true` disables the SDK, in any letter case and with surrounding whitespace ignored, as the SDK reads it. |
|
|
188
190
|
| `OTEL_SERVICE_NAME` | Service name; overrides the option, because the operator's standard variable wins over what the code chose. Blank values count as absent. |
|
|
189
191
|
| `OTEL_METRICS_EXPORTER`, `OTEL_LOGS_EXPORTER` | Metrics and logs are exported only when these name an exporter. |
|
|
190
192
|
| `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` | Mapped onto the batch span processor the library passes; the SDK applies them only to one it builds itself. |
|
|
@@ -202,25 +204,29 @@ The OpenTelemetry SDK reads these itself, and the library never touches them: `O
|
|
|
202
204
|
|
|
203
205
|
The start emits these warnings:
|
|
204
206
|
|
|
205
|
-
| Code | Meaning
|
|
206
|
-
| ------------------------------------------- |
|
|
207
|
-
| `BYMAX_TELEMETRY_START_FAILED` | The SDK could not start (a peer is missing, or the SDK threw). Tracing is off.
|
|
208
|
-
| `BYMAX_TELEMETRY_ESM_HOOK_UNAVAILABLE` | The loader hook could not be registered. Native-ESM code is not instrumented.
|
|
209
|
-
| `BYMAX_TELEMETRY_SERVICE_NAME_MISSING` | No service name is set; spans use `unknown_service:node`.
|
|
210
|
-
| `BYMAX_TELEMETRY_UNSAFE_REDACTION_DISABLED` | A redaction was turned off through an `unsafe` option.
|
|
207
|
+
| Code | Meaning |
|
|
208
|
+
| ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
209
|
+
| `BYMAX_TELEMETRY_START_FAILED` | The SDK could not start (a peer is missing, or the SDK threw). Tracing is off. |
|
|
210
|
+
| `BYMAX_TELEMETRY_ESM_HOOK_UNAVAILABLE` | The loader hook could not be registered. Native-ESM code is not instrumented. |
|
|
211
|
+
| `BYMAX_TELEMETRY_SERVICE_NAME_MISSING` | No service name is set; spans use `unknown_service:node`. |
|
|
212
|
+
| `BYMAX_TELEMETRY_UNSAFE_REDACTION_DISABLED` | A redaction was turned off through an `unsafe` option. |
|
|
213
|
+
| `BYMAX_TELEMETRY_OPTIONS_IGNORED` | A `startTelemetry` call reached an SDK that was already running, so its options were ignored, or `enabled: false` did not stop it. Any defined option counts, `env` included. |
|
|
214
|
+
| `BYMAX_TELEMETRY_RESTART_UNSUPPORTED` | `startTelemetry` was called after a shutdown in the same process, and is refused. |
|
|
211
215
|
|
|
212
216
|
The programmatic `startTelemetry` keeps its rejection when the SDK cannot start, for callers that want it.
|
|
213
217
|
|
|
214
218
|
### What is traced
|
|
215
219
|
|
|
216
220
|
- **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.
|
|
217
|
-
-
|
|
221
|
+
- **`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.
|
|
218
222
|
- **`fs` instrumentation is off by default**, because it floods traces with disk activity that has no context. Turn it on with `instrumentations.fs`.
|
|
219
223
|
|
|
220
224
|
### Flushing
|
|
221
225
|
|
|
222
226
|
Awaiting `shutdown()` or `shutdownTelemetry()` means the spans were exported, whoever started the flush: overlapping callers wait for the same flush, and a shutdown that arrives while the SDK is still starting waits for the start and then stops what it built. A flush the collector refuses is reported, never thrown into your shutdown path, by the Nest module; the programmatic functions reject, so their caller decides.
|
|
223
227
|
|
|
228
|
+
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.
|
|
229
|
+
|
|
224
230
|
---
|
|
225
231
|
|
|
226
232
|
## 🔄 OpenTelemetry Versions
|
|
@@ -243,16 +249,17 @@ A caret on a `0.x` version allows patch releases only, so each OpenTelemetry min
|
|
|
243
249
|
|
|
244
250
|
## 🩺 Troubleshooting
|
|
245
251
|
|
|
246
|
-
| You see
|
|
247
|
-
|
|
|
248
|
-
| No spans at all
|
|
249
|
-
| Spans from a CommonJS app but none from a native-ESM app
|
|
250
|
-
| Spans arrive but carry no service name
|
|
251
|
-
| `BYMAX_TELEMETRY_START_FAILED`
|
|
252
|
-
| HTTP spans but no Redis spans
|
|
253
|
-
| Metrics or logs missing
|
|
254
|
-
| The last spans are lost
|
|
255
|
-
|
|
|
252
|
+
| You see | Look at |
|
|
253
|
+
| --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
254
|
+
| No spans at all | `OTEL_SDK_DISABLED`; that the application was started with `--import`; `OTEL_EXPORTER_OTLP_ENDPOINT`; the start warnings. |
|
|
255
|
+
| Spans from a CommonJS app but none from a native-ESM app | `BYMAX_TELEMETRY_ESM_HOOK_UNAVAILABLE`: install `@opentelemetry/instrumentation`. |
|
|
256
|
+
| Spans arrive but carry no service name | `BYMAX_TELEMETRY_SERVICE_NAME_MISSING`: set `OTEL_SERVICE_NAME` or the `serviceName` option. A name set only through `OTEL_RESOURCE_ATTRIBUTES` still reaches the spans, unless `OTEL_NODE_RESOURCE_DETECTORS` leaves out both the `env` and the `service` detector. |
|
|
257
|
+
| `BYMAX_TELEMETRY_START_FAILED` | The warning names the cause, usually an OpenTelemetry peer that is not installed. |
|
|
258
|
+
| HTTP spans but no Redis spans | `ioredis` commands are traced under an active span only, and the client must be loaded after the preload. |
|
|
259
|
+
| Metrics or logs missing | They are off unless `OTEL_METRICS_EXPORTER` or `OTEL_LOGS_EXPORTER` names an exporter. |
|
|
260
|
+
| The last spans of another module are lost when the application closes | List `TelemetryModule` first in the application module's imports, so it closes last. |
|
|
261
|
+
| The last spans are lost on `SIGTERM` | Call `app.enableShutdownHooks()` in Nest, or `shutdownTelemetry()` from your own shutdown path. |
|
|
262
|
+
| A query string still appears in a span | It is on an attribute other than `url.query`, `url.full`, `http.url` or `http.target`: see [What This Library Does NOT Do](#-what-this-library-does-not-do). |
|
|
256
263
|
|
|
257
264
|
---
|
|
258
265
|
|
|
@@ -293,7 +300,7 @@ The resource carries `host.name`, `os.*`, `process.pid`, `process.owner`, the ex
|
|
|
293
300
|
|
|
294
301
|
### How this is verified
|
|
295
302
|
|
|
296
|
-
The packed tarball is installed and run with real `node --import` processes, in a CommonJS application and a native-ESM application, against a local OTLP receiver and a fake Redis. A real HTTP request carries a planted query secret and a real `EVAL` carries a planted argument; both are absent from the whole exported body, while the HTTP spans and the Redis command name are present. Negative controls (no loader hook, no preload, a preload loaded after `ioredis`, `OTEL_SDK_DISABLED=true`) export no such span, so the checks can fail. The
|
|
303
|
+
The packed tarball is installed and run with real `node --import` processes, in a CommonJS application and a native-ESM application, against a local OTLP receiver and a fake Redis. A real HTTP request carries a planted query secret and a real `EVAL` carries a planted argument; both are absent from the whole exported body, while the HTTP spans and the Redis command name are present. Negative controls (no loader hook, no preload, a preload loaded after `ioredis`, `OTEL_SDK_DISABLED=true`) export no such span, so the checks can fail. The span-end layer works on attributes, so it applies to spans from any instrumentation; an instrumentation the proofs do not exercise is not proven individually.
|
|
297
304
|
|
|
298
305
|
What is **not** redacted is listed flat in [What This Library Does NOT Do](#-what-this-library-does-not-do). To report a vulnerability, follow [SECURITY.md](./SECURITY.md).
|
|
299
306
|
|
|
@@ -305,7 +312,7 @@ What is **not** redacted is listed flat in [What This Library Does NOT Do](#-wha
|
|
|
305
312
|
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
306
313
|
| Query redaction | `url.query` is replaced by `[redacted]` and the query is cut from `url.full`, `http.url` and `http.target` as each span ends, for any instrumentation |
|
|
307
314
|
| Outgoing URLs | The HTTP instrumentation redacts a credential-parameter list (`token`, `code`, `access_token`, `signature`, `X-Amz-*`, and more); hosts add names, never drop them; a test compares the list with the SDK's own, so a name the SDK adds later is caught |
|
|
308
|
-
| Redis | `db.query.text` holds the command name only; `EVAL` and `EVALSHA` payloads, which carry `KEYS` and `ARGV`, never leave the process
|
|
315
|
+
| Redis | `db.query.text` holds the command name only, for `ioredis` and node-redis; `EVAL` and `EVALSHA` payloads, which carry `KEYS` and `ARGV`, and every key never leave the process |
|
|
309
316
|
| Process command line | `process.command_args` and `process.command_line` are dropped from the resource, because command-line arguments are a common carrier of secrets |
|
|
310
317
|
| Opt-outs | Literal `unsafe.*: true` options only, each emitting a `SecurityWarning`; no environment variable turns redaction off |
|
|
311
318
|
| Overrides | `instrumentations.overrides` is merged under the library's redaction, which is applied again on top |
|
|
@@ -354,17 +361,17 @@ pnpm check:runtime # packed-tarball consumer proofs
|
|
|
354
361
|
|
|
355
362
|
### SDK: `@bymax-one/nest-telemetry`
|
|
356
363
|
|
|
357
|
-
| Export | Signature | Purpose
|
|
358
|
-
| ------------------------------- | ---------------------------------------------------------- |
|
|
359
|
-
| `startTelemetry` | `(options?: TelemetryOptions) => Promise<TelemetryHandle>` | Assembles and starts the SDK; returns the running handle when one exists; rejects when the SDK cannot start
|
|
360
|
-
| `shutdownTelemetry` | `() => Promise<void>` | Waits for a start in progress, then flushes and stops the SDK; resolves at once when none was started
|
|
361
|
-
| `ignorePaths` | `(patterns: readonly RegExp[]) => (request) => boolean` | Predicate for `ignoreIncomingRequest`: matches the request path with its query cut; a request with no target is not matched
|
|
362
|
-
| `DEFAULT_REDACTED_QUERY_PARAMS` | `readonly string[]` | The credential-parameter list redacted from outgoing request URLs
|
|
363
|
-
| `TelemetryOptions` | type | The options of `startTelemetry` ([Configuration](#-configuration))
|
|
364
|
-
| `TelemetryHandle` | type | `{ enabled: boolean, shutdown(): Promise<void> }`
|
|
365
|
-
| `UnsafeOptions` | type | The literal-`true` redaction opt-outs
|
|
366
|
-
| `InstrumentationOptions` | type | `fs`, `sendLogs` and `overrides`
|
|
367
|
-
| `IncomingRequestTarget` | type | What an incoming-request predicate sees: the request `url`
|
|
364
|
+
| Export | Signature | Purpose |
|
|
365
|
+
| ------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
366
|
+
| `startTelemetry` | `(options?: TelemetryOptions) => Promise<TelemetryHandle>` | Assembles and starts the SDK; returns the running handle when one exists; rejects when the SDK cannot start or was already shut down in this process |
|
|
367
|
+
| `shutdownTelemetry` | `() => Promise<void>` | Waits for a start in progress, then flushes and stops the SDK; resolves at once when none was started |
|
|
368
|
+
| `ignorePaths` | `(patterns: readonly RegExp[]) => (request) => boolean` | Predicate for `ignoreIncomingRequest`: matches the request path with its query cut; a request with no target is not matched |
|
|
369
|
+
| `DEFAULT_REDACTED_QUERY_PARAMS` | `readonly string[]` | The credential-parameter list redacted from outgoing request URLs |
|
|
370
|
+
| `TelemetryOptions` | type | The options of `startTelemetry` ([Configuration](#-configuration)) |
|
|
371
|
+
| `TelemetryHandle` | type | `{ enabled: boolean, shutdown(): Promise<void> }` |
|
|
372
|
+
| `UnsafeOptions` | type | The literal-`true` redaction opt-outs |
|
|
373
|
+
| `InstrumentationOptions` | type | `fs`, `sendLogs` and `overrides` |
|
|
374
|
+
| `IncomingRequestTarget` | type | What an incoming-request predicate sees: the request `url` |
|
|
368
375
|
|
|
369
376
|
`ignorePaths` copies each pattern without its `g` and `y` flags, which would keep state between calls. Anchor the patterns at both ends; an unanchored one also matches routes that merely contain the word.
|
|
370
377
|
|
|
@@ -376,7 +383,7 @@ No exports. `node --import @bymax-one/nest-telemetry/register` registers the loa
|
|
|
376
383
|
|
|
377
384
|
| Export | Kind | Purpose |
|
|
378
385
|
| ---------------------------- | -------- | ---------------------------------------------------------------------------------------------------- |
|
|
379
|
-
| `TelemetryModule` | module |
|
|
386
|
+
| `TelemetryModule` | module | Global; registers `TelemetryShutdownHook`. List it first in the application module's imports |
|
|
380
387
|
| `TelemetryShutdownHook` | provider | `OnApplicationShutdown`: awaits `shutdownTelemetry()`; a refused flush is reported and never rejects |
|
|
381
388
|
| `TELEMETRY_LOGGER` | token | Optional provider with an `errorStructured(logKey, error)` method, used to report a failed flush |
|
|
382
389
|
| `TELEMETRY_FLUSH_FAILED_KEY` | constant | The stable key, `TRACING_FLUSH_FAILED`, under which a failed flush is reported |
|
|
@@ -389,8 +396,14 @@ No exports. `node --import @bymax-one/nest-telemetry/register` registers the loa
|
|
|
389
396
|
By design, the following are out of scope:
|
|
390
397
|
|
|
391
398
|
- ❌ **Redact secrets in the URL path** — only the query string is removed. A path such as `/reset/<token>` is exported as it is
|
|
392
|
-
- ❌ **Redact SQL text with inline literals** — database instrumentations record the statement, and values written into it are exported
|
|
399
|
+
- ❌ **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
|
|
393
400
|
- ❌ **Redact `exception.message` in span events** — an exception's message is exported as recorded
|
|
401
|
+
- ❌ **Redact the text of database driver errors** — not measured; an error recorded on a span carries whatever message the driver wrote
|
|
402
|
+
- ❌ **Redact the memcached key** — `db.memcached.key` is recorded on every memcached span
|
|
403
|
+
- ❌ **Redact an SNS phone number** — a publish to a `PhoneNumber` records the number as the destination name
|
|
404
|
+
- ❌ **Redact the Kafka message key** — `messaging.kafka.message.key` is recorded on producer and consumer spans
|
|
405
|
+
- ❌ **Redact gRPC error messages** — `grpc.error_message` is recorded when a call fails
|
|
406
|
+
- ❌ **Stop the OpenAI instrumentation from capturing prompts** — it reads `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` itself, and when that is set, message content is recorded
|
|
394
407
|
- ❌ **Redact span names your own code builds from raw URLs**
|
|
395
408
|
- ❌ **Redact baggage**
|
|
396
409
|
- ❌ **Redact request and response bodies, or HTTP headers** — they are not captured by default, and they are not redacted if you enable capturing them
|
|
@@ -398,6 +411,7 @@ By design, the following are out of scope:
|
|
|
398
411
|
- ❌ **Choose a sampler** — configure `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
|
|
399
412
|
- ❌ **Run a collector or a backend** — point `OTEL_EXPORTER_OTLP_ENDPOINT` at one
|
|
400
413
|
- ❌ **Decide your span names** — those come from the instrumentations and from your code
|
|
414
|
+
- ❌ **Start again after a shutdown in the same process** — `startTelemetry` is refused, because auto-instrumented modules stay patched against the first SDK
|
|
401
415
|
- ❌ **Install a signal handler** — handling `SIGTERM` belongs to the application
|
|
402
416
|
- ❌ **Provide strict semantic versioning** — each release in the [CHANGELOG](./CHANGELOG.md) says what changed and what to do about it, and the version number alone is not the compatibility information
|
|
403
417
|
|
package/dist/nest/index.cjs
CHANGED
|
@@ -104,6 +104,7 @@ exports.TelemetryShutdownHook = __decorateClass([
|
|
|
104
104
|
exports.TelemetryModule = class TelemetryModule {
|
|
105
105
|
};
|
|
106
106
|
exports.TelemetryModule = __decorateClass([
|
|
107
|
+
common.Global(),
|
|
107
108
|
common.Module({ providers: [exports.TelemetryShutdownHook] })
|
|
108
109
|
], exports.TelemetryModule);
|
|
109
110
|
|
package/dist/nest/index.d.cts
CHANGED
|
@@ -65,9 +65,9 @@ declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* List it first in the imports of the application module, before any module that is global or
|
|
69
|
+
* imports a global module. Nest then awaits the SDK flush while closing the application, so
|
|
70
|
+
* buffered spans are exported before the process exits.
|
|
71
71
|
*/
|
|
72
72
|
declare class TelemetryModule {
|
|
73
73
|
}
|
package/dist/nest/index.d.ts
CHANGED
|
@@ -65,9 +65,9 @@ declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* List it first in the imports of the application module, before any module that is global or
|
|
69
|
+
* imports a global module. Nest then awaits the SDK flush while closing the application, so
|
|
70
|
+
* buffered spans are exported before the process exits.
|
|
71
71
|
*/
|
|
72
72
|
declare class TelemetryModule {
|
|
73
73
|
}
|
package/dist/nest/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Injectable, Inject, Module, Logger } from '@nestjs/common';
|
|
1
|
+
import { Injectable, Inject, Global, Module, Logger } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
3
|
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -102,6 +102,7 @@ TelemetryShutdownHook = __decorateClass([
|
|
|
102
102
|
var TelemetryModule = class {
|
|
103
103
|
};
|
|
104
104
|
TelemetryModule = __decorateClass([
|
|
105
|
+
Global(),
|
|
105
106
|
Module({ providers: [TelemetryShutdownHook] })
|
|
106
107
|
], TelemetryModule);
|
|
107
108
|
|
package/dist/register/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ function readTelemetryEnvironment(source = process.env) {
|
|
|
23
23
|
const serviceName = source["OTEL_SERVICE_NAME"]?.trim();
|
|
24
24
|
const detectors = source["OTEL_NODE_RESOURCE_DETECTORS"];
|
|
25
25
|
return {
|
|
26
|
-
sdkDisabled: source["OTEL_SDK_DISABLED"]?.toLowerCase() === "true",
|
|
26
|
+
sdkDisabled: source["OTEL_SDK_DISABLED"]?.trim().toLowerCase() === "true",
|
|
27
27
|
serviceName: serviceName === "" ? void 0 : serviceName,
|
|
28
28
|
metricsExporters: readExporterList(source["OTEL_METRICS_EXPORTER"]),
|
|
29
29
|
logsExporters: readExporterList(source["OTEL_LOGS_EXPORTER"]),
|
|
@@ -91,6 +91,7 @@ function serializeRedisCommandName(commandName) {
|
|
|
91
91
|
var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
|
|
92
92
|
var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
|
|
93
93
|
var IOREDIS_INSTRUMENTATION = "@opentelemetry/instrumentation-ioredis";
|
|
94
|
+
var REDIS_INSTRUMENTATION = "@opentelemetry/instrumentation-redis";
|
|
94
95
|
var PINO_INSTRUMENTATION = "@opentelemetry/instrumentation-pino";
|
|
95
96
|
var LOG_EXPORTERS = /* @__PURE__ */ new Set(["otlp", "console"]);
|
|
96
97
|
var UNKNOWN_SERVICE_NAME = "unknown_service:node";
|
|
@@ -98,6 +99,7 @@ var WARNING_OPTIONS = {
|
|
|
98
99
|
type: "SecurityWarning",
|
|
99
100
|
code: "BYMAX_TELEMETRY_UNSAFE_REDACTION_DISABLED"
|
|
100
101
|
};
|
|
102
|
+
var IGNORED_WARNING = { type: "Warning", code: "BYMAX_TELEMETRY_OPTIONS_IGNORED" };
|
|
101
103
|
function planSignals(env) {
|
|
102
104
|
const overrides = {};
|
|
103
105
|
if (env.metricsExporters.length === 0) overrides.metricReaders = [];
|
|
@@ -147,10 +149,9 @@ function buildInstrumentationConfig(options, signals) {
|
|
|
147
149
|
merged[HTTP_INSTRUMENTATION]["ignoreIncomingRequestHook"] = options.ignoreIncomingRequest;
|
|
148
150
|
}
|
|
149
151
|
if (redactRedis) {
|
|
150
|
-
|
|
151
|
-
...merged[
|
|
152
|
-
|
|
153
|
-
};
|
|
152
|
+
for (const name of [IOREDIS_INSTRUMENTATION, REDIS_INSTRUMENTATION]) {
|
|
153
|
+
merged[name] = { ...merged[name], dbStatementSerializer: serializeRedisCommandName };
|
|
154
|
+
}
|
|
154
155
|
}
|
|
155
156
|
return merged;
|
|
156
157
|
}
|
|
@@ -182,10 +183,20 @@ function warnAboutUnsafeOptions(options) {
|
|
|
182
183
|
);
|
|
183
184
|
}
|
|
184
185
|
}
|
|
186
|
+
function warnAboutIgnoredOptions(options) {
|
|
187
|
+
const stop = options.enabled === false;
|
|
188
|
+
if (stop || Object.values(options).some((v) => v !== void 0)) {
|
|
189
|
+
process.emitWarning(
|
|
190
|
+
stop ? "startTelemetry({ enabled: false }) was called while telemetry is already running. It does not stop the running SDK: call shutdownTelemetry() for that." : "startTelemetry was called while telemetry is already running, so the options of this call were ignored. Pass them to the first call.",
|
|
191
|
+
IGNORED_WARNING
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
185
195
|
|
|
186
196
|
// src/sdk/handle.ts
|
|
187
197
|
var HANDLE_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/handle");
|
|
188
198
|
var PENDING_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/pending-start");
|
|
199
|
+
var STOPPED_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/stopped");
|
|
189
200
|
var store = globalThis;
|
|
190
201
|
function registerHandle(handle) {
|
|
191
202
|
store[HANDLE_KEY] = handle;
|
|
@@ -193,8 +204,8 @@ function registerHandle(handle) {
|
|
|
193
204
|
function currentHandle() {
|
|
194
205
|
return store[HANDLE_KEY];
|
|
195
206
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
207
|
+
function hasStopped() {
|
|
208
|
+
return Reflect.get(globalThis, STOPPED_KEY) === true;
|
|
198
209
|
}
|
|
199
210
|
function pendingStart() {
|
|
200
211
|
return store[PENDING_KEY];
|
|
@@ -219,8 +230,9 @@ function createHandle(stopSdk) {
|
|
|
219
230
|
}
|
|
220
231
|
flush ??= stopSdk().finally(() => {
|
|
221
232
|
finished = true;
|
|
233
|
+
Reflect.set(globalThis, STOPPED_KEY, true);
|
|
222
234
|
if (currentHandle() === handle) {
|
|
223
|
-
|
|
235
|
+
Reflect.deleteProperty(globalThis, HANDLE_KEY);
|
|
224
236
|
}
|
|
225
237
|
});
|
|
226
238
|
return flush;
|
|
@@ -277,6 +289,7 @@ function selectResourceDetectors(selection, detectors, keepCommandLine) {
|
|
|
277
289
|
}
|
|
278
290
|
|
|
279
291
|
// src/sdk/start.ts
|
|
292
|
+
var RESTART_MESSAGE = "Telemetry cannot start again after it was shut down in the same process: the modules the first start instrumented stay patched against its tracer provider, so a second SDK would export nothing for them. Start telemetry once per process; in a test suite, start it once in a global setup.";
|
|
280
293
|
var DISABLED_HANDLE = {
|
|
281
294
|
enabled: false,
|
|
282
295
|
shutdown: () => Promise.resolve()
|
|
@@ -284,6 +297,7 @@ var DISABLED_HANDLE = {
|
|
|
284
297
|
async function startTelemetry(options = {}) {
|
|
285
298
|
const env = readTelemetryEnvironment(options.env);
|
|
286
299
|
if (options.enabled === false || env.sdkDisabled) {
|
|
300
|
+
if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(options);
|
|
287
301
|
return DISABLED_HANDLE;
|
|
288
302
|
}
|
|
289
303
|
let running = currentHandle();
|
|
@@ -292,12 +306,21 @@ async function startTelemetry(options = {}) {
|
|
|
292
306
|
running = currentHandle();
|
|
293
307
|
}
|
|
294
308
|
if (running !== void 0) {
|
|
309
|
+
warnAboutIgnoredOptions(options);
|
|
295
310
|
return running;
|
|
296
311
|
}
|
|
297
312
|
const joined = pendingStart();
|
|
298
313
|
if (joined !== void 0) {
|
|
314
|
+
warnAboutIgnoredOptions(options);
|
|
299
315
|
return joined;
|
|
300
316
|
}
|
|
317
|
+
if (hasStopped()) {
|
|
318
|
+
process.emitWarning(RESTART_MESSAGE, {
|
|
319
|
+
type: "Warning",
|
|
320
|
+
code: "BYMAX_TELEMETRY_RESTART_UNSUPPORTED"
|
|
321
|
+
});
|
|
322
|
+
throw new Error(RESTART_MESSAGE);
|
|
323
|
+
}
|
|
301
324
|
const start = boot(options, env).finally(clearPendingStart);
|
|
302
325
|
setPendingStart(start);
|
|
303
326
|
return start;
|
package/dist/sdk/index.cjs
CHANGED
|
@@ -73,6 +73,7 @@ function ignorePaths(patterns) {
|
|
|
73
73
|
// src/sdk/handle.ts
|
|
74
74
|
var HANDLE_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/handle");
|
|
75
75
|
var PENDING_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/pending-start");
|
|
76
|
+
var STOPPED_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/stopped");
|
|
76
77
|
var store = globalThis;
|
|
77
78
|
function registerHandle(handle) {
|
|
78
79
|
store[HANDLE_KEY] = handle;
|
|
@@ -80,8 +81,8 @@ function registerHandle(handle) {
|
|
|
80
81
|
function currentHandle() {
|
|
81
82
|
return store[HANDLE_KEY];
|
|
82
83
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
84
|
+
function hasStopped() {
|
|
85
|
+
return Reflect.get(globalThis, STOPPED_KEY) === true;
|
|
85
86
|
}
|
|
86
87
|
function pendingStart() {
|
|
87
88
|
return store[PENDING_KEY];
|
|
@@ -106,8 +107,9 @@ function createHandle(stopSdk) {
|
|
|
106
107
|
}
|
|
107
108
|
flush ??= stopSdk().finally(() => {
|
|
108
109
|
finished = true;
|
|
110
|
+
Reflect.set(globalThis, STOPPED_KEY, true);
|
|
109
111
|
if (currentHandle() === handle) {
|
|
110
|
-
|
|
112
|
+
Reflect.deleteProperty(globalThis, HANDLE_KEY);
|
|
111
113
|
}
|
|
112
114
|
});
|
|
113
115
|
return flush;
|
|
@@ -124,6 +126,7 @@ async function shutdownTelemetry() {
|
|
|
124
126
|
var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
|
|
125
127
|
var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
|
|
126
128
|
var IOREDIS_INSTRUMENTATION = "@opentelemetry/instrumentation-ioredis";
|
|
129
|
+
var REDIS_INSTRUMENTATION = "@opentelemetry/instrumentation-redis";
|
|
127
130
|
var PINO_INSTRUMENTATION = "@opentelemetry/instrumentation-pino";
|
|
128
131
|
var LOG_EXPORTERS = /* @__PURE__ */ new Set(["otlp", "console"]);
|
|
129
132
|
var UNKNOWN_SERVICE_NAME = "unknown_service:node";
|
|
@@ -131,6 +134,7 @@ var WARNING_OPTIONS = {
|
|
|
131
134
|
type: "SecurityWarning",
|
|
132
135
|
code: "BYMAX_TELEMETRY_UNSAFE_REDACTION_DISABLED"
|
|
133
136
|
};
|
|
137
|
+
var IGNORED_WARNING = { type: "Warning", code: "BYMAX_TELEMETRY_OPTIONS_IGNORED" };
|
|
134
138
|
function planSignals(env) {
|
|
135
139
|
const overrides = {};
|
|
136
140
|
if (env.metricsExporters.length === 0) overrides.metricReaders = [];
|
|
@@ -180,10 +184,9 @@ function buildInstrumentationConfig(options, signals) {
|
|
|
180
184
|
merged[HTTP_INSTRUMENTATION]["ignoreIncomingRequestHook"] = options.ignoreIncomingRequest;
|
|
181
185
|
}
|
|
182
186
|
if (redactRedis) {
|
|
183
|
-
|
|
184
|
-
...merged[
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
+
for (const name of [IOREDIS_INSTRUMENTATION, REDIS_INSTRUMENTATION]) {
|
|
188
|
+
merged[name] = { ...merged[name], dbStatementSerializer: serializeRedisCommandName };
|
|
189
|
+
}
|
|
187
190
|
}
|
|
188
191
|
return merged;
|
|
189
192
|
}
|
|
@@ -215,6 +218,15 @@ function warnAboutUnsafeOptions(options) {
|
|
|
215
218
|
);
|
|
216
219
|
}
|
|
217
220
|
}
|
|
221
|
+
function warnAboutIgnoredOptions(options) {
|
|
222
|
+
const stop = options.enabled === false;
|
|
223
|
+
if (stop || Object.values(options).some((v) => v !== void 0)) {
|
|
224
|
+
process.emitWarning(
|
|
225
|
+
stop ? "startTelemetry({ enabled: false }) was called while telemetry is already running. It does not stop the running SDK: call shutdownTelemetry() for that." : "startTelemetry was called while telemetry is already running, so the options of this call were ignored. Pass them to the first call.",
|
|
226
|
+
IGNORED_WARNING
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
218
230
|
|
|
219
231
|
// src/sdk/environment.ts
|
|
220
232
|
function readExporterList(raw) {
|
|
@@ -237,7 +249,7 @@ function readTelemetryEnvironment(source = process.env) {
|
|
|
237
249
|
const serviceName = source["OTEL_SERVICE_NAME"]?.trim();
|
|
238
250
|
const detectors = source["OTEL_NODE_RESOURCE_DETECTORS"];
|
|
239
251
|
return {
|
|
240
|
-
sdkDisabled: source["OTEL_SDK_DISABLED"]?.toLowerCase() === "true",
|
|
252
|
+
sdkDisabled: source["OTEL_SDK_DISABLED"]?.trim().toLowerCase() === "true",
|
|
241
253
|
serviceName: serviceName === "" ? void 0 : serviceName,
|
|
242
254
|
metricsExporters: readExporterList(source["OTEL_METRICS_EXPORTER"]),
|
|
243
255
|
logsExporters: readExporterList(source["OTEL_LOGS_EXPORTER"]),
|
|
@@ -294,6 +306,7 @@ function selectResourceDetectors(selection, detectors, keepCommandLine) {
|
|
|
294
306
|
}
|
|
295
307
|
|
|
296
308
|
// src/sdk/start.ts
|
|
309
|
+
var RESTART_MESSAGE = "Telemetry cannot start again after it was shut down in the same process: the modules the first start instrumented stay patched against its tracer provider, so a second SDK would export nothing for them. Start telemetry once per process; in a test suite, start it once in a global setup.";
|
|
297
310
|
var DISABLED_HANDLE = {
|
|
298
311
|
enabled: false,
|
|
299
312
|
shutdown: () => Promise.resolve()
|
|
@@ -301,6 +314,7 @@ var DISABLED_HANDLE = {
|
|
|
301
314
|
async function startTelemetry(options = {}) {
|
|
302
315
|
const env = readTelemetryEnvironment(options.env);
|
|
303
316
|
if (options.enabled === false || env.sdkDisabled) {
|
|
317
|
+
if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(options);
|
|
304
318
|
return DISABLED_HANDLE;
|
|
305
319
|
}
|
|
306
320
|
let running = currentHandle();
|
|
@@ -309,12 +323,21 @@ async function startTelemetry(options = {}) {
|
|
|
309
323
|
running = currentHandle();
|
|
310
324
|
}
|
|
311
325
|
if (running !== void 0) {
|
|
326
|
+
warnAboutIgnoredOptions(options);
|
|
312
327
|
return running;
|
|
313
328
|
}
|
|
314
329
|
const joined = pendingStart();
|
|
315
330
|
if (joined !== void 0) {
|
|
331
|
+
warnAboutIgnoredOptions(options);
|
|
316
332
|
return joined;
|
|
317
333
|
}
|
|
334
|
+
if (hasStopped()) {
|
|
335
|
+
process.emitWarning(RESTART_MESSAGE, {
|
|
336
|
+
type: "Warning",
|
|
337
|
+
code: "BYMAX_TELEMETRY_RESTART_UNSUPPORTED"
|
|
338
|
+
});
|
|
339
|
+
throw new Error(RESTART_MESSAGE);
|
|
340
|
+
}
|
|
318
341
|
const start = boot(options, env).finally(clearPendingStart);
|
|
319
342
|
setPendingStart(start);
|
|
320
343
|
return start;
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -71,6 +71,7 @@ function ignorePaths(patterns) {
|
|
|
71
71
|
// src/sdk/handle.ts
|
|
72
72
|
var HANDLE_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/handle");
|
|
73
73
|
var PENDING_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/pending-start");
|
|
74
|
+
var STOPPED_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/stopped");
|
|
74
75
|
var store = globalThis;
|
|
75
76
|
function registerHandle(handle) {
|
|
76
77
|
store[HANDLE_KEY] = handle;
|
|
@@ -78,8 +79,8 @@ function registerHandle(handle) {
|
|
|
78
79
|
function currentHandle() {
|
|
79
80
|
return store[HANDLE_KEY];
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
82
|
+
function hasStopped() {
|
|
83
|
+
return Reflect.get(globalThis, STOPPED_KEY) === true;
|
|
83
84
|
}
|
|
84
85
|
function pendingStart() {
|
|
85
86
|
return store[PENDING_KEY];
|
|
@@ -104,8 +105,9 @@ function createHandle(stopSdk) {
|
|
|
104
105
|
}
|
|
105
106
|
flush ??= stopSdk().finally(() => {
|
|
106
107
|
finished = true;
|
|
108
|
+
Reflect.set(globalThis, STOPPED_KEY, true);
|
|
107
109
|
if (currentHandle() === handle) {
|
|
108
|
-
|
|
110
|
+
Reflect.deleteProperty(globalThis, HANDLE_KEY);
|
|
109
111
|
}
|
|
110
112
|
});
|
|
111
113
|
return flush;
|
|
@@ -122,6 +124,7 @@ async function shutdownTelemetry() {
|
|
|
122
124
|
var FS_INSTRUMENTATION = "@opentelemetry/instrumentation-fs";
|
|
123
125
|
var HTTP_INSTRUMENTATION = "@opentelemetry/instrumentation-http";
|
|
124
126
|
var IOREDIS_INSTRUMENTATION = "@opentelemetry/instrumentation-ioredis";
|
|
127
|
+
var REDIS_INSTRUMENTATION = "@opentelemetry/instrumentation-redis";
|
|
125
128
|
var PINO_INSTRUMENTATION = "@opentelemetry/instrumentation-pino";
|
|
126
129
|
var LOG_EXPORTERS = /* @__PURE__ */ new Set(["otlp", "console"]);
|
|
127
130
|
var UNKNOWN_SERVICE_NAME = "unknown_service:node";
|
|
@@ -129,6 +132,7 @@ var WARNING_OPTIONS = {
|
|
|
129
132
|
type: "SecurityWarning",
|
|
130
133
|
code: "BYMAX_TELEMETRY_UNSAFE_REDACTION_DISABLED"
|
|
131
134
|
};
|
|
135
|
+
var IGNORED_WARNING = { type: "Warning", code: "BYMAX_TELEMETRY_OPTIONS_IGNORED" };
|
|
132
136
|
function planSignals(env) {
|
|
133
137
|
const overrides = {};
|
|
134
138
|
if (env.metricsExporters.length === 0) overrides.metricReaders = [];
|
|
@@ -178,10 +182,9 @@ function buildInstrumentationConfig(options, signals) {
|
|
|
178
182
|
merged[HTTP_INSTRUMENTATION]["ignoreIncomingRequestHook"] = options.ignoreIncomingRequest;
|
|
179
183
|
}
|
|
180
184
|
if (redactRedis) {
|
|
181
|
-
|
|
182
|
-
...merged[
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
+
for (const name of [IOREDIS_INSTRUMENTATION, REDIS_INSTRUMENTATION]) {
|
|
186
|
+
merged[name] = { ...merged[name], dbStatementSerializer: serializeRedisCommandName };
|
|
187
|
+
}
|
|
185
188
|
}
|
|
186
189
|
return merged;
|
|
187
190
|
}
|
|
@@ -213,6 +216,15 @@ function warnAboutUnsafeOptions(options) {
|
|
|
213
216
|
);
|
|
214
217
|
}
|
|
215
218
|
}
|
|
219
|
+
function warnAboutIgnoredOptions(options) {
|
|
220
|
+
const stop = options.enabled === false;
|
|
221
|
+
if (stop || Object.values(options).some((v) => v !== void 0)) {
|
|
222
|
+
process.emitWarning(
|
|
223
|
+
stop ? "startTelemetry({ enabled: false }) was called while telemetry is already running. It does not stop the running SDK: call shutdownTelemetry() for that." : "startTelemetry was called while telemetry is already running, so the options of this call were ignored. Pass them to the first call.",
|
|
224
|
+
IGNORED_WARNING
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
216
228
|
|
|
217
229
|
// src/sdk/environment.ts
|
|
218
230
|
function readExporterList(raw) {
|
|
@@ -235,7 +247,7 @@ function readTelemetryEnvironment(source = process.env) {
|
|
|
235
247
|
const serviceName = source["OTEL_SERVICE_NAME"]?.trim();
|
|
236
248
|
const detectors = source["OTEL_NODE_RESOURCE_DETECTORS"];
|
|
237
249
|
return {
|
|
238
|
-
sdkDisabled: source["OTEL_SDK_DISABLED"]?.toLowerCase() === "true",
|
|
250
|
+
sdkDisabled: source["OTEL_SDK_DISABLED"]?.trim().toLowerCase() === "true",
|
|
239
251
|
serviceName: serviceName === "" ? void 0 : serviceName,
|
|
240
252
|
metricsExporters: readExporterList(source["OTEL_METRICS_EXPORTER"]),
|
|
241
253
|
logsExporters: readExporterList(source["OTEL_LOGS_EXPORTER"]),
|
|
@@ -292,6 +304,7 @@ function selectResourceDetectors(selection, detectors, keepCommandLine) {
|
|
|
292
304
|
}
|
|
293
305
|
|
|
294
306
|
// src/sdk/start.ts
|
|
307
|
+
var RESTART_MESSAGE = "Telemetry cannot start again after it was shut down in the same process: the modules the first start instrumented stay patched against its tracer provider, so a second SDK would export nothing for them. Start telemetry once per process; in a test suite, start it once in a global setup.";
|
|
295
308
|
var DISABLED_HANDLE = {
|
|
296
309
|
enabled: false,
|
|
297
310
|
shutdown: () => Promise.resolve()
|
|
@@ -299,6 +312,7 @@ var DISABLED_HANDLE = {
|
|
|
299
312
|
async function startTelemetry(options = {}) {
|
|
300
313
|
const env = readTelemetryEnvironment(options.env);
|
|
301
314
|
if (options.enabled === false || env.sdkDisabled) {
|
|
315
|
+
if (currentHandle()?.stopping === false || pendingStart()) warnAboutIgnoredOptions(options);
|
|
302
316
|
return DISABLED_HANDLE;
|
|
303
317
|
}
|
|
304
318
|
let running = currentHandle();
|
|
@@ -307,12 +321,21 @@ async function startTelemetry(options = {}) {
|
|
|
307
321
|
running = currentHandle();
|
|
308
322
|
}
|
|
309
323
|
if (running !== void 0) {
|
|
324
|
+
warnAboutIgnoredOptions(options);
|
|
310
325
|
return running;
|
|
311
326
|
}
|
|
312
327
|
const joined = pendingStart();
|
|
313
328
|
if (joined !== void 0) {
|
|
329
|
+
warnAboutIgnoredOptions(options);
|
|
314
330
|
return joined;
|
|
315
331
|
}
|
|
332
|
+
if (hasStopped()) {
|
|
333
|
+
process.emitWarning(RESTART_MESSAGE, {
|
|
334
|
+
type: "Warning",
|
|
335
|
+
code: "BYMAX_TELEMETRY_RESTART_UNSUPPORTED"
|
|
336
|
+
});
|
|
337
|
+
throw new Error(RESTART_MESSAGE);
|
|
338
|
+
}
|
|
316
339
|
const start = boot(options, env).finally(clearPendingStart);
|
|
317
340
|
setPendingStart(start);
|
|
318
341
|
return start;
|
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.2",
|
|
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",
|
|
@@ -189,7 +189,9 @@
|
|
|
189
189
|
"ioredis": "^6.0.0",
|
|
190
190
|
"jest": "^30.4.2",
|
|
191
191
|
"lint-staged": "^17.0.7",
|
|
192
|
+
"mysql2": "3.24.6",
|
|
192
193
|
"prettier": "^3.8.3",
|
|
194
|
+
"redis": "^5.12.2",
|
|
193
195
|
"reflect-metadata": "^0.2.2",
|
|
194
196
|
"rxjs": "^7.8.0",
|
|
195
197
|
"supertest": "^7.2.2",
|