@bymax-one/nest-logger 1.4.22 → 1.4.24
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 +230 -1
- package/README.md +94 -22
- package/dist/observability/index.cjs +112 -0
- package/dist/observability/index.d.cts +55 -0
- package/dist/observability/index.d.ts +55 -0
- package/dist/observability/index.mjs +110 -0
- package/dist/server/index.cjs +516 -163
- package/dist/server/index.d.cts +92 -4
- package/dist/server/index.d.ts +92 -4
- package/dist/server/index.mjs +516 -164
- package/dist/shared/index.cjs +1 -0
- package/dist/shared/index.d.cts +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.mjs +1 -0
- package/package.json +24 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,233 @@ heading here.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [1.4.24] - 2026-11-18
|
|
16
|
+
|
|
17
|
+
### Breaking
|
|
18
|
+
|
|
19
|
+
- **A key that only spells a key the logger writes is dropped, like the key itself.** 1.4.23 dropped
|
|
20
|
+
the owned keys and let the logger's value win over a payload key of the same name, but a payload key
|
|
21
|
+
that spelled one differently was written beside it: `trace_id`, `trace.id` or `TraceId` next to
|
|
22
|
+
`traceId`, `request_id` or `request.id` next to `requestId`, `Level` or `log_key` next to `level`
|
|
23
|
+
or `logKey`. A backend that normalises field names reads those as the same field, so a line could
|
|
24
|
+
still be attributed to another request or trace. The case and the separators `_`, `.` and `-` are
|
|
25
|
+
now folded when names are compared, and a spelling of an owned key is dropped from `meta` and from
|
|
26
|
+
an object message, and a spelling of a key the request context or the active span writes on that
|
|
27
|
+
call is dropped from the payload of `meta`, of an object message and of the raw Pino logger. A key
|
|
28
|
+
that is not a spelling of one (`trace_ids`, `levels`, `my_trace`) is kept, and outside a request or
|
|
29
|
+
a span, where the logger writes no such key, a `request_id` is the payload's own field. **Apply:**
|
|
30
|
+
nothing is required; search the `meta` of your calls and your object messages for a field whose
|
|
31
|
+
name, with the case and the `_`, `.` and `-` removed, is `level`, `time`, `msg`, `service`,
|
|
32
|
+
`deployment`, `logkey`, `userid` or `context`, or that starts with `service.` or `deployment.` in
|
|
33
|
+
any case (`Level`, `time_`, `log_key`, `Context`, `user_id`, `user.id`, `Service.x`): it is no
|
|
34
|
+
longer written on any call. Inside a request or a span the same holds, in `meta`, in an object
|
|
35
|
+
message and in the payload of the raw Pino logger, for the spellings of the keys the logger writes
|
|
36
|
+
there (`request_id`, `tenant_id`). Rename those fields (`severity`, `elapsedMs`,
|
|
37
|
+
`legacyRequestId`, `legacyUserId`).
|
|
38
|
+
|
|
39
|
+
- **The lines the library writes about its destinations are library text, with the error of the host
|
|
40
|
+
in `err`, and that error's message is censored.** The lines of `LOGGER_DESTINATION_WRITE_FAILED`
|
|
41
|
+
and `LOGGER_DESTINATION_INIT_FAILED` (a failed `onInit`, a failed `onRegistryReady`) put the name
|
|
42
|
+
of the destination in their `msg`, for example
|
|
43
|
+
`Log destination "audit" failed to write; the entry was dropped`. `msg` is now library text with
|
|
44
|
+
no name in it (for a write, `A log destination failed to write; the entry was dropped`) and the
|
|
45
|
+
name is in `destination` alone. A failed `onShutdown` was
|
|
46
|
+
written as a text line,
|
|
47
|
+
`[DestinationRegistry] Shutdown failed for "audit": <the stack of the error>`, which put the whole
|
|
48
|
+
stack of a host error on stderr outside any censor. It is now a JSON line like the others, under a
|
|
49
|
+
new reserved key, `LOGGER_DESTINATION_SHUTDOWN_FAILED`, with `destination`, `err` and a constant
|
|
50
|
+
`msg`, and its stack is not written. The message of the error in `err` of these lines, of
|
|
51
|
+
`HTTP_UNEXPECTED_ERROR_DROPPED` and of `LOGGER_OTEL_API_BROKEN` was bounded and escaped only; it
|
|
52
|
+
now also passes the censor of the message of an entry (`redactPaths` and `redactCensor`, under the
|
|
53
|
+
name `message`, whatever the strategy), so a credential in an address a driver could not reach is
|
|
54
|
+
no longer written. A censor that cannot answer leaves the line with an empty message. The other
|
|
55
|
+
text lines on stderr (the entries dropped for a full queue, the totals at shutdown, the spent
|
|
56
|
+
shutdown budget) carry counters and the escaped name of a destination, and are unchanged.
|
|
57
|
+
**Apply:** an alert or a search that matches the old text must match the `logKey` and the
|
|
58
|
+
`destination` field instead: `LOGGER_DESTINATION_WRITE_FAILED` and `LOGGER_DESTINATION_INIT_FAILED`
|
|
59
|
+
as before, and `LOGGER_DESTINATION_SHUTDOWN_FAILED` for a failed shutdown, which a match on
|
|
60
|
+
`Shutdown failed for` no longer finds, and a log shipper that read that line as text now receives
|
|
61
|
+
a JSON entry with `level: "error"`. The stack of the error is no longer written there: if you need
|
|
62
|
+
it, log it in your own `onShutdown`. If you list the reserved keys (a dashboard filter, an
|
|
63
|
+
allow-list), add the new one. A `message` in `redactPaths` now also hides the message of the error
|
|
64
|
+
in these lines.
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
|
|
68
|
+
- **The logger counts what it cuts and what its destinations refuse.** `LOGGER_OBSERVABILITY_TOKEN`
|
|
69
|
+
provides an `ILoggerObservability`: `truncatedTotal(reason)` (the fields cut or replaced for a size
|
|
70
|
+
bound, with `reason` of `'max_entry_size'` or `'max_string_length'`), `destinationErrorTotal()` (the
|
|
71
|
+
writes the destinations refused) and `deliveryState()` (how many destinations finished their
|
|
72
|
+
`onInit`, how many of them failed it, how many refused a write or had an entry dropped, and whether
|
|
73
|
+
one is healthy). The types `ILoggerObservability`,
|
|
74
|
+
`DeliveryState` and `TruncationReason` are exported with it. Nothing changes for a host that does
|
|
75
|
+
not read them.
|
|
76
|
+
|
|
77
|
+
- **A new `@bymax-one/nest-logger/observability` subpath publishes the counters as Prometheus
|
|
78
|
+
metrics and the delivery state as a readiness check.** `BymaxLoggerObservabilityModule` provides
|
|
79
|
+
`LoggerMetricsContributor`, which registers `bymax_logger_entries_truncated_total{reason}` (with
|
|
80
|
+
`reason` of `max_entry_size` or `max_string_length`) and `bymax_logger_destination_errors_total` on
|
|
81
|
+
the registry `@bymax-one/nest-core` serves, and `LoggerHealthIndicator`, named `logger`, which is
|
|
82
|
+
`up` while at least one destination is healthy. `@bymax-one/nest-core` (`^1.6.10`) and `prom-client`
|
|
83
|
+
(`^15`) are optional peer dependencies, imported only by this subpath; the main entry needs neither. **Apply:**
|
|
84
|
+
nothing is required; to publish the metrics, install the two peers and import
|
|
85
|
+
`BymaxLoggerObservabilityModule` next to `BymaxLoggerModule`.
|
|
86
|
+
|
|
87
|
+
#### Apply to a derived backend
|
|
88
|
+
|
|
89
|
+
Nothing is required. A derived backend that builds the Pino instance itself through
|
|
90
|
+
`buildPinoInstance` passes its `DestinationHealth`, which now counts; one that provides its own
|
|
91
|
+
`LOGGER_OBSERVABILITY_TOKEN` must return the three methods of `ILoggerObservability`.
|
|
92
|
+
|
|
93
|
+
`PinoLoggerService` gains one private member, `errorText`, and one public method,
|
|
94
|
+
`censorMessageText(text)`, in its declaration. A subclass that defines a member of either name no
|
|
95
|
+
longer compiles against it: rename yours. Nothing else about its
|
|
96
|
+
constructor or its public methods changes. A service you build by hand over a Pino instance you built
|
|
97
|
+
yourself censors the text of an `Error` with its own redactor, as it does the text of an object
|
|
98
|
+
message; over a Pino instance from `buildPinoInstance` it uses the function the factory leaves on
|
|
99
|
+
that instance, which also covers `redactStrategy: 'paths'`. The merge of the request and trace keys
|
|
100
|
+
that `buildPinoInstance` installs, and the owned-key guard of the service, now compare names with
|
|
101
|
+
their case and the separators `_`, `.` and `-` folded, and the `err` serializer and the derived
|
|
102
|
+
`exception.*` fields it builds censor the message where it opens a stack; nothing is required beyond
|
|
103
|
+
what the Breaking entry above says.
|
|
104
|
+
|
|
105
|
+
### Fixed
|
|
106
|
+
|
|
107
|
+
- **The text of an entry that comes from an `Error` is censored like `err.message`.** The text of
|
|
108
|
+
`error(err)`, `errorStructured(key, err)` and `warn(err)` (and `log`, `fatal`, `debug`, `verbose`
|
|
109
|
+
with an `Error`) is the error's `message`, and it was written as it was while the field
|
|
110
|
+
`err.message` was censored, so `redactPaths: ['message']` left the secret in `msg`. It is now
|
|
111
|
+
censored under the name `message`, also with `redactStrategy: 'paths'`. It is still capped at
|
|
112
|
+
16 KiB like every log message and not cut at `maxStringLength`, which does not apply to the log
|
|
113
|
+
message. The same text is censored where it opens the stack: in `err.stack`, in the stack of each
|
|
114
|
+
`cause` and of each of the `errors` of an `AggregateError`, and in `exception.message` and
|
|
115
|
+
`exception.stacktrace` with `errorFormat: 'semconv'` or `'both'`. It is replaced where the engine
|
|
116
|
+
writes it, right after the first `: ` of the first line (or at the start, for an error with no
|
|
117
|
+
name), by an exact comparison there, never by a search and never by a pattern built from your
|
|
118
|
+
text, so an error whose name repeats or contains its message is censored in the message and not
|
|
119
|
+
in the name, and so is a message that wraps another error with its frames. It holds for an `Error`,
|
|
120
|
+
a subclass and an `Error` of another realm, and for a message with a control character, which the
|
|
121
|
+
stack escapes. A stack whose header is not in the default form loses its frames when its message
|
|
122
|
+
is censored: it becomes its name, if any, and the censored message, as what it holds may be the
|
|
123
|
+
secret too. A stack of a message that nothing censored is not touched. **What this covers,
|
|
124
|
+
precisely:** redaction works on field names, so it covers a field and the text copied from a named
|
|
125
|
+
field (the `message` or `event` of an object message, and the `message` of an `Error` where it
|
|
126
|
+
appears as the text of the entry, in its stack and in the derived `exception.*` fields); it never
|
|
127
|
+
reads the content of a string, so a text a caller passes as a string, such as
|
|
128
|
+
``logger.warn(`card ${number}`)``, is written as it is, and a secret that an error carries in
|
|
129
|
+
another field (a `code`, an own property) is covered only by the name of that field. 1.4.23 said a
|
|
130
|
+
secret in `event` or `message` does not reach `msg`; that holds for the text of an object message
|
|
131
|
+
and, from this release, for the message of an `Error`, and for no other source of the text. **Apply:** nothing is required; a log search that relied on finding a
|
|
132
|
+
censored value in the `msg` of an `Error` no longer finds it.
|
|
133
|
+
- **The derived exception fields are bounded by `maxEntrySizeBytes`.** With `errorFormat: 'semconv'`
|
|
134
|
+
or `'both'`, `exception.type`, `exception.message`, `exception.stacktrace` and `error.type` were
|
|
135
|
+
cut only by the fixed 16 KiB text cap, so with `maxEntrySizeBytes` set below the 64 KiB default
|
|
136
|
+
each could be larger than the ceiling that bounds a serializer's output. Each
|
|
137
|
+
is now cut to `maxEntrySizeBytes` UTF-8 bytes, ending in `…[truncated]` (omitted under a 14-byte ceiling), at a character boundary.
|
|
138
|
+
**Apply:** nothing is required; a query that reads the full message or stack of a very long error
|
|
139
|
+
through these fields gets the cut text when the ceiling is lower than the error, so raise
|
|
140
|
+
`maxEntrySizeBytes` if you need more of it.
|
|
141
|
+
- **A serializer output that `JSON.stringify` cannot measure is bounded.** A value with a reference
|
|
142
|
+
back to an ancestor, or a `BigInt`, passed the size ceiling unmeasured, so a huge one reached the
|
|
143
|
+
line. It is now measured as it is written (a cycle as `"[Circular]"`, a `BigInt` by its digits) and
|
|
144
|
+
truncated when over the ceiling; a repeated reference without a cycle is counted every time it is
|
|
145
|
+
written. **Apply:** nothing is required; an alert on `LOGGER_ENTRY_TRUNCATED` now also fires for
|
|
146
|
+
these values.
|
|
147
|
+
- **A serializer that is itself `undefined` is refused with its type.** `serializers: { a: undefined }`
|
|
148
|
+
said `options.serializers must map every serializer key to a function` and no more; it now ends in
|
|
149
|
+
`Received undefined`, as the other refused members do. **Apply:** code that matches the text of
|
|
150
|
+
that refusal exactly matches the new one.
|
|
151
|
+
|
|
152
|
+
### Documentation
|
|
153
|
+
|
|
154
|
+
- **The README says what a call costs.** A string line, a structured call and an object message
|
|
155
|
+
are timed in its Performance section, with the cost of comparing the names of a payload with the
|
|
156
|
+
keys the logger writes.
|
|
157
|
+
- **The README names every export of a public subpath.** Some exports of the root entry and one of
|
|
158
|
+
`/shared` (the option and context types, the metadata key of the deprecated `@LogContext` and the
|
|
159
|
+
`ReservedLogKey` union) were never named in it; an "Option and context types" table describes
|
|
160
|
+
each, and a spec reads the barrels through the TypeScript compiler and fails when an export is
|
|
161
|
+
missing, so a new one cannot ship unnamed.
|
|
162
|
+
- **The size measurement is said to count a shared sub-object once per reference.** A sub-object that
|
|
163
|
+
several parents share is measured, and written by Pino, once for each reference, so a graph in
|
|
164
|
+
which large sub-objects are shared widely costs time and size in proportion; keep such graphs out
|
|
165
|
+
of the log.
|
|
166
|
+
|
|
167
|
+
## [1.4.23] - 2026-11-17
|
|
168
|
+
|
|
169
|
+
### Breaking
|
|
170
|
+
|
|
171
|
+
- **A payload cannot replace the correlation keys the logger writes from the request context and
|
|
172
|
+
the active span.** A `requestId`, a `tenantId` or another key of the request
|
|
173
|
+
context inside a request, or the trace fields under an active span (`traceId`, `spanId`, `traceFlags`, or the names you set in `otel`,
|
|
174
|
+
or `trace_id`, `span_id` and `trace_flags` with `fieldFormat: 'snake_case'`) carried by an
|
|
175
|
+
object message, by the metadata of a structured call or by the raw Pino logger replaced the
|
|
176
|
+
value the logger had written, so a line could be attributed to another request, tenant or trace.
|
|
177
|
+
The logger's value now wins, except `userId`, which a structured call names as an argument and which keeps winning over the one of the request context; a key the logger does not write, including a `requestId` outside any
|
|
178
|
+
request, is kept as the payload has it, and a key the logger leaves `undefined` does not erase the payload's own value. The merge also drops the payload's own `__proto__` key and its symbol keys, which `Object.assign` used to copy. **Apply:** nothing is required; code that set one of
|
|
179
|
+
these keys on purpose inside a request to override the context no longer gets that, so set it in
|
|
180
|
+
the request context instead (`LogContextService.run`).
|
|
181
|
+
- **A key the logger writes itself can no longer be replaced from `meta` or from an object
|
|
182
|
+
message.** `level`, `time`, `msg`, `service`, `deployment`, `service.*` and `deployment.*`, in the metadata of `info`, `warnStructured` and
|
|
183
|
+
`errorStructured`, were written as a second key of the same name, and a reader that keeps the
|
|
184
|
+
last of a repeated key saw the caller's `level`, `service` or environment. They are dropped from
|
|
185
|
+
the metadata and from an object message, as `logKey`, `userId` and `context` already were.
|
|
186
|
+
**Apply:** nothing is required; a field you named `level`, `time`, `msg`, `service` or
|
|
187
|
+
`deployment` in `meta` is no longer written, so rename it (`severity`, `elapsedMs`, `detail`,
|
|
188
|
+
`owner`, `rollout`).
|
|
189
|
+
|
|
190
|
+
### Fixed
|
|
191
|
+
|
|
192
|
+
- **A plain object passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal`
|
|
193
|
+
is written as the fields of the entry.** `new Logger('Queue').warn({ event: 'QUEUE_DRAINED',
|
|
194
|
+
jobs: 7 })` through `app.useLogger(app.get(PinoLoggerService))` wrote `msg: "[object Object]"`
|
|
195
|
+
and every key was lost. The
|
|
196
|
+
keys are now fields of the entry, through the same redaction and `maxStringLength` pipeline as
|
|
197
|
+
any other field (a `password` is censored, a long string is cut), the entry text is the
|
|
198
|
+
object's `message` string, else its `event` string, else empty, and the keys the logger
|
|
199
|
+
owns are dropped from the object as they are from `meta`. The text is censored under the names of
|
|
200
|
+
the field it came from, also with `redactStrategy: 'paths'`, so a secret in `event` or `message`
|
|
201
|
+
does not reach `msg`, and it is cut at `maxStringLength` like the field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one, keep their own error-only path,
|
|
202
|
+
and a value that is not plain (a class instance, an array) is still written as its string form.
|
|
203
|
+
**Apply:** code that logged an object and got `[object Object]` now gets its fields; a
|
|
204
|
+
dashboard or an alert that matched `[object Object]` in `msg` matches the `event` or `message`
|
|
205
|
+
text instead.
|
|
206
|
+
- **An option that holds `undefined` or `null` is read as not set, in the options and in every
|
|
207
|
+
group.** An `undefined` in a group replaced its default in the spread that merges the two, so `shouldCaptureExceptions: undefined` stayed
|
|
208
|
+
`undefined` and not the default `true`, and a `null` anywhere was refused as a value of the wrong
|
|
209
|
+
kind. Each known key is read by property access, so an `http` or `otel` group written as
|
|
210
|
+
a class instance whose values are getters on its prototype is honored; the spread that merged it skipped them and
|
|
211
|
+
the default won. `false`, `0` and `''` are values you set and are judged as before, and `service`
|
|
212
|
+
is still required: a `null` or an `undefined` service says `options.service is required`, where
|
|
213
|
+
1.4.22 said `must be an object. Received null` for `null`. **Apply:** nothing is required; code
|
|
214
|
+
that relied on a `null` option being refused, or on an explicit `undefined` in a group replacing
|
|
215
|
+
its default, no longer gets that.
|
|
216
|
+
- **A refusal does not print the key of a serializer, and names the type of an `undefined` list
|
|
217
|
+
member.** The refusal of a serializer that is not a function now says
|
|
218
|
+
`options.serializers must map every serializer key to a function`, followed by the type
|
|
219
|
+
received (a member that is itself `undefined` keeps no type), where it printed the key the caller chose, and a member of `redactPaths`,
|
|
220
|
+
`errorOwnFieldNames`, `destinations`, `http.excludePaths` or `http.secretPathSegments`
|
|
221
|
+
that is `undefined` is refused as `Received undefined`, where it had no
|
|
222
|
+
type. **Apply:** code that matches the text of the serializer refusal matches the new one.
|
|
223
|
+
- **The censor rule holds when the logger is built from resolved options.** A `redactCensor` longer
|
|
224
|
+
than `maxStringLength` was refused only by `validateOptions`, so a derived backend that built
|
|
225
|
+
`ResolvedBymaxLoggerModuleOptions` itself and called the factory that builds the logger skipped it,
|
|
226
|
+
and its censor would be cut. The factory refuses it with the same message. **Apply:** a derived
|
|
227
|
+
backend that builds the resolved options keeps its censor within the limit.
|
|
228
|
+
|
|
229
|
+
#### Apply to a derived backend
|
|
230
|
+
|
|
231
|
+
`PinoLoggerService` gains two private members, `nestStyleMessage` and `censorText`, in its
|
|
232
|
+
declaration. A subclass that defines a member of either name no longer compiles against it: rename
|
|
233
|
+
yours. Nothing else about its constructor or its public methods changes.
|
|
234
|
+
|
|
235
|
+
A service you build by hand over a Pino instance from `buildPinoInstance` censors and cuts the text
|
|
236
|
+
of an object message with the function the factory leaves on that instance; over a Pino instance you
|
|
237
|
+
built yourself, it falls back to its own redactor and applies no `maxStringLength`. That function is a property of the instance under a symbol key, so `getRawLogger()` returns an instance that carries it. Code that calls
|
|
238
|
+
`buildPinoInstance` gets the merge in which the keys the logger writes from the request context and
|
|
239
|
+
the span win over a payload, and the owned-key guard applies to the metadata and to an object message
|
|
240
|
+
of every method of the service; nothing is required beyond what the Breaking entries above say.
|
|
241
|
+
|
|
15
242
|
## [1.4.22] - 2026-11-17
|
|
16
243
|
|
|
17
244
|
### Breaking
|
|
@@ -3020,7 +3247,9 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
|
|
|
3020
3247
|
- Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
|
|
3021
3248
|
`release.yml`, Dependabot, and issue templates
|
|
3022
3249
|
|
|
3023
|
-
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.
|
|
3250
|
+
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.24...HEAD
|
|
3251
|
+
[1.4.24]: https://github.com/bymaxone/nest-logger/compare/v1.4.23...v1.4.24
|
|
3252
|
+
[1.4.23]: https://github.com/bymaxone/nest-logger/compare/v1.4.22...v1.4.23
|
|
3024
3253
|
[1.4.22]: https://github.com/bymaxone/nest-logger/compare/v1.4.21...v1.4.22
|
|
3025
3254
|
[1.4.21]: https://github.com/bymaxone/nest-logger/compare/v1.4.20...v1.4.21
|
|
3026
3255
|
[1.4.20]: https://github.com/bymaxone/nest-logger/compare/v1.4.19...v1.4.20
|
package/README.md
CHANGED
|
@@ -63,17 +63,20 @@ The library has **zero direct dependencies**: every package arrives as a peer de
|
|
|
63
63
|
|
|
64
64
|
## 📦 Subpath Exports
|
|
65
65
|
|
|
66
|
-
One package,
|
|
66
|
+
One package, three entry points — import only what your app needs:
|
|
67
67
|
|
|
68
|
-
| Subpath
|
|
69
|
-
|
|
|
70
|
-
| **Server**
|
|
71
|
-
| **Shared**
|
|
68
|
+
| Subpath | Import | Purpose | Dependencies |
|
|
69
|
+
| ----------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----------------------------------------------------------: |
|
|
70
|
+
| **Server** | `@bymax-one/nest-logger` | NestJS module, logger service, interceptor, filter, decorators, destinations | NestJS 11, pino, rxjs, reflect-metadata |
|
|
71
|
+
| **Shared** | `@bymax-one/nest-logger/shared` | Types, constants, the log-key regex — `LogLevel`, `LogEntry`, `ServiceMetadata`, `ResolvedServiceMetadata`, `EmittedServiceResource`, `EmittedDeploymentResource` | None |
|
|
72
|
+
| **Observability** | `@bymax-one/nest-logger/observability` | The Prometheus counters and the readiness check of the logger, for `@bymax-one/nest-core` (see [Metrics and health](#-metrics-and-health)) | `@bymax-one/nest-core` and `prom-client`, both optional peers |
|
|
72
73
|
|
|
73
74
|
```
|
|
74
75
|
shared (zero deps)
|
|
75
76
|
↑
|
|
76
77
|
server
|
|
78
|
+
↑
|
|
79
|
+
observability (optional peers)
|
|
77
80
|
```
|
|
78
81
|
|
|
79
82
|
The `/shared` subpath is safe to import in isomorphic code, test helpers, CLI scripts, or shared packages that must not pull in NestJS.
|
|
@@ -102,6 +105,9 @@ pnpm add -D pino-pretty
|
|
|
102
105
|
|
|
103
106
|
# Optional — OpenTelemetry trace correlation
|
|
104
107
|
pnpm add @opentelemetry/api @opentelemetry/sdk-node
|
|
108
|
+
|
|
109
|
+
# Optional — the /observability subpath (Prometheus counters and the readiness check)
|
|
110
|
+
pnpm add @bymax-one/nest-core prom-client
|
|
105
111
|
```
|
|
106
112
|
|
|
107
113
|
> [!WARNING]
|
|
@@ -250,6 +256,8 @@ Wire the access log in `main.ts` with `applyAccessLog(app)` (see [HTTP Logging](
|
|
|
250
256
|
|
|
251
257
|
Full options reference for `BymaxLoggerModule.forRoot(options)`:
|
|
252
258
|
|
|
259
|
+
A key that holds `undefined` or `null` is read as not set, in the options and in each group, so its default applies; `false`, `0` and `''` are values you set and are judged as such, and `service` is required.
|
|
260
|
+
|
|
253
261
|
### Top-level options
|
|
254
262
|
|
|
255
263
|
| Option | Type | Default | Description |
|
|
@@ -613,7 +621,7 @@ function assertValidLogKey(key: string) {
|
|
|
613
621
|
|
|
614
622
|
These are used by the library; do not reuse them in application code. All are exported as `RESERVED_LOG_KEYS` from `@bymax-one/nest-logger/shared`.
|
|
615
623
|
|
|
616
|
-
`LOGGER_BOOTSTRAP_OK` · `LOGGER_BOOTSTRAP_WARNING` · `LOGGER_SHUTDOWN_OK` · `HTTP_REQUEST_START` · `HTTP_REQUEST_SUCCESS` · `HTTP_REQUEST_REDIRECT` · `HTTP_REQUEST_CLIENT_ERROR` · `HTTP_REQUEST_SERVER_ERROR` · `HTTP_REQUEST_ABORTED` · `HTTP_REQUEST_COMPLETED` · `HTTP_EXCEPTION_HANDLED` · `HTTP_EXCEPTION_UNHANDLED` · `HTTP_UNEXPECTED_ERROR` · `HTTP_UNEXPECTED_ERROR_DROPPED` · `METHOD_EXECUTION` · `METHOD_SLOW_EXECUTION` · `LOGGER_DESTINATION_INIT_FAILED` · `LOGGER_DESTINATION_WRITE_FAILED` · `LOGGER_ENTRY_TRUNCATED` · `LOGGER_REDACTION_FAILED` · `LOGGER_OTEL_API_BROKEN`
|
|
624
|
+
`LOGGER_BOOTSTRAP_OK` · `LOGGER_BOOTSTRAP_WARNING` · `LOGGER_SHUTDOWN_OK` · `HTTP_REQUEST_START` · `HTTP_REQUEST_SUCCESS` · `HTTP_REQUEST_REDIRECT` · `HTTP_REQUEST_CLIENT_ERROR` · `HTTP_REQUEST_SERVER_ERROR` · `HTTP_REQUEST_ABORTED` · `HTTP_REQUEST_COMPLETED` · `HTTP_EXCEPTION_HANDLED` · `HTTP_EXCEPTION_UNHANDLED` · `HTTP_UNEXPECTED_ERROR` · `HTTP_UNEXPECTED_ERROR_DROPPED` · `METHOD_EXECUTION` · `METHOD_SLOW_EXECUTION` · `LOGGER_DESTINATION_INIT_FAILED` · `LOGGER_DESTINATION_WRITE_FAILED` · `LOGGER_DESTINATION_SHUTDOWN_FAILED` · `LOGGER_ENTRY_TRUNCATED` · `LOGGER_REDACTION_FAILED` · `LOGGER_OTEL_API_BROKEN`
|
|
617
625
|
|
|
618
626
|
`HTTP_REQUEST_COMPLETED` is reserved but never emitted: the four status-specific terminal keys already carry the same `duration`. The reserved-but-unwritten set is exported as `RESERVED_LOG_KEYS_NOT_EMITTED`, and a test asserts that every other declared key has a writer in the source.
|
|
619
627
|
|
|
@@ -794,6 +802,41 @@ Providers are singletons: `AsyncLocalStorage` delivers per-request context witho
|
|
|
794
802
|
|
|
795
803
|
---
|
|
796
804
|
|
|
805
|
+
## 📊 Metrics and health
|
|
806
|
+
|
|
807
|
+
The `@bymax-one/nest-logger/observability` subpath publishes what the logger counts as Prometheus counters and as a readiness check, for an application that runs `@bymax-one/nest-core`. It needs the optional peers `@bymax-one/nest-core` and `prom-client`; the main entry imports neither, and nothing is created unless you import the subpath.
|
|
808
|
+
|
|
809
|
+
```typescript
|
|
810
|
+
import { Module } from '@nestjs/common'
|
|
811
|
+
import { BymaxLoggerModule } from '@bymax-one/nest-logger'
|
|
812
|
+
import { BymaxLoggerObservabilityModule } from '@bymax-one/nest-logger/observability'
|
|
813
|
+
|
|
814
|
+
@Module({
|
|
815
|
+
imports: [
|
|
816
|
+
BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } }),
|
|
817
|
+
BymaxLoggerObservabilityModule
|
|
818
|
+
]
|
|
819
|
+
})
|
|
820
|
+
export class AppModule {}
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
`BymaxLoggerObservabilityModule` provides `LoggerMetricsContributor` and `LoggerHealthIndicator`, which `@bymax-one/nest-core` finds by their markers: the contributor is called once at bootstrap with the registry the scrape endpoint serves, and the indicator is listed in the readiness response under the name `logger` (`LOGGER_HEALTH_INDICATOR_NAME`). With `isGlobal: false` on `BymaxLoggerModule` the token is visible only to the modules that import it, so do not import `BymaxLoggerObservabilityModule`: list `LoggerMetricsContributor` and `LoggerHealthIndicator` in the `providers` of a module of yours that imports the same `forRoot` result.
|
|
824
|
+
|
|
825
|
+
### Metrics
|
|
826
|
+
|
|
827
|
+
| Name | Type | Labels | Meaning |
|
|
828
|
+
| --------------------------------------- | ------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
829
|
+
| `bymax_logger_entries_truncated_total` | counter | `reason`: `max_entry_size`, `max_string_length` | Fields of a log entry cut or replaced for a size bound; one field counts once (see `truncatedTotal`) |
|
|
830
|
+
| `bymax_logger_destination_errors_total` | counter | none | Writes to a log destination that threw or rejected; an entry dropped for want of queue room is not one |
|
|
831
|
+
|
|
832
|
+
The counters read the logger's own counts at scrape time, so a log call costs no more than before and each scrape adds the growth since the previous one. Both `reason` series exist from the first scrape, at zero. The label values are a closed set; no destination name, field name or message is ever a label.
|
|
833
|
+
|
|
834
|
+
### Health
|
|
835
|
+
|
|
836
|
+
`LoggerHealthIndicator` is `up` when at least one log destination finished its `onInit` healthy, so an entry can still be delivered, and `down` when none did, which is also the state before the first has finished. Its details carry counts only: `destinations`, `failedInit` and `writeFailing`. The check reads the state the logger already keeps; it sends nothing to a destination and cannot wait on one.
|
|
837
|
+
|
|
838
|
+
---
|
|
839
|
+
|
|
797
840
|
## 🔐 Security Model
|
|
798
841
|
|
|
799
842
|
A logger sees every payload the application handles, so the security posture is about what **never** reaches the sink, and about a sink failure never reaching the application.
|
|
@@ -867,7 +910,7 @@ The OTel mixin passes the active span's identifiers through `isValidTraceId` / `
|
|
|
867
910
|
|
|
868
911
|
### Destination failures are contained
|
|
869
912
|
|
|
870
|
-
Every `write()` runs inside a try/catch. A destination that throws or rejects produces a `LOGGER_DESTINATION_WRITE_FAILED` line on `stderr` (never back through the logger, which would loop) and the entry is dropped for that sink only. The line is written for the first failure and then at most once every 10 seconds per destination, with `suppressed` counting the failures it stands in for, and shutdown says how many writes the destination failed in total when it failed more than one. A destination whose `onInit()` rejects is reported as `LOGGER_DESTINATION_INIT_FAILED` and removed from the fan-out and shutdown, and never blocks boot.
|
|
913
|
+
Every `write()` runs inside a try/catch. A destination that throws or rejects produces a `LOGGER_DESTINATION_WRITE_FAILED` line on `stderr` (never back through the logger, which would loop) and the entry is dropped for that sink only. The line is written for the first failure and then at most once every 10 seconds per destination, with `suppressed` counting the failures it stands in for, and shutdown says how many writes the destination failed in total when it failed more than one. A destination whose `onInit()` rejects is reported as `LOGGER_DESTINATION_INIT_FAILED` and removed from the fan-out and shutdown, and never blocks boot. One whose `onShutdown()` fails is reported as `LOGGER_DESTINATION_SHUTDOWN_FAILED`, and the teardown of the others goes on. These lines are library text: the destination is in the `destination` field and never in `msg`, and the error is in `err` (its type and message, never its stack), where the message passes the censor of the message of an entry (`redactPaths`, `redactCensor`), so a credential in the address a destination could not reach is not written.
|
|
871
914
|
|
|
872
915
|
### What redaction covers, and what it cannot
|
|
873
916
|
|
|
@@ -906,13 +949,13 @@ An interpolated value has no name, so no configuration can redact it. **A value
|
|
|
906
949
|
|
|
907
950
|
### Bounded field size
|
|
908
951
|
|
|
909
|
-
Every serializer, the default `err` one and any you supply, is wrapped so a field whose serialized JSON exceeds `maxEntrySizeBytes` (64 KB by default) is replaced by an envelope with `_truncated`, `_logKey: 'LOGGER_ENTRY_TRUNCATED'`, `_originalSize` and a 200-character `_preview`.
|
|
952
|
+
Every serializer, the default `err` one and any you supply, is wrapped so a field whose serialized JSON exceeds `maxEntrySizeBytes` (64 KB by default) is replaced by an envelope with `_truncated`, `_logKey: 'LOGGER_ENTRY_TRUNCATED'`, `_originalSize` and a 200-character `_preview`. A reference back to an ancestor and a `BigInt` are measured as they are written, and a sub-object that is shared by several parents is measured once for each reference, as Pino writes it, so do not log a graph in which large sub-objects are shared widely; an output that cannot be read at all (a `toJSON` or a getter that throws) is written as `{ _redactionFailed: true, _logKey: 'LOGGER_REDACTION_FAILED' }`. With `errorFormat: 'semconv'` or `'both'`, each derived `exception.type`, `exception.message`, `exception.stacktrace` and `error.type` is cut to `maxEntrySizeBytes` UTF-8 bytes as well, ending in `…[truncated]` (omitted under a 14-byte ceiling), on top of the 16 KiB text cap.
|
|
910
953
|
|
|
911
954
|
### Bounded string length
|
|
912
955
|
|
|
913
|
-
`maxEntrySizeBytes` bounds what a serializer returns, and a string under a metadata key is the caller's own data, written as given. `maxStringLength` bounds that string too, and is off until set. A string longer than the limit is cut to that many characters (UTF-16 units, so a cut never splits a surrogate pair) and ends with `…[truncated]`; what is written is the limit plus 12 characters at most, and a string of exactly the limit is written whole.
|
|
956
|
+
`maxEntrySizeBytes` bounds what a serializer returns and the derived exception fields, and a string under a metadata key is the caller's own data, written as given. `maxStringLength` bounds that string too, and is off until set. A string longer than the limit is cut to that many characters (UTF-16 units, so a cut never splits a surrogate pair) and ends with `…[truncated]`; what is written is the limit plus 12 characters at most, and a string of exactly the limit is written whole.
|
|
914
957
|
|
|
915
|
-
It applies to every string value of the record at any depth, in an object or an array, after redaction: a value a redaction rule censors is the censor and not a cut text. It does not apply to a key, to a value that is not text, to the log message (already capped at 16384 characters), to the `logKey` of the entry (an identifier, and `event.name` is derived from it), to the bindings of a logger (the service identity and the `context` of an `@InjectLogger` logger are written once, whole), to anything under a key that has a serializer (`err` and the keys of `serializers`): this limit does not cut the error you log under `err`, and `maxEntrySizeBytes` caps what a serializer returns when that output serializes to JSON. The event name and the `exception.type`, `exception.message`, `exception.stacktrace` and `error.type` fields written from an error are added after the cut, so the limit does not apply to them, and the exception fields among them
|
|
958
|
+
It applies to every string value of the record at any depth, in an object or an array, after redaction: a value a redaction rule censors is the censor and not a cut text. It does not apply to a key, to a value that is not text, to the log message (already capped at 16384 characters), to the `logKey` of the entry (an identifier, and `event.name` is derived from it), to the bindings of a logger (the service identity and the `context` of an `@InjectLogger` logger are written once, whole), to anything under a key that has a serializer (`err` and the keys of `serializers`): this limit does not cut the error you log under `err`, and `maxEntrySizeBytes` caps what a serializer returns when that output serializes to JSON. The event name and the `exception.type`, `exception.message`, `exception.stacktrace` and `error.type` fields written from an error are added after the cut, so the limit does not apply to them, and the exception fields among them are cut by `maxEntrySizeBytes` (in UTF-8 bytes) and by the cap of 16384 characters, and a key of your own with one of those names is cut like any other string. The names left whole are matched on the root key, so a key of your own named like a key of `serializers` is left whole too. An `Error` placed in the metadata under any other key is data of the record when the cut runs, so its message, its stack and its own fields are cut like any other string. The limit is an integer from 64, because the strings the library writes into a record itself (trace and span ids) are shorter than that. A string the caller supplies, such as a `userId`, a `tenantId`, or a `requestId` taken from an inbound request header, is cut like any other when it is longer than the limit. Setting it makes the record walk run even when no field name is covered (`shouldDisableDefaultRedact: true` and no `redactPaths`), and the walk writes a boxed `String` or `Number`, a `Buffer`, a `Uint8Array` and an `Error` in the metadata as the default redaction already does: a two-byte `Buffer` is written as `[Binary 2 bytes]` and not as `{"type":"Buffer","data":[104,105]}`, while a boxed `Number` is written as `{}` and a boxed `String` as a map of its indexes (`{"0":"a","1":"b","2":"c"}` for `new String('abc')`), as the default redaction writes them. A `redactCensor` longer than the limit is refused at startup, because a censor the cut shortened would no longer be the text you look for in place of a secret.
|
|
916
959
|
|
|
917
960
|
### Security Checklist
|
|
918
961
|
|
|
@@ -989,7 +1032,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
989
1032
|
| `warnStructured` | `(logKey, msg, userId?, meta?)` | Structured warn log — takes a **message string** |
|
|
990
1033
|
| `errorStructured` | `(logKey, error, userId?, meta?)` | Structured error log — takes an **`Error`**, serialized to `err` |
|
|
991
1034
|
|
|
992
|
-
`meta` carries arbitrary fields, except that `logKey`, `userId` and `context` belong to the payload (read from the authenticated ALS scope, so a metadata bag cannot forge them) and `__proto__`, `constructor` and `prototype` are dropped, since they name a prototype chain rather than a field.
|
|
1035
|
+
`meta` carries arbitrary fields, except that `logKey`, `userId` and `context` belong to the payload (read from the authenticated ALS scope, so a metadata bag cannot forge them), `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` are written by the logger itself and are dropped from `meta`, and `__proto__`, `constructor` and `prototype` are dropped, since they name a prototype chain rather than a field. A key the logger writes from the request context or from the active span (`requestId`, `tenantId`, the trace fields) keeps the logger's value when the payload carries the same key, for `meta`, an object message and the raw Pino logger alike, except `userId`, which a call names as an argument and which wins over the one of the request context; a key the logger does not write, such as a `requestId` outside a request, keeps the payload's own value. A key that only spells one of these keys, or an owned key, is dropped like the key itself (`Level`, `log_key`, `trace_id` for `traceId`, `request.id` for `requestId`): names are compared with the case and the separators `_`, `.` and `-` folded, so a backend that normalises names cannot read the payload's copy as the logger's field. The raw Pino logger from `getRawLogger()` bypasses the owned-key guards of `meta` and of an object message, so a payload can still repeat `level`, `service` or `userId` there; the request and trace keys still win, and redaction still applies.
|
|
993
1036
|
|
|
994
1037
|
**NestJS `LoggerService` bridge** — the variadic contract NestJS calls, so `app.useLogger()` works. These take a message, not a log key.
|
|
995
1038
|
|
|
@@ -1002,13 +1045,15 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
1002
1045
|
| `fatal` | `(message, ...optionalParams)` | → Pino `fatal` |
|
|
1003
1046
|
| `error` | `(message \| Error, stack?, context?)` | An `Error` routes to the serialized `err` path |
|
|
1004
1047
|
|
|
1048
|
+
**An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. Redaction works on field names and never reads the content of a string, so a text a caller passes as a string, such as ``logger.warn(`card ${number}`)``, is written as it is.
|
|
1049
|
+
|
|
1005
1050
|
**Helpers**
|
|
1006
1051
|
|
|
1007
1052
|
| Method | Signature | Notes |
|
|
1008
1053
|
| -------------- | ------------ | ----------------------------------------------------------------- |
|
|
1009
1054
|
| `child` | `(bindings)` | New `PinoLoggerService` over a Pino child logger |
|
|
1010
1055
|
| `setContext` | `(context)` | Global label — ⚠️ singleton; prefer `@InjectLogger(MyClass.name)` |
|
|
1011
|
-
| `getRawLogger` | `()` | The underlying Pino instance
|
|
1056
|
+
| `getRawLogger` | `()` | The underlying Pino instance; bypasses the `meta` guards above |
|
|
1012
1057
|
|
|
1013
1058
|
> [!NOTE]
|
|
1014
1059
|
> There is no `fatalStructured` / `debugStructured`. Structured `fatal` and `debug` helpers are out of scope until a consumer needs them; use `getRawLogger()` in the meantime.
|
|
@@ -1035,7 +1080,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
1035
1080
|
|
|
1036
1081
|
### Injection tokens and helpers
|
|
1037
1082
|
|
|
1038
|
-
Every token is a `Symbol`, never a string, so it cannot collide with one of yours. Inject with an explicit `@Inject(TOKEN)`: the package is built without decorator metadata, and so is any consumer built the same way.
|
|
1083
|
+
Every token is a `Symbol`, never a string, so it cannot collide with one of yours; `LOGGER_OBSERVABILITY_TOKEN` is registered in the global symbol registry (`Symbol.for`), so a host that loads the package through ESM and CommonJS at once holds one token, and it collides only with a symbol registered under the identical description. Inject with an explicit `@Inject(TOKEN)`: the package is built without decorator metadata, and so is any consumer built the same way.
|
|
1039
1084
|
|
|
1040
1085
|
| Export | Provides | Use it to |
|
|
1041
1086
|
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -1043,11 +1088,34 @@ Every token is a `Symbol`, never a string, so it cannot collide with one of your
|
|
|
1043
1088
|
| `LOGGER_PINO_INSTANCE_TOKEN` | the underlying Pino instance | hand it to a library that wants a Pino logger |
|
|
1044
1089
|
| `LOGGER_DESTINATIONS_TOKEN` | the destinations array, `readonly ILogDestination[]` | inspect what is registered; do not mutate it |
|
|
1045
1090
|
| `LOGGER_REDACTOR_TOKEN` | the by-name redaction function, `(value: unknown) => unknown`. With `redactStrategy: 'paths'` it censors no name outside an `Error`, because Pino's path redaction then runs at write time instead | apply the module's by-name redaction to a value of your own under the default `'names'` strategy; do not treat it as a sanitization boundary under `'paths'`. |
|
|
1091
|
+
| `LOGGER_OBSERVABILITY_TOKEN` | the `ILoggerObservability` view of the logger: its counters and the delivery state (see below) |
|
|
1046
1092
|
| `LOG_CONTEXT_TOKEN` | the `LogContextService` instance (an alias of the class) | inject the context by token |
|
|
1047
1093
|
| `REDACT_COMMON_FIELDS` | the default sensitive field **names**, matched at any depth | extend the defaults by reference instead of copying the list |
|
|
1048
1094
|
| `DEFAULT_REDACT_PATHS` | the legacy path expansion of those names | only with `redactStrategy: 'paths'` |
|
|
1049
1095
|
| `isValidTraceId(id)` | `true` for 32 lowercase hex characters that are not all zeros | apply the rule the trace mixin applies before it injects an id |
|
|
1050
1096
|
|
|
1097
|
+
### Option and context types (from `@bymax-one/nest-logger`)
|
|
1098
|
+
|
|
1099
|
+
| Type | What it is |
|
|
1100
|
+
| ------------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
1101
|
+
| `BymaxLoggerModuleOptions` | the options of `forRoot` (the Configuration tables above) |
|
|
1102
|
+
| `BymaxLoggerModuleAsyncOptions` | the options of `forRootAsync`: a factory, a class or an existing provider that returns them |
|
|
1103
|
+
| `HttpOptions`, `OtelOptions` | the `http` and `otel` groups of the options |
|
|
1104
|
+
| `ErrorOwnFieldsMode` | `'all' \| 'safe'`, the values of `errorOwnFields` |
|
|
1105
|
+
| `LogContextBag` | the store of a request scope: `requestId`, `tenantId`, `userId`, `traceId`, `spanId` and any key of your own |
|
|
1106
|
+
| `IncomingHeaders` | the raw inbound headers an HTTP layer delivers: `Record<string, string \| string[] \| undefined>` |
|
|
1107
|
+
| `LOG_CONTEXT_METADATA_KEY` | the reflect-metadata key under which the deprecated `@LogContext` stores its label |
|
|
1108
|
+
|
|
1109
|
+
### Counters and delivery state (from `@bymax-one/nest-logger`)
|
|
1110
|
+
|
|
1111
|
+
The logger counts what it cuts and what its destinations refuse, and exposes the counts with the state of the fan-out through `LOGGER_OBSERVABILITY_TOKEN`, typed `ILoggerObservability`. Nothing is sent to a destination to read them, and the counts start at zero when the module starts.
|
|
1112
|
+
|
|
1113
|
+
| Method | Returns | What it is |
|
|
1114
|
+
| ------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1115
|
+
| `truncatedTotal(reason)` | `number` | the fields cut or replaced for a size bound, one cut counting once; the text of an object message is the entry's `msg` field, so an `event` is cut twice, as a field and as `msg`. `TruncationReason` is `'max_entry_size'` (a serializer output over `maxEntrySizeBytes` or one that cannot be measured, or a derived `exception.*` field cut to it) or `'max_string_length'` (a string cut at `maxStringLength`, the text of an object message among them) |
|
|
1116
|
+
| `destinationErrorTotal()` | `number` | the writes the destinations refused (they threw or rejected), over all destinations; an entry dropped for want of queue room is not counted here |
|
|
1117
|
+
| `deliveryState()` | `DeliveryState` | `destinations` that finished their `onInit`, how many of them `failedInit`, how many are `writeFailing` (refused a write or had an entry dropped), and whether `hasHealthySink`: at least one destination is healthy |
|
|
1118
|
+
|
|
1051
1119
|
### Level maps (from `@bymax-one/nest-logger`)
|
|
1052
1120
|
|
|
1053
1121
|
`LogEntry.level` is the Pino string label, not the numeric code. A destination writing a numeric column converts with the exported maps:
|
|
@@ -1107,6 +1175,8 @@ type LogEntry = {
|
|
|
1107
1175
|
}
|
|
1108
1176
|
```
|
|
1109
1177
|
|
|
1178
|
+
`ReservedLogKey` (also from `/shared`) is the union of every value of `RESERVED_LOG_KEYS`, for constraining a log-key argument.
|
|
1179
|
+
|
|
1110
1180
|
Under `resourceFormat: 'flat'` there is no `service` object: the values arrive as dotted top-level keys (`"service.instance.id"`), which the index signature admits.
|
|
1111
1181
|
|
|
1112
1182
|
### `ILogDestination`
|
|
@@ -1152,15 +1222,16 @@ The `PrettyDevDestination` errors are thrown inside `onInit`, which the registry
|
|
|
1152
1222
|
|
|
1153
1223
|
### Log keys
|
|
1154
1224
|
|
|
1155
|
-
| Code
|
|
1156
|
-
|
|
|
1157
|
-
| `LOGGER_DESTINATION_INIT_FAILED`
|
|
1158
|
-
| `
|
|
1159
|
-
| `
|
|
1160
|
-
| `
|
|
1161
|
-
| `
|
|
1162
|
-
| `
|
|
1163
|
-
| `
|
|
1225
|
+
| Code | Surfaces as | When | Action |
|
|
1226
|
+
| ------------------------------------ | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
1227
|
+
| `LOGGER_DESTINATION_INIT_FAILED` | NDJSON line on `stderr` | `destination.onInit()` throws or rejects | Sink is removed from the write fan-out and shutdown; boot continues |
|
|
1228
|
+
| `LOGGER_DESTINATION_SHUTDOWN_FAILED` | NDJSON line on `stderr` | `destination.onShutdown()` throws, rejects or does not settle within the shutdown budget | The teardown of the other destinations goes on; anything the sink still held is lost |
|
|
1229
|
+
| `LOGGER_DESTINATION_WRITE_FAILED` | NDJSON line on `stderr` | `destination.write()` throws or rejects | Entry dropped for that destination; others continue |
|
|
1230
|
+
| `HTTP_UNEXPECTED_ERROR_DROPPED` | NDJSON line on `stderr` | `PinoUnexpectedErrorSink` could not log a report (the logger threw, or the report could not be read) | The report is dropped; the line names why. The response is unaffected |
|
|
1231
|
+
| `LOGGER_OTEL_API_BROKEN` | NDJSON line on `stderr`, once | `@opentelemetry/api` is installed but throws while loading, or exports no usable `trace` namespace | Reinstall it, or turn `otel.shouldAutoInjectTraceContext` off; until then `traceId` and `spanId` are absent |
|
|
1232
|
+
| `LOGGER_BOOTSTRAP_WARNING` | log entry with `reason: 'OTEL_API_UNAVAILABLE'` | `otel.shouldAutoInjectTraceContext` is on and `@opentelemetry/api` cannot be resolved | Install `@opentelemetry/api`, or turn the option off; until then `traceId` and `spanId` are absent |
|
|
1233
|
+
| `LOGGER_ENTRY_TRUNCATED` | `_logKey` in the envelope | a serialized field exceeds `maxEntrySizeBytes` | Reduce the payload or raise the ceiling |
|
|
1234
|
+
| `LOGGER_REDACTION_FAILED` | `_logKey` in the envelope, with `_redactionFailed: true` | a record cannot be walked by the redactor (a throwing getter, a hostile proxy in the metadata) | The record is dropped whole, never partly emitted; the message and ambient context stay. Find the value that broke the walk |
|
|
1164
1235
|
|
|
1165
1236
|
---
|
|
1166
1237
|
|
|
@@ -1183,6 +1254,7 @@ Measured by this repository's own benchmark (`pnpm bench`, see [bench/README.md]
|
|
|
1183
1254
|
|
|
1184
1255
|
- **About 274,000 entries/s** through the full production path, which retains 0.345× of the throughput of the bare wrapper (no redaction, no mixin) measured the same way.
|
|
1185
1256
|
- The legacy `redactStrategy: 'paths'` is about seventy times slower in the same bench run, and its cost grows with the number of default paths.
|
|
1257
|
+
- One call through the shipped configuration, for an entry of four fields (the median of five runs of 300,000 calls on one machine under Node 24): a string line about 1.85 µs, a structured call with `meta` about 3.4 µs, and an object message about 3.3 µs, which is about 1.8 times the string line and costs the same work as `meta`. Comparing the names of a payload with the keys the logger owns and writes adds about 0.2 µs to a structured call and about 0.25 µs to an object message.
|
|
1186
1258
|
|
|
1187
1259
|
Absolute figures depend on the machine; the benchmark gates the ratio so a regression fails CI.
|
|
1188
1260
|
|