@bymax-one/nest-logger 1.2.0 → 1.2.1
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 +138 -1
- package/README.md +171 -13
- package/dist/server/index.cjs +315 -40
- package/dist/server/index.d.cts +127 -13
- package/dist/server/index.d.ts +127 -13
- package/dist/server/index.mjs +327 -49
- package/dist/shared/index.d.cts +102 -3
- package/dist/shared/index.d.ts +102 -3
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -96,6 +96,79 @@ interface ServiceMetadata {
|
|
|
96
96
|
readonly name: string;
|
|
97
97
|
/** OTel attribute `service.version` — semver, commit SHA, or build tag. */
|
|
98
98
|
readonly version: string;
|
|
99
|
+
/**
|
|
100
|
+
* OTel attribute `service.namespace` (**Stable**) — the group the service
|
|
101
|
+
* belongs to, e.g. a team, a bounded context or a tenant of the platform.
|
|
102
|
+
* Two services may share a `name` as long as their namespaces differ.
|
|
103
|
+
*/
|
|
104
|
+
readonly namespace?: string;
|
|
105
|
+
/**
|
|
106
|
+
* OTel attribute `service.instance.id` (**Stable**) — identifies ONE running
|
|
107
|
+
* instance, so the triplet (namespace, name, instanceId) is globally unique.
|
|
108
|
+
*
|
|
109
|
+
* The library never generates this. A value minted here would be the logger's
|
|
110
|
+
* rather than the OpenTelemetry Resource's, so logs and traces would disagree
|
|
111
|
+
* about which instance served a request, and it would change on every restart
|
|
112
|
+
* while looking authoritative. Supply it from the platform — the Kubernetes
|
|
113
|
+
* pod UID, the ECS task ARN, the VM instance id — or through
|
|
114
|
+
* `OTEL_RESOURCE_ATTRIBUTES`, which is the same source the SDK reads.
|
|
115
|
+
*
|
|
116
|
+
* Treat it as HIGH cardinality: fine as a log field, not as a metric label.
|
|
117
|
+
*/
|
|
118
|
+
readonly instanceId?: string;
|
|
119
|
+
/**
|
|
120
|
+
* OTel attribute `deployment.environment.name` (**Stable**) — `production`,
|
|
121
|
+
* `staging`, and so on. Falls back to `NODE_ENV` when omitted.
|
|
122
|
+
*
|
|
123
|
+
* The older `deployment.environment` spelling is **Deprecated** in the
|
|
124
|
+
* semantic conventions and is never emitted.
|
|
125
|
+
*/
|
|
126
|
+
readonly environment?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The `service` block as it appears in an EMITTED record, under the default
|
|
130
|
+
* `resourceFormat: 'nested'`.
|
|
131
|
+
*
|
|
132
|
+
* Distinct from {@link ServiceMetadata} on purpose, and the distinction is the
|
|
133
|
+
* kind of defect this library has already been bitten by once: a published type
|
|
134
|
+
* that describes something the runtime never emits. `ServiceMetadata` is what a
|
|
135
|
+
* consumer CONFIGURES — flat option names like `instanceId` and `environment`.
|
|
136
|
+
* What comes out is the flattened OTel attribute path: `service.instance.id`
|
|
137
|
+
* nests as `service: { instance: { id } }`, and the environment is not under
|
|
138
|
+
* `service` at all, it is `deployment.environment.name`. Typing the emitted
|
|
139
|
+
* record with the configuration interface would advertise `entry.service.instanceId`
|
|
140
|
+
* to every consumer, and that property does not exist on any entry.
|
|
141
|
+
*
|
|
142
|
+
* Under `resourceFormat: 'flat'` these values appear as dotted top-level keys
|
|
143
|
+
* (`"service.instance.id"`), which {@link LogEntry}'s index signature already
|
|
144
|
+
* admits — a flat record simply has no `service` object.
|
|
145
|
+
*/
|
|
146
|
+
interface EmittedServiceResource {
|
|
147
|
+
/** OTel `service.name`. */
|
|
148
|
+
readonly name: string;
|
|
149
|
+
/** OTel `service.version`. */
|
|
150
|
+
readonly version: string;
|
|
151
|
+
/** OTel `service.namespace`, when resolved. */
|
|
152
|
+
readonly namespace?: string;
|
|
153
|
+
/** OTel `service.instance.id`, nested as the attribute path spells it. */
|
|
154
|
+
readonly instance?: {
|
|
155
|
+
readonly id: string;
|
|
156
|
+
};
|
|
157
|
+
/** Consumer-supplied extras carried through from the `service` option. */
|
|
158
|
+
readonly [key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The `deployment` block as it appears in an EMITTED record under
|
|
162
|
+
* `resourceFormat: 'nested'`, carrying `deployment.environment.name`.
|
|
163
|
+
*
|
|
164
|
+
* Absent entirely when no source resolved an environment. The deprecated
|
|
165
|
+
* `deployment.environment` spelling is never emitted.
|
|
166
|
+
*/
|
|
167
|
+
interface EmittedDeploymentResource {
|
|
168
|
+
/** OTel `deployment.environment.name`, flattened from its attribute path. */
|
|
169
|
+
readonly environment: {
|
|
170
|
+
readonly name: string;
|
|
171
|
+
};
|
|
99
172
|
}
|
|
100
173
|
|
|
101
174
|
/**
|
|
@@ -191,6 +264,52 @@ interface BymaxLoggerModuleOptions {
|
|
|
191
264
|
* path-matching semantics; expect it to be removed in a future major.
|
|
192
265
|
*/
|
|
193
266
|
redactStrategy?: 'names' | 'paths';
|
|
267
|
+
/**
|
|
268
|
+
* Shape of the resource/service identity on every entry. Default `'nested'`.
|
|
269
|
+
*
|
|
270
|
+
* - `'nested'` — `{ service: { name, version, namespace, instance: { id } },
|
|
271
|
+
* deployment: { environment: { name } } }`. The historical shape, extended;
|
|
272
|
+
* no existing query breaks.
|
|
273
|
+
* - `'flat'` — the dotted OTel attribute names verbatim (`service.name`,
|
|
274
|
+
* `service.instance.id`, `deployment.environment.name`), which is what a
|
|
275
|
+
* collector mapping log fields onto resource attributes reads directly.
|
|
276
|
+
*
|
|
277
|
+
* Both carry the same values; only the key shape differs.
|
|
278
|
+
*/
|
|
279
|
+
resourceFormat?: 'nested' | 'flat';
|
|
280
|
+
/**
|
|
281
|
+
* Field carrying the machine-readable event name, mirroring `logKey`.
|
|
282
|
+
* Default `'event.name'`; `false` emits nothing.
|
|
283
|
+
*
|
|
284
|
+
* `logKey` stays exactly as it is — this is additive, never a rename.
|
|
285
|
+
*
|
|
286
|
+
* The value is meant to be mapped onto the **`EventName`** field of the
|
|
287
|
+
* OpenTelemetry LogRecord, which is Stable in the Logs Data Model. Note that
|
|
288
|
+
* the same-named `event.name` *attribute* is Deprecated in the semantic
|
|
289
|
+
* conventions precisely because the value belongs in that top-level field
|
|
290
|
+
* instead; the key here is the JSON carrier, not an OTLP attribute. The name is
|
|
291
|
+
* configurable so a pipeline that maps a different key can use it.
|
|
292
|
+
*
|
|
293
|
+
* Keep event names LOW cardinality — `payment.failed`, not
|
|
294
|
+
* `payment.failed.918231781`. Identifiers belong in their own fields.
|
|
295
|
+
*/
|
|
296
|
+
eventNameField?: string | false;
|
|
297
|
+
/**
|
|
298
|
+
* Shape of the error fields on an entry. Default `'pino'`.
|
|
299
|
+
*
|
|
300
|
+
* - `'pino'` — only the legacy `err` object (`type`, `message`, `stack`,
|
|
301
|
+
* plus the `cause` chain). What every existing query reads.
|
|
302
|
+
* - `'semconv'` — only the OpenTelemetry attributes: `exception.type`,
|
|
303
|
+
* `exception.message`, `exception.stacktrace` and `error.type`. The `err`
|
|
304
|
+
* object is removed, so this is an explicit migration, never a default.
|
|
305
|
+
* - `'both'` — both shapes on the same entry. Recommended while moving
|
|
306
|
+
* dashboards over: nothing breaks, and the new fields are already there.
|
|
307
|
+
*
|
|
308
|
+
* All four attributes are **Stable** in Semantic Conventions v1.44.0.
|
|
309
|
+
* `error.type` carries the error's class name and is LOW cardinality by
|
|
310
|
+
* construction — never a message, never an identifier.
|
|
311
|
+
*/
|
|
312
|
+
errorFormat?: 'pino' | 'semconv' | 'both';
|
|
194
313
|
/** Censor string written in place of redacted values. Default: `[REDACTED]`. */
|
|
195
314
|
redactCensor?: string;
|
|
196
315
|
/** Disable default redact paths (use with caution). Default: false. */
|
|
@@ -598,17 +717,6 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
|
|
|
598
717
|
* this service has no additional teardown work.
|
|
599
718
|
*/
|
|
600
719
|
onApplicationShutdown(): void;
|
|
601
|
-
/**
|
|
602
|
-
* Serialize an Error into a plain, log-safe object matching Pino's built-in
|
|
603
|
-
* `err` serializer shape (`type`, `message`, `stack`).
|
|
604
|
-
*
|
|
605
|
-
* Reads `error.name` (NOT `error.constructor.name`) for `type`: native
|
|
606
|
-
* subclasses set `name` to their class name, and a sanitized plain-object error
|
|
607
|
-
* (from `sanitizeError`) carries the real class name on `name` — whereas its
|
|
608
|
-
* `constructor.name` would be the unhelpful `'Object'`, breaking `err.type`
|
|
609
|
-
* dashboards for every exception logged through `HttpExceptionFilter`.
|
|
610
|
-
*/
|
|
611
|
-
private serializeError;
|
|
612
720
|
/** Resolve the context: last string param wins, else the instance context. */
|
|
613
721
|
private resolveContext;
|
|
614
722
|
/** Emit a structured payload at info or warn level. */
|
|
@@ -1179,8 +1287,14 @@ interface LogEntry {
|
|
|
1179
1287
|
msg: string;
|
|
1180
1288
|
/** Convention key — `MODULE_ACTION_RESULT` format. */
|
|
1181
1289
|
logKey?: string;
|
|
1182
|
-
/**
|
|
1183
|
-
|
|
1290
|
+
/**
|
|
1291
|
+
* Service identity as EMITTED — see {@link EmittedServiceResource}. Not the
|
|
1292
|
+
* configuration shape: `service.instance.id` nests, and the environment lives
|
|
1293
|
+
* under `deployment`, not here.
|
|
1294
|
+
*/
|
|
1295
|
+
service?: EmittedServiceResource;
|
|
1296
|
+
/** Deployment identity as emitted — see {@link EmittedDeploymentResource}. */
|
|
1297
|
+
deployment?: EmittedDeploymentResource;
|
|
1184
1298
|
/** Optional NestJS context (typically the emitting class name). */
|
|
1185
1299
|
context?: string;
|
|
1186
1300
|
/** Optional correlation IDs propagated via AsyncLocalStorage. */
|