@bymax-one/nest-telemetry 1.0.2 → 1.0.4
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 +96 -0
- package/README.md +80 -57
- package/dist/nest/index.cjs +47 -0
- package/dist/nest/index.d.cts +32 -3
- package/dist/nest/index.d.ts +32 -3
- package/dist/nest/index.mjs +46 -1
- package/dist/register/index.mjs +136 -17
- package/dist/sdk/index.cjs +138 -18
- package/dist/sdk/index.d.cts +24 -6
- package/dist/sdk/index.d.ts +24 -6
- package/dist/sdk/index.mjs +138 -18
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,100 @@ 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.4] - 2026-11-14
|
|
12
|
+
|
|
13
|
+
### Security
|
|
14
|
+
|
|
15
|
+
- **`host.id` is no longer exported by default.** It is dropped from the resource, and `host.name` stays. `unsafe.exportHostId: true`
|
|
16
|
+
keeps it and emits a `SecurityWarning`.
|
|
17
|
+
- **`process.command` is dropped with the command-line attributes.** It is `argv[1]`, which for
|
|
18
|
+
`node -e code ARG` is the first argument. `unsafe.exportProcessCommandArgs: true` keeps it, with
|
|
19
|
+
`process.command_args` and `process.command_line`.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- **A batch-processor timer value a timer cannot hold is ignored.** An `OTEL_BSP_SCHEDULE_DELAY` above
|
|
24
|
+
2147483647 ms reached `setTimeout`, which Node clamps to 1 ms, and the SDK exported once per span: 40
|
|
25
|
+
exports in 2 seconds in a measurement, against none at the default. An `OTEL_BSP_EXPORT_TIMEOUT` above it
|
|
26
|
+
became a 1 ms timeout on the processor side. Both are now ignored, the default applies, and
|
|
27
|
+
`BYMAX_TELEMETRY_BSP_VALUE_IGNORED` names the variable. The two sizes are not timers and are not limited.
|
|
28
|
+
- **`instrumentations.sendLogs: false` now keeps winston and bunyan records off the logs pipeline too.** It
|
|
29
|
+
set the log-sending key of pino only, so with `OTEL_LOGS_EXPORTER=otlp` the records of the other two were
|
|
30
|
+
forwarded whatever the option said. One option now sets the key of all three.
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `unsafe.exportHostId` on `UnsafeOptions`.
|
|
35
|
+
- `BYMAX_TELEMETRY_BSP_VALUE_IGNORED`: a timer variable was ignored for being longer than a timer holds.
|
|
36
|
+
|
|
37
|
+
### Apply to a derived backend
|
|
38
|
+
|
|
39
|
+
The declarations gained `unsafe.exportHostId`; a derived backend acts on these behaviours:
|
|
40
|
+
|
|
41
|
+
1. A dashboard, an alert or a join keyed on `host.id` stops matching. Key it on `host.name` or
|
|
42
|
+
`service.instance.id`, or set `unsafe.exportHostId: true` and accept that the machine identifier goes to
|
|
43
|
+
every collector and backend.
|
|
44
|
+
2. A query that reads `process.command` stops matching. `service.name` and `process.executable.path` identify
|
|
45
|
+
the process, or set `unsafe.exportProcessCommandArgs: true`.
|
|
46
|
+
3. An application that set `instrumentations.sendLogs: false` and uses winston or bunyan with
|
|
47
|
+
`OTEL_LOGS_EXPORTER=otlp` stops sending those records to the logs pipeline. Set `sendLogs: true`, or an
|
|
48
|
+
override for the one library, to keep them.
|
|
49
|
+
4. An `OTEL_BSP_SCHEDULE_DELAY` or `OTEL_BSP_EXPORT_TIMEOUT` above 2147483647 now falls back to the default
|
|
50
|
+
with a warning. Set a value up to 2147483647.
|
|
51
|
+
|
|
52
|
+
## [1.0.3] - 2026-11-14
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
|
|
56
|
+
- **`shutdownTimeoutMs`** on `TelemetryOptions`: the longest `shutdown()` and `shutdownTelemetry()` wait for the
|
|
57
|
+
final flush, in milliseconds. It defaults to 5000. A value that is not a finite number above zero, or is above
|
|
58
|
+
120000, means the default. When the flush has not finished by then, shutdown emits
|
|
59
|
+
`BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT` and resolves; the flush keeps running in the background and a failure after
|
|
60
|
+
the deadline is dropped. Spans still queued at that point may be lost.
|
|
61
|
+
- `BYMAX_TELEMETRY_EXPORT_FAILED`: a span export failed, so the batch was dropped. The warning names the
|
|
62
|
+
exporter and a short upper-case error code (`UNKNOWN` when there is none), never the payload, the endpoint or
|
|
63
|
+
the error message, and repeats at most once a minute. Before, a collector that was down left the application
|
|
64
|
+
silent.
|
|
65
|
+
- **A bound `TELEMETRY_LOGGER` now receives the two runtime warnings.** `BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT` is
|
|
66
|
+
reported through `errorStructured` under `TELEMETRY_SHUTDOWN_TIMEOUT_KEY` (`TRACING_SHUTDOWN_TIMEOUT`), and
|
|
67
|
+
`BYMAX_TELEMETRY_EXPORT_FAILED` through the optional `warnStructured` under `TELEMETRY_EXPORT_FAILED_KEY`
|
|
68
|
+
(`TRACING_EXPORT_FAILED`), with the exporter kind and the error code as metadata and never a message, an
|
|
69
|
+
endpoint or a payload. With no logger bound, or a logger without the method, they stay process warnings,
|
|
70
|
+
unchanged. Both keys are exported from `./nest`.
|
|
71
|
+
- A **Production** section in the README with measured, scoped figures for sampling, TLS to the collector, a
|
|
72
|
+
collector that is down, CPU, memory and the optional `--max-semi-space-size` lever. "What This Library Does
|
|
73
|
+
NOT Do" says that log records forwarded through `OTEL_LOGS_EXPORTER` are not redacted by this library.
|
|
74
|
+
|
|
75
|
+
### Changed
|
|
76
|
+
|
|
77
|
+
- **`ignorePaths` never ignores a path longer than 2,048 characters**, and the patterns are not run against it,
|
|
78
|
+
so the request keeps its span. Before, the patterns ran against a path of any length. The query is cut first,
|
|
79
|
+
so only the path counts. The cap does not bound a pattern with nested quantifiers on a short path, so anchor
|
|
80
|
+
patterns with no nested quantifiers.
|
|
81
|
+
- **A down collector now ends shutdown at the deadline with a warning, where it used to reject.** Against a
|
|
82
|
+
closed port, shutdown took 7 seconds before this release and rejected with the connection error. The
|
|
83
|
+
exporter's retries outlast the 5-second default, so shutdown now resolves with
|
|
84
|
+
`BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT`.
|
|
85
|
+
|
|
86
|
+
### Apply to a derived backend
|
|
87
|
+
|
|
88
|
+
The declarations gained `shutdownTimeoutMs`, two exported log keys and an optional `warnStructured` on the logger shape; a derived backend acts on these behaviours:
|
|
89
|
+
|
|
90
|
+
1. A caller that branches on the rejection of `shutdown()` or `shutdownTelemetry()` to detect a collector that
|
|
91
|
+
is down now has to read the `BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT` and `BYMAX_TELEMETRY_EXPORT_FAILED`
|
|
92
|
+
warnings instead, or set `shutdownTimeoutMs` above the time the exporter needs to give up. Measured against a
|
|
93
|
+
closed port, a deadline of 5000 ms resolved at 5002 ms with the warning, and a deadline of 20000 ms rejected
|
|
94
|
+
with the connection error after 7.8 s. A collector that accepts a connection and never answers took 10
|
|
95
|
+
seconds, the exporter's own timeout.
|
|
96
|
+
2. Set `shutdownTimeoutMs` to fit the termination grace period of the platform: a shutdown that waits longer
|
|
97
|
+
than the grace period is killed before it finishes.
|
|
98
|
+
3. A host on `TelemetryModule` that binds `TELEMETRY_LOGGER` now gets a structured entry for a down collector.
|
|
99
|
+
Alert on `TRACING_SHUTDOWN_TIMEOUT` and `TRACING_EXPORT_FAILED`; the first replaces the rejection a down
|
|
100
|
+
collector used to cause at shutdown. A logger that should receive the export failure needs a
|
|
101
|
+
`warnStructured(logKey, message, userId, metadata)` method.
|
|
102
|
+
4. A route that `ignorePaths` was ignoring with a path over 2,048 characters now produces a span. Anchor the
|
|
103
|
+
patterns, with no nested quantifiers.
|
|
104
|
+
|
|
11
105
|
## [1.0.2] - 2026-11-13
|
|
12
106
|
|
|
13
107
|
### Security
|
|
@@ -113,6 +207,8 @@ First release.
|
|
|
113
207
|
- Verification from the packed tarball: real `node --import` processes in a CommonJS and a native-ESM
|
|
114
208
|
application, with planted secrets absent from the exported body and negative controls.
|
|
115
209
|
|
|
210
|
+
[1.0.4]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.4
|
|
211
|
+
[1.0.3]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.3
|
|
116
212
|
[1.0.2]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.2
|
|
117
213
|
[1.0.1]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.1
|
|
118
214
|
[1.0.0]: https://github.com/bymaxone/nest-telemetry/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ Install it with the OpenTelemetry peers you use: the command is in [Quick Start]
|
|
|
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
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
|
-
- ✅ **Command line kept out of the resource** — `process.command_args` and `process.
|
|
75
|
+
- ✅ **Command line kept out of the resource** — `process.command_args`, `process.command_line` and `process.command` are dropped
|
|
76
76
|
- ✅ **Explicit, loud opt-outs** — Each off switch is a literal `unsafe.*: true` and emits a `SecurityWarning`
|
|
77
77
|
|
|
78
78
|
---
|
|
@@ -81,11 +81,11 @@ Install it with the OpenTelemetry peers you use: the command is in [Quick Start]
|
|
|
81
81
|
|
|
82
82
|
One package, separate entry points. Import only what your app needs:
|
|
83
83
|
|
|
84
|
-
| Subpath | Import | Purpose
|
|
85
|
-
| ------------ | ------------------------------------ |
|
|
86
|
-
| **SDK** | `@bymax-one/nest-telemetry` | `startTelemetry`, `shutdownTelemetry`, `ignorePaths`, `DEFAULT_REDACTED_QUERY_PARAMS`, types
|
|
87
|
-
| **Register** | `@bymax-one/nest-telemetry/register` | The preload for `node --import`; importing it runs it, and it exports nothing
|
|
88
|
-
| **Nest** | `@bymax-one/nest-telemetry/nest` | `TelemetryModule`, `TelemetryShutdownHook`, `TELEMETRY_LOGGER`, `TELEMETRY_FLUSH_FAILED_KEY`, `ITelemetryErrorLogger` (type) | NestJS 11 |
|
|
84
|
+
| Subpath | Import | Purpose | Dependencies |
|
|
85
|
+
| ------------ | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----------------: |
|
|
86
|
+
| **SDK** | `@bymax-one/nest-telemetry` | `startTelemetry`, `shutdownTelemetry`, `ignorePaths`, `DEFAULT_REDACTED_QUERY_PARAMS`, types | OpenTelemetry peers |
|
|
87
|
+
| **Register** | `@bymax-one/nest-telemetry/register` | The preload for `node --import`; importing it runs it, and it exports nothing | OpenTelemetry peers |
|
|
88
|
+
| **Nest** | `@bymax-one/nest-telemetry/nest` | `TelemetryModule`, `TelemetryShutdownHook`, `TELEMETRY_LOGGER`, `TELEMETRY_FLUSH_FAILED_KEY`, `TELEMETRY_SHUTDOWN_TIMEOUT_KEY`, `TELEMETRY_EXPORT_FAILED_KEY`, `ITelemetryErrorLogger` (type) | NestJS 11 |
|
|
89
89
|
|
|
90
90
|
The SDK entry and `./register` import no `@nestjs/*` package; only `./nest` does. Requiring `./register` from CommonJS throws and names `node --import`.
|
|
91
91
|
|
|
@@ -165,32 +165,34 @@ This package installs no signal handler and shows none, because handling signals
|
|
|
165
165
|
|
|
166
166
|
Every field is the host's policy, and none is required.
|
|
167
167
|
|
|
168
|
-
| Option | Default | What it does
|
|
169
|
-
| -------------------------------------- | ---------------------------- |
|
|
170
|
-
| `enabled` | `true` | `false` never starts the SDK. `OTEL_SDK_DISABLED=true` disables it regardless.
|
|
171
|
-
| `serviceName` | `unknown_service:node` | The service name. `OTEL_SERVICE_NAME` overrides it.
|
|
172
|
-
| `serviceVersion` | none | The service version.
|
|
173
|
-
| `ignoreIncomingRequest` | none | Returns `true` for an incoming request that must produce no server span. `ignorePaths(patterns)` builds one from anchored patterns.
|
|
174
|
-
| `instrumentations.fs` | `false` | File-system instrumentation.
|
|
175
|
-
| `instrumentations.sendLogs` | follows `OTEL_LOGS_EXPORTER` | Whether
|
|
176
|
-
| `instrumentations.overrides` | none | Per-instrumentation configuration, merged over the library's. Redaction settings cannot be replaced here.
|
|
177
|
-
| `extraRedactedQueryParams` | none | Names added to the list redacted from outgoing request URLs. They add to the defaults and never replace them.
|
|
178
|
-
| `unsafe.disableUrlRedaction` | off | Keeps `url.query`, `url.full`, `http.url` and `http.target` as recorded. Literal `true`. Warns.
|
|
179
|
-
| `unsafe.disableRedisArgumentRedaction` | off | Keeps Redis command arguments in `db.query.text`. Literal `true`. Warns.
|
|
180
|
-
| `unsafe.exportProcessCommandArgs` | off | Keeps `process.command_args` and `process.
|
|
181
|
-
| `
|
|
168
|
+
| Option | Default | What it does |
|
|
169
|
+
| -------------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
170
|
+
| `enabled` | `true` | `false` never starts the SDK. `OTEL_SDK_DISABLED=true` disables it regardless. |
|
|
171
|
+
| `serviceName` | `unknown_service:node` | The service name. `OTEL_SERVICE_NAME` overrides it. |
|
|
172
|
+
| `serviceVersion` | none | The service version. |
|
|
173
|
+
| `ignoreIncomingRequest` | none | Returns `true` for an incoming request that must produce no server span. `ignorePaths(patterns)` builds one from anchored patterns. |
|
|
174
|
+
| `instrumentations.fs` | `false` | File-system instrumentation. |
|
|
175
|
+
| `instrumentations.sendLogs` | follows `OTEL_LOGS_EXPORTER` | Whether the records of pino, winston and bunyan are forwarded to the OpenTelemetry logs pipeline. |
|
|
176
|
+
| `instrumentations.overrides` | none | Per-instrumentation configuration, merged over the library's. Redaction settings cannot be replaced here. |
|
|
177
|
+
| `extraRedactedQueryParams` | none | Names added to the list redacted from outgoing request URLs. They add to the defaults and never replace them. |
|
|
178
|
+
| `unsafe.disableUrlRedaction` | off | Keeps `url.query`, `url.full`, `http.url` and `http.target` as recorded. Literal `true`. Warns. |
|
|
179
|
+
| `unsafe.disableRedisArgumentRedaction` | off | Keeps Redis command arguments in `db.query.text`. Literal `true`. Warns. |
|
|
180
|
+
| `unsafe.exportProcessCommandArgs` | off | Keeps `process.command_args`, `process.command_line` and `process.command` in the resource. Literal `true`. Warns. |
|
|
181
|
+
| `unsafe.exportHostId` | off | Keeps `host.id`, the machine identifier, in the resource. Literal `true`. Warns. |
|
|
182
|
+
| `shutdownTimeoutMs` | `5000` | The longest shutdown waits for the final flush. Past it, shutdown warns and resolves. A value that is not a finite number above zero, or is above `120000`, means the default. |
|
|
183
|
+
| `env` | the process environment | The environment the library reads. The OpenTelemetry SDK itself always reads the process environment. |
|
|
182
184
|
|
|
183
185
|
### Environment variables
|
|
184
186
|
|
|
185
187
|
The library reads these in one source file, and a test fails if any other file names `process.env`:
|
|
186
188
|
|
|
187
|
-
| Variable | Effect
|
|
188
|
-
| ----------------------------------------------------------------------------------------------------------------- |
|
|
189
|
-
| `OTEL_SDK_DISABLED` | `true` disables the SDK, in any letter case and with surrounding whitespace ignored, as the SDK reads it.
|
|
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.
|
|
191
|
-
| `OTEL_METRICS_EXPORTER`, `OTEL_LOGS_EXPORTER` | Metrics and logs are exported only when these name an exporter.
|
|
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.
|
|
193
|
-
| `OTEL_NODE_RESOURCE_DETECTORS` | Selects resource detectors, under the specification's names (`service`, `host`, `process`) and the SDK's older ones.
|
|
189
|
+
| Variable | Effect |
|
|
190
|
+
| ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
191
|
+
| `OTEL_SDK_DISABLED` | `true` disables the SDK, in any letter case and with surrounding whitespace ignored, as the SDK reads it. |
|
|
192
|
+
| `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. |
|
|
193
|
+
| `OTEL_METRICS_EXPORTER`, `OTEL_LOGS_EXPORTER` | Metrics and logs are exported only when these name an exporter. |
|
|
194
|
+
| `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. A schedule delay or export timeout above 2147483647 ms is ignored with a warning, because a timer cannot hold it. |
|
|
195
|
+
| `OTEL_NODE_RESOURCE_DETECTORS` | Selects resource detectors, under the specification's names (`service`, `host`, `process`) and the SDK's older ones. |
|
|
194
196
|
|
|
195
197
|
The OpenTelemetry SDK reads these itself, and the library never touches them: `OTEL_EXPORTER_OTLP_*`, `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`, `OTEL_RESOURCE_ATTRIBUTES`.
|
|
196
198
|
|
|
@@ -204,14 +206,17 @@ The OpenTelemetry SDK reads these itself, and the library never touches them: `O
|
|
|
204
206
|
|
|
205
207
|
The start emits these warnings:
|
|
206
208
|
|
|
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.
|
|
209
|
+
| Code | Meaning |
|
|
210
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
211
|
+
| `BYMAX_TELEMETRY_START_FAILED` | The SDK could not start (a peer is missing, or the SDK threw). Tracing is off. |
|
|
212
|
+
| `BYMAX_TELEMETRY_ESM_HOOK_UNAVAILABLE` | The loader hook could not be registered. Native-ESM code is not instrumented. |
|
|
213
|
+
| `BYMAX_TELEMETRY_SERVICE_NAME_MISSING` | No service name is set; spans use `unknown_service:node`. |
|
|
214
|
+
| `BYMAX_TELEMETRY_UNSAFE_REDACTION_DISABLED` | A redaction was turned off through an `unsafe` option. |
|
|
215
|
+
| `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. |
|
|
216
|
+
| `BYMAX_TELEMETRY_RESTART_UNSUPPORTED` | `startTelemetry` was called after a shutdown in the same process, and is refused. |
|
|
217
|
+
| `BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT` | The final flush did not finish within `shutdownTimeoutMs`. Shutdown resolved without it, and spans still queued may be lost. With `TelemetryModule` and a bound `TELEMETRY_LOGGER`, it is reported through `errorStructured` under `TRACING_SHUTDOWN_TIMEOUT` instead. |
|
|
218
|
+
| `BYMAX_TELEMETRY_EXPORT_FAILED` | A span export failed, so the batch was dropped. The warning names the exporter and a short error code, never the payload or the endpoint, and repeats at most once a minute. With `TelemetryModule` and a bound `TELEMETRY_LOGGER` that has `warnStructured`, it is reported through it under `TRACING_EXPORT_FAILED` instead. |
|
|
219
|
+
| `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. |
|
|
215
220
|
|
|
216
221
|
The programmatic `startTelemetry` keeps its rejection when the SDK cannot start, for callers that want it.
|
|
217
222
|
|
|
@@ -223,12 +228,25 @@ The programmatic `startTelemetry` keeps its rejection when the SDK cannot start,
|
|
|
223
228
|
|
|
224
229
|
### Flushing
|
|
225
230
|
|
|
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.
|
|
231
|
+
Awaiting `shutdown()` or `shutdownTelemetry()` means the spans were exported, whoever started the flush, unless the deadline below passed first: 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.
|
|
232
|
+
|
|
233
|
+
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.
|
|
227
234
|
|
|
228
235
|
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
236
|
|
|
230
237
|
---
|
|
231
238
|
|
|
239
|
+
## 🏭 Production
|
|
240
|
+
|
|
241
|
+
Every figure here was measured on one laptop, with Node 24 and a handler that does nothing but answer. Read them as orders of magnitude for your own measurement to confirm, not as promises.
|
|
242
|
+
|
|
243
|
+
- **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.
|
|
244
|
+
- **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.
|
|
245
|
+
- **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.
|
|
246
|
+
- **CPU.** One process, 4 runs per mode, median CPU time per request: 25 µs without the library, 26 µs with it loaded and disabled, 58 µs with a healthy collector (range 35 to 66) and 43 µs with the collector down (range 26 to 65). The extra cost in that handler is roughly 10 to 40 µs per request, and a handler that does real I/O dilutes it. The same configuration varied by up to a factor of two between runs.
|
|
247
|
+
- **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.
|
|
248
|
+
- **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.
|
|
249
|
+
|
|
232
250
|
## 🔄 OpenTelemetry Versions
|
|
233
251
|
|
|
234
252
|
Every `@opentelemetry/*` package is an optional peer. The `0.x` packages break between minors, and `sdk-node` pins its own dependencies to exact versions, so the ranges here name only the generation the tests run against:
|
|
@@ -258,6 +276,7 @@ A caret on a `0.x` version allows patch releases only, so each OpenTelemetry min
|
|
|
258
276
|
| 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
277
|
| Metrics or logs missing | They are off unless `OTEL_METRICS_EXPORTER` or `OTEL_LOGS_EXPORTER` names an exporter. |
|
|
260
278
|
| 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. |
|
|
279
|
+
| No spans arrive and nothing else is logged | `BYMAX_TELEMETRY_EXPORT_FAILED`: the collector did not accept the export. Check the endpoint in `OTEL_EXPORTER_OTLP_ENDPOINT` and that the collector is reachable. |
|
|
261
280
|
| The last spans are lost on `SIGTERM` | Call `app.enableShutdownHooks()` in Nest, or `shutdownTelemetry()` from your own shutdown path. |
|
|
262
281
|
| 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). |
|
|
263
282
|
|
|
@@ -296,7 +315,7 @@ The layers are in the [Security Table](#-security-table) below.
|
|
|
296
315
|
|
|
297
316
|
### Exported on purpose
|
|
298
317
|
|
|
299
|
-
The resource carries `host.name`, `os.*`, `process.pid`, `process.owner`, the executable path and runtime facts, and `service.instance.id`. They identify the instance during an incident. If you do not want them, set `OTEL_NODE_RESOURCE_DETECTORS`.
|
|
318
|
+
The resource carries `host.name`, `os.*`, `process.pid`, `process.owner`, the executable path and runtime facts, and `service.instance.id`. They identify the instance during an incident. If you do not want them, set `OTEL_NODE_RESOURCE_DETECTORS`. It does not carry `host.id`, the machine identifier: that is a stable hardware id, the platform UUID or `/etc/machine-id`, and it is dropped unless you set `unsafe.exportHostId`.
|
|
300
319
|
|
|
301
320
|
### How this is verified
|
|
302
321
|
|
|
@@ -313,7 +332,8 @@ What is **not** redacted is listed flat in [What This Library Does NOT Do](#-wha
|
|
|
313
332
|
| 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 |
|
|
314
333
|
| 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 |
|
|
315
334
|
| 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 |
|
|
316
|
-
| Process command line | `process.command_args` and `process.
|
|
335
|
+
| Process command line | `process.command_args`, `process.command_line` and `process.command` are dropped from the resource, because command-line arguments are a common carrier of secrets |
|
|
336
|
+
| Host id | `host.id`, the machine identifier (the platform UUID, or `/etc/machine-id`), is dropped from the resource; `host.name` stays |
|
|
317
337
|
| Opt-outs | Literal `unsafe.*: true` options only, each emitting a `SecurityWarning`; no environment variable turns redaction off |
|
|
318
338
|
| Overrides | `instrumentations.overrides` is merged under the library's redaction, which is applied again on top |
|
|
319
339
|
| Environment | Read in one module; a test fails if any other file names `process.env` |
|
|
@@ -361,19 +381,19 @@ pnpm check:runtime # packed-tarball consumer proofs
|
|
|
361
381
|
|
|
362
382
|
### SDK: `@bymax-one/nest-telemetry`
|
|
363
383
|
|
|
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`
|
|
384
|
+
| Export | Signature | Purpose |
|
|
385
|
+
| ------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
386
|
+
| `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 |
|
|
387
|
+
| `shutdownTelemetry` | `() => Promise<void>` | Waits for a start in progress, then flushes and stops the SDK; resolves at once when none was started |
|
|
388
|
+
| `ignorePaths` | `(patterns: readonly RegExp[]) => (request) => boolean` | Predicate for `ignoreIncomingRequest`: matches the request path with its query cut; a request with no target, or a path over 2,048 characters, is not matched |
|
|
389
|
+
| `DEFAULT_REDACTED_QUERY_PARAMS` | `readonly string[]` | The credential-parameter list redacted from outgoing request URLs |
|
|
390
|
+
| `TelemetryOptions` | type | The options of `startTelemetry` ([Configuration](#-configuration)) |
|
|
391
|
+
| `TelemetryHandle` | type | `{ enabled: boolean, shutdown(): Promise<void> }` |
|
|
392
|
+
| `UnsafeOptions` | type | The literal-`true` redaction opt-outs |
|
|
393
|
+
| `InstrumentationOptions` | type | `fs`, `sendLogs` and `overrides` |
|
|
394
|
+
| `IncomingRequestTarget` | type | What an incoming-request predicate sees: the request `url` |
|
|
375
395
|
|
|
376
|
-
`ignorePaths` copies each pattern without its `g` and `y` flags, which would keep state between calls. Anchor the patterns at both ends
|
|
396
|
+
`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.
|
|
377
397
|
|
|
378
398
|
### Register: `@bymax-one/nest-telemetry/register`
|
|
379
399
|
|
|
@@ -381,13 +401,15 @@ No exports. `node --import @bymax-one/nest-telemetry/register` registers the loa
|
|
|
381
401
|
|
|
382
402
|
### Nest: `@bymax-one/nest-telemetry/nest`
|
|
383
403
|
|
|
384
|
-
| Export
|
|
385
|
-
|
|
|
386
|
-
| `TelemetryModule`
|
|
387
|
-
| `TelemetryShutdownHook`
|
|
388
|
-
| `TELEMETRY_LOGGER`
|
|
389
|
-
| `TELEMETRY_FLUSH_FAILED_KEY`
|
|
390
|
-
| `
|
|
404
|
+
| Export | Kind | Purpose |
|
|
405
|
+
| -------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
406
|
+
| `TelemetryModule` | module | Global; registers `TelemetryShutdownHook`. List it first in the application module's imports |
|
|
407
|
+
| `TelemetryShutdownHook` | provider | `OnApplicationShutdown`: awaits `shutdownTelemetry()`; a refused flush is reported and never rejects |
|
|
408
|
+
| `TELEMETRY_LOGGER` | token | Optional provider with an `errorStructured(logKey, error)` method for a failed flush and a shutdown that hit its deadline, and an optional `warnStructured(logKey, message, userId, metadata)` for a failed export |
|
|
409
|
+
| `TELEMETRY_FLUSH_FAILED_KEY` | constant | The stable key, `TRACING_FLUSH_FAILED`, under which a failed flush is reported |
|
|
410
|
+
| `TELEMETRY_SHUTDOWN_TIMEOUT_KEY` | constant | The stable key, `TRACING_SHUTDOWN_TIMEOUT`, under which a shutdown that hit `shutdownTimeoutMs` is reported |
|
|
411
|
+
| `TELEMETRY_EXPORT_FAILED_KEY` | constant | The stable key, `TRACING_EXPORT_FAILED`, under which a failed span export is reported, with the exporter kind and the error code as metadata |
|
|
412
|
+
| `ITelemetryErrorLogger` | type | The shape `TELEMETRY_LOGGER` provides: `errorStructured(logKey, error)` and an optional `warnStructured` |
|
|
391
413
|
|
|
392
414
|
---
|
|
393
415
|
|
|
@@ -408,6 +430,7 @@ By design, the following are out of scope:
|
|
|
408
430
|
- ❌ **Redact baggage**
|
|
409
431
|
- ❌ **Redact request and response bodies, or HTTP headers** — they are not captured by default, and they are not redacted if you enable capturing them
|
|
410
432
|
- ❌ **Redact attributes your own code sets**
|
|
433
|
+
- ❌ **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
|
|
411
434
|
- ❌ **Choose a sampler** — configure `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
|
|
412
435
|
- ❌ **Run a collector or a backend** — point `OTEL_EXPORTER_OTLP_ENDPOINT` at one
|
|
413
436
|
- ❌ **Decide your span names** — those come from the instrumentations and from your code
|
package/dist/nest/index.cjs
CHANGED
|
@@ -13,6 +13,17 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
15
15
|
|
|
16
|
+
// src/sdk/warning-sink.ts
|
|
17
|
+
var SINK_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/warning-sink");
|
|
18
|
+
function registerWarningSink(sink) {
|
|
19
|
+
Reflect.set(globalThis, SINK_KEY, sink);
|
|
20
|
+
return () => {
|
|
21
|
+
if (Reflect.get(globalThis, SINK_KEY) === sink) {
|
|
22
|
+
Reflect.deleteProperty(globalThis, SINK_KEY);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
// src/sdk/handle.ts
|
|
17
28
|
var HANDLE_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/handle");
|
|
18
29
|
var PENDING_KEY = /* @__PURE__ */ Symbol.for("@bymax-one/nest-telemetry/pending-start");
|
|
@@ -30,6 +41,8 @@ async function shutdownTelemetry() {
|
|
|
30
41
|
|
|
31
42
|
// src/nest/telemetry-shutdown.hook.ts
|
|
32
43
|
var TELEMETRY_FLUSH_FAILED_KEY = "TRACING_FLUSH_FAILED";
|
|
44
|
+
var TELEMETRY_SHUTDOWN_TIMEOUT_KEY = "TRACING_SHUTDOWN_TIMEOUT";
|
|
45
|
+
var TELEMETRY_EXPORT_FAILED_KEY = "TRACING_EXPORT_FAILED";
|
|
33
46
|
var TELEMETRY_LOGGER = /* @__PURE__ */ Symbol("TELEMETRY_LOGGER");
|
|
34
47
|
exports.TelemetryShutdownHook = class TelemetryShutdownHook {
|
|
35
48
|
/**
|
|
@@ -38,6 +51,15 @@ exports.TelemetryShutdownHook = class TelemetryShutdownHook {
|
|
|
38
51
|
constructor(moduleRef) {
|
|
39
52
|
this.moduleRef = moduleRef;
|
|
40
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Routes the library's two runtime warnings to the structured logger the application bound, when
|
|
56
|
+
* there is one. Without it they stay process warnings.
|
|
57
|
+
*/
|
|
58
|
+
onModuleInit() {
|
|
59
|
+
if (this.structuredLogger() !== void 0) {
|
|
60
|
+
this.releaseSink = registerWarningSink((warning) => this.route(warning));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
41
63
|
/**
|
|
42
64
|
* Flushes and stops the SDK, if one was started.
|
|
43
65
|
*
|
|
@@ -54,7 +76,30 @@ exports.TelemetryShutdownHook = class TelemetryShutdownHook {
|
|
|
54
76
|
await shutdownTelemetry();
|
|
55
77
|
} catch (error) {
|
|
56
78
|
this.report(error);
|
|
79
|
+
} finally {
|
|
80
|
+
this.releaseSink?.();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Writes a warning to the structured logger under its key.
|
|
85
|
+
*
|
|
86
|
+
* @param warning - The warning.
|
|
87
|
+
* @returns Whether the logger took it; a warning with no key or no method on the logger is left
|
|
88
|
+
* to the process warning.
|
|
89
|
+
*/
|
|
90
|
+
route(warning) {
|
|
91
|
+
const logger = this.structuredLogger();
|
|
92
|
+
if (warning.code === "BYMAX_TELEMETRY_SHUTDOWN_TIMEOUT" && typeof logger?.errorStructured === "function") {
|
|
93
|
+
logger.errorStructured(TELEMETRY_SHUTDOWN_TIMEOUT_KEY, new Error(warning.text));
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (warning.code === "BYMAX_TELEMETRY_EXPORT_FAILED" && typeof logger?.warnStructured === "function") {
|
|
97
|
+
logger.warnStructured(TELEMETRY_EXPORT_FAILED_KEY, warning.text, void 0, {
|
|
98
|
+
...warning.fields
|
|
99
|
+
});
|
|
100
|
+
return true;
|
|
57
101
|
}
|
|
102
|
+
return false;
|
|
58
103
|
}
|
|
59
104
|
/**
|
|
60
105
|
* Reports a failed flush: through the structured logger when the application provides a usable
|
|
@@ -108,5 +153,7 @@ exports.TelemetryModule = __decorateClass([
|
|
|
108
153
|
common.Module({ providers: [exports.TelemetryShutdownHook] })
|
|
109
154
|
], exports.TelemetryModule);
|
|
110
155
|
|
|
156
|
+
exports.TELEMETRY_EXPORT_FAILED_KEY = TELEMETRY_EXPORT_FAILED_KEY;
|
|
111
157
|
exports.TELEMETRY_FLUSH_FAILED_KEY = TELEMETRY_FLUSH_FAILED_KEY;
|
|
112
158
|
exports.TELEMETRY_LOGGER = TELEMETRY_LOGGER;
|
|
159
|
+
exports.TELEMETRY_SHUTDOWN_TIMEOUT_KEY = TELEMETRY_SHUTDOWN_TIMEOUT_KEY;
|
package/dist/nest/index.d.cts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { OnApplicationShutdown } from '@nestjs/common';
|
|
1
|
+
import { OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
|
|
2
2
|
|
|
3
3
|
/** Log key of the entry a failed flush leaves, stable so an alert can match it. */
|
|
4
4
|
declare const TELEMETRY_FLUSH_FAILED_KEY = "TRACING_FLUSH_FAILED";
|
|
5
|
+
/** Log key of the entry a shutdown that hit its deadline leaves, stable so an alert can match it. */
|
|
6
|
+
declare const TELEMETRY_SHUTDOWN_TIMEOUT_KEY = "TRACING_SHUTDOWN_TIMEOUT";
|
|
7
|
+
/** Log key of the entry a failed span export leaves, stable so an alert can match it. */
|
|
8
|
+
declare const TELEMETRY_EXPORT_FAILED_KEY = "TRACING_EXPORT_FAILED";
|
|
5
9
|
/** Injection token of the optional structured logger a failed flush is reported through. */
|
|
6
10
|
declare const TELEMETRY_LOGGER: unique symbol;
|
|
7
11
|
/** The one call the hook makes on a structured logger. */
|
|
@@ -13,6 +17,16 @@ interface ITelemetryErrorLogger {
|
|
|
13
17
|
* @param error - The failure.
|
|
14
18
|
*/
|
|
15
19
|
errorStructured(logKey: string, error: Error): void;
|
|
20
|
+
/**
|
|
21
|
+
* Writes a warning entry under a log key, for a failed span export. Optional: a logger without
|
|
22
|
+
* it gets that warning as a process warning.
|
|
23
|
+
*
|
|
24
|
+
* @param logKey - The entry's log key.
|
|
25
|
+
* @param message - The library's own text, never anything from the exporter.
|
|
26
|
+
* @param userId - Always `undefined`.
|
|
27
|
+
* @param metadata - The exporter kind and a short error code.
|
|
28
|
+
*/
|
|
29
|
+
warnStructured?(logKey: string, message: string, userId?: string, metadata?: Record<string, unknown>): void;
|
|
16
30
|
}
|
|
17
31
|
/** What the hook needs of Nest's module reference: to look a provider up anywhere in the application. */
|
|
18
32
|
interface IProviderLookup {
|
|
@@ -27,12 +41,19 @@ interface IProviderLookup {
|
|
|
27
41
|
}): unknown;
|
|
28
42
|
}
|
|
29
43
|
/** Awaits the SDK flush as part of the application's own graceful shutdown. */
|
|
30
|
-
declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
44
|
+
declare class TelemetryShutdownHook implements OnApplicationShutdown, OnModuleInit {
|
|
31
45
|
private readonly moduleRef;
|
|
46
|
+
/** Removes this hook's warning sink, when it registered one. */
|
|
47
|
+
private releaseSink;
|
|
32
48
|
/**
|
|
33
49
|
* @param moduleRef - Resolves the optional structured logger when a flush fails.
|
|
34
50
|
*/
|
|
35
51
|
constructor(moduleRef: IProviderLookup);
|
|
52
|
+
/**
|
|
53
|
+
* Routes the library's two runtime warnings to the structured logger the application bound, when
|
|
54
|
+
* there is one. Without it they stay process warnings.
|
|
55
|
+
*/
|
|
56
|
+
onModuleInit(): void;
|
|
36
57
|
/**
|
|
37
58
|
* Flushes and stops the SDK, if one was started.
|
|
38
59
|
*
|
|
@@ -45,6 +66,14 @@ declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
|
45
66
|
* has been reported. Never rejects.
|
|
46
67
|
*/
|
|
47
68
|
onApplicationShutdown(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Writes a warning to the structured logger under its key.
|
|
71
|
+
*
|
|
72
|
+
* @param warning - The warning.
|
|
73
|
+
* @returns Whether the logger took it; a warning with no key or no method on the logger is left
|
|
74
|
+
* to the process warning.
|
|
75
|
+
*/
|
|
76
|
+
private route;
|
|
48
77
|
/**
|
|
49
78
|
* Reports a failed flush: through the structured logger when the application provides a usable
|
|
50
79
|
* one, else through the Nest logger with the key in the message. Reporting is itself guarded at
|
|
@@ -72,5 +101,5 @@ declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
|
72
101
|
declare class TelemetryModule {
|
|
73
102
|
}
|
|
74
103
|
|
|
75
|
-
export { TELEMETRY_FLUSH_FAILED_KEY, TELEMETRY_LOGGER, TelemetryModule, TelemetryShutdownHook };
|
|
104
|
+
export { TELEMETRY_EXPORT_FAILED_KEY, TELEMETRY_FLUSH_FAILED_KEY, TELEMETRY_LOGGER, TELEMETRY_SHUTDOWN_TIMEOUT_KEY, TelemetryModule, TelemetryShutdownHook };
|
|
76
105
|
export type { ITelemetryErrorLogger };
|
package/dist/nest/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { OnApplicationShutdown } from '@nestjs/common';
|
|
1
|
+
import { OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
|
|
2
2
|
|
|
3
3
|
/** Log key of the entry a failed flush leaves, stable so an alert can match it. */
|
|
4
4
|
declare const TELEMETRY_FLUSH_FAILED_KEY = "TRACING_FLUSH_FAILED";
|
|
5
|
+
/** Log key of the entry a shutdown that hit its deadline leaves, stable so an alert can match it. */
|
|
6
|
+
declare const TELEMETRY_SHUTDOWN_TIMEOUT_KEY = "TRACING_SHUTDOWN_TIMEOUT";
|
|
7
|
+
/** Log key of the entry a failed span export leaves, stable so an alert can match it. */
|
|
8
|
+
declare const TELEMETRY_EXPORT_FAILED_KEY = "TRACING_EXPORT_FAILED";
|
|
5
9
|
/** Injection token of the optional structured logger a failed flush is reported through. */
|
|
6
10
|
declare const TELEMETRY_LOGGER: unique symbol;
|
|
7
11
|
/** The one call the hook makes on a structured logger. */
|
|
@@ -13,6 +17,16 @@ interface ITelemetryErrorLogger {
|
|
|
13
17
|
* @param error - The failure.
|
|
14
18
|
*/
|
|
15
19
|
errorStructured(logKey: string, error: Error): void;
|
|
20
|
+
/**
|
|
21
|
+
* Writes a warning entry under a log key, for a failed span export. Optional: a logger without
|
|
22
|
+
* it gets that warning as a process warning.
|
|
23
|
+
*
|
|
24
|
+
* @param logKey - The entry's log key.
|
|
25
|
+
* @param message - The library's own text, never anything from the exporter.
|
|
26
|
+
* @param userId - Always `undefined`.
|
|
27
|
+
* @param metadata - The exporter kind and a short error code.
|
|
28
|
+
*/
|
|
29
|
+
warnStructured?(logKey: string, message: string, userId?: string, metadata?: Record<string, unknown>): void;
|
|
16
30
|
}
|
|
17
31
|
/** What the hook needs of Nest's module reference: to look a provider up anywhere in the application. */
|
|
18
32
|
interface IProviderLookup {
|
|
@@ -27,12 +41,19 @@ interface IProviderLookup {
|
|
|
27
41
|
}): unknown;
|
|
28
42
|
}
|
|
29
43
|
/** Awaits the SDK flush as part of the application's own graceful shutdown. */
|
|
30
|
-
declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
44
|
+
declare class TelemetryShutdownHook implements OnApplicationShutdown, OnModuleInit {
|
|
31
45
|
private readonly moduleRef;
|
|
46
|
+
/** Removes this hook's warning sink, when it registered one. */
|
|
47
|
+
private releaseSink;
|
|
32
48
|
/**
|
|
33
49
|
* @param moduleRef - Resolves the optional structured logger when a flush fails.
|
|
34
50
|
*/
|
|
35
51
|
constructor(moduleRef: IProviderLookup);
|
|
52
|
+
/**
|
|
53
|
+
* Routes the library's two runtime warnings to the structured logger the application bound, when
|
|
54
|
+
* there is one. Without it they stay process warnings.
|
|
55
|
+
*/
|
|
56
|
+
onModuleInit(): void;
|
|
36
57
|
/**
|
|
37
58
|
* Flushes and stops the SDK, if one was started.
|
|
38
59
|
*
|
|
@@ -45,6 +66,14 @@ declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
|
45
66
|
* has been reported. Never rejects.
|
|
46
67
|
*/
|
|
47
68
|
onApplicationShutdown(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Writes a warning to the structured logger under its key.
|
|
71
|
+
*
|
|
72
|
+
* @param warning - The warning.
|
|
73
|
+
* @returns Whether the logger took it; a warning with no key or no method on the logger is left
|
|
74
|
+
* to the process warning.
|
|
75
|
+
*/
|
|
76
|
+
private route;
|
|
48
77
|
/**
|
|
49
78
|
* Reports a failed flush: through the structured logger when the application provides a usable
|
|
50
79
|
* one, else through the Nest logger with the key in the message. Reporting is itself guarded at
|
|
@@ -72,5 +101,5 @@ declare class TelemetryShutdownHook implements OnApplicationShutdown {
|
|
|
72
101
|
declare class TelemetryModule {
|
|
73
102
|
}
|
|
74
103
|
|
|
75
|
-
export { TELEMETRY_FLUSH_FAILED_KEY, TELEMETRY_LOGGER, TelemetryModule, TelemetryShutdownHook };
|
|
104
|
+
export { TELEMETRY_EXPORT_FAILED_KEY, TELEMETRY_FLUSH_FAILED_KEY, TELEMETRY_LOGGER, TELEMETRY_SHUTDOWN_TIMEOUT_KEY, TelemetryModule, TelemetryShutdownHook };
|
|
76
105
|
export type { ITelemetryErrorLogger };
|