@bymax-one/nest-logger 1.4.23 → 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.
@@ -375,7 +375,7 @@ function validateCustomization(options) {
375
375
  if (!isRecord2(serializers)) reject("serializers", "must be an object", serializers);
376
376
  for (const serializer of Object.values(serializers)) {
377
377
  if (typeof serializer !== "function") {
378
- reject("serializers", "must map every serializer key to a function", serializer);
378
+ reject("serializers", "must map every serializer key to a function", serializer, true);
379
379
  }
380
380
  }
381
381
  }
@@ -489,6 +489,7 @@ var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
489
489
  var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
490
490
  var LOGGER_DESTINATIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_DESTINATIONS");
491
491
  var LOGGER_REDACTOR_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_REDACTOR");
492
+ var LOGGER_OBSERVABILITY_TOKEN = /* @__PURE__ */ Symbol.for("BYMAX_LOGGER_OBSERVABILITY");
492
493
  var LOG_CONTEXT_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_LOG_CONTEXT");
493
494
 
494
495
  // src/shared/constants/reserved-log-keys.constants.ts
@@ -511,6 +512,7 @@ var RESERVED_LOG_KEYS = Object.freeze({
511
512
  METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION",
512
513
  LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED",
513
514
  LOGGER_DESTINATION_WRITE_FAILED: "LOGGER_DESTINATION_WRITE_FAILED",
515
+ LOGGER_DESTINATION_SHUTDOWN_FAILED: "LOGGER_DESTINATION_SHUTDOWN_FAILED",
514
516
  LOGGER_ENTRY_TRUNCATED: "LOGGER_ENTRY_TRUNCATED",
515
517
  LOGGER_REDACTION_FAILED: "LOGGER_REDACTION_FAILED",
516
518
  LOGGER_OTEL_API_BROKEN: "LOGGER_OTEL_API_BROKEN"
@@ -547,20 +549,38 @@ function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
547
549
  const whole = last >= 55296 && last <= 56319 ? head.slice(0, -1) : head;
548
550
  return whole + TEXT_TRUNCATED;
549
551
  }
552
+ function cutBytes(text, maxBytes) {
553
+ if (Buffer.byteLength(text, "utf-8") <= maxBytes) return text;
554
+ const markerBytes = Buffer.byteLength(TEXT_TRUNCATED, "utf-8");
555
+ const marked = maxBytes >= markerBytes;
556
+ const bytes = Buffer.from(text, "utf-8");
557
+ let end = Math.min(marked ? maxBytes - markerBytes : maxBytes, bytes.length);
558
+ while ((bytes.readUInt8(end) & 192) === 128) end -= 1;
559
+ return bytes.subarray(0, end).toString("utf-8") + (marked ? TEXT_TRUNCATED : "");
560
+ }
550
561
 
551
562
  // src/server/utils/entry-text-finisher.util.ts
552
563
  var ENTRY_TEXT_FINISHER = /* @__PURE__ */ Symbol("bymax.entryTextFinisher");
553
- function createEntryTextFinisher(redact, limit) {
564
+ function createTextCensor(redact) {
554
565
  return (key, text) => {
555
566
  try {
556
567
  const censored = Reflect.get(redact({ [key]: text }, true), key);
557
- if (typeof censored !== "string") return "";
558
- return limit === void 0 ? censored : cutText(censored, false, limit);
568
+ return typeof censored === "string" ? censored : "";
559
569
  } catch {
560
570
  return "";
561
571
  }
562
572
  };
563
573
  }
574
+ function createEntryTextFinisher(redact, limit, onCut) {
575
+ const censor = createTextCensor(redact);
576
+ return (key, text, cut) => {
577
+ const censored = censor(key, text);
578
+ if (limit === void 0 || cut === void 0) return censored;
579
+ const cutOff = cutText(censored, false, limit);
580
+ if (cut.emitted && cutOff !== censored) onCut?.();
581
+ return cutOff;
582
+ };
583
+ }
564
584
 
565
585
  // src/server/utils/escape-log-text.util.ts
566
586
  var LINE_TERMINATORS = /* @__PURE__ */ new Set(["\r", "\n", "\x85", "\u2028", "\u2029"]);
@@ -582,6 +602,12 @@ function escapeControlCharacters(text) {
582
602
  return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
583
603
  }
584
604
 
605
+ // src/server/utils/fold-key.util.ts
606
+ var SEPARATORS = /[._-]/g;
607
+ function foldKey(key) {
608
+ return key.replace(SEPARATORS, "").toLowerCase();
609
+ }
610
+
585
611
  // src/server/utils/is-plain-record.util.ts
586
612
  function isPlainRecord(node) {
587
613
  try {
@@ -591,6 +617,25 @@ function isPlainRecord(node) {
591
617
  return false;
592
618
  }
593
619
  }
620
+
621
+ // src/server/utils/censor-stack-header.util.ts
622
+ var NAME_SEPARATOR = ": ";
623
+ function endsHeader(stack, message, from) {
624
+ const end = from + message.length;
625
+ return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
626
+ }
627
+ function censorStackHeader(stack, name, message, censored) {
628
+ if (message === "" || censored === message) return stack;
629
+ const separator = stack.indexOf(NAME_SEPARATOR);
630
+ if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
631
+ const from = separator + NAME_SEPARATOR.length;
632
+ if (endsHeader(stack, message, from)) {
633
+ return stack.slice(0, from) + censored + stack.slice(from + message.length);
634
+ }
635
+ }
636
+ if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
637
+ return name === "" ? censored : name + NAME_SEPARATOR + censored;
638
+ }
594
639
  function isError(value) {
595
640
  try {
596
641
  return util.types.isNativeError(value) || value instanceof Error;
@@ -654,7 +699,8 @@ function sanitizeError(err, options) {
654
699
  const maxCauseDepth = options?.maxCauseDepth ?? DEFAULT_MAX_CAUSE_DEPTH;
655
700
  return toSanitizedError(err, /* @__PURE__ */ new WeakSet(), 0, {
656
701
  maxDepth: maxCauseDepth,
657
- ownFields: options?.ownFields ?? ALL_OWN_FIELDS
702
+ ownFields: options?.ownFields ?? ALL_OWN_FIELDS,
703
+ censorMessage: options?.censorMessage
658
704
  });
659
705
  }
660
706
  function isErrorLike(value) {
@@ -671,17 +717,20 @@ function readsAsError(value) {
671
717
  const candidate = value;
672
718
  return typeof candidate.name === "string" && typeof candidate.message === "string";
673
719
  }
720
+ function readScrubbedStack(value, message, result, walk2) {
721
+ const stack = readOptional(() => value.stack, result);
722
+ return stack === void 0 ? void 0 : scrubStack(stack, headerCensor(result.name, message, walk2.censorMessage));
723
+ }
674
724
  function toSanitizedError(value, seen, depth2, walk2) {
675
725
  try {
676
726
  if (!readsAsError(value)) {
677
727
  return { name: "UnknownError", message: cutText(String(value)) };
678
728
  }
679
729
  seen.add(value);
680
- const result = { name: cutText(value.name), message: cutText(value.message) };
681
- const stack = readOptional(() => value.stack, result);
682
- if (stack !== void 0) {
683
- result.stack = scrubStack(stack);
684
- }
730
+ const message = value.message;
731
+ const result = { name: cutText(value.name), message: cutText(message) };
732
+ const stack = readScrubbedStack(value, message, result, walk2);
733
+ if (stack !== void 0) result.stack = stack;
685
734
  const isAtDepthLimit = depth2 >= walk2.maxDepth;
686
735
  const cause = readOptional(() => value.cause, result);
687
736
  if (cause !== void 0) {
@@ -769,9 +818,19 @@ function readAggregatedErrors(value) {
769
818
  return Array.isArray(candidate) ? candidate : void 0;
770
819
  }
771
820
  var MAX_STACK_SCAN = 8 * MAX_TEXT_LENGTH;
772
- function scrubStack(stack) {
821
+ function headerCensor(name, message, censorMessage) {
822
+ if (typeof message !== "string" || censorMessage === void 0) return void 0;
823
+ const named = typeof name === "string" ? name : "";
824
+ try {
825
+ return { name: named, message, censored: censorMessage(message) };
826
+ } catch {
827
+ return { name: named, message, censored: "" };
828
+ }
829
+ }
830
+ function scrubStack(stack, header) {
831
+ const head = stack.slice(0, MAX_STACK_SCAN);
773
832
  const scrubbed = escapeControlCharacters(
774
- stack.slice(0, MAX_STACK_SCAN).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
833
+ (header === void 0 ? head : censorStackHeader(head, header.name, header.message, header.censored)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
775
834
  );
776
835
  return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
777
836
  }
@@ -787,14 +846,14 @@ function createWidthMarker(omitted) {
787
846
 
788
847
  // src/server/services/pino-logger.service.ts
789
848
  var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
790
- var ENTRY_STRUCTURE_KEYS = /* @__PURE__ */ new Set([
791
- "level",
792
- "time",
793
- "msg",
794
- "service",
795
- "deployment"
796
- ]);
797
- var isEntryStructureKey = (key) => ENTRY_STRUCTURE_KEYS.has(key) || key.startsWith("service.") || key.startsWith("deployment.");
849
+ var ENTRY_STRUCTURE_KEYS = ["level", "time", "msg", "service", "deployment"];
850
+ var OWNED_KEY_SPELLINGS = new Set(
851
+ [...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS].map(foldKey)
852
+ );
853
+ var isOwnedKey = (key) => {
854
+ const lower = key.toLowerCase();
855
+ return OWNED_KEY_SPELLINGS.has(foldKey(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
856
+ };
798
857
  function withoutOwnedKeys(metadata, omit) {
799
858
  if (metadata === void 0) {
800
859
  return {};
@@ -802,7 +861,7 @@ function withoutOwnedKeys(metadata, omit) {
802
861
  try {
803
862
  const safe = {};
804
863
  for (const key of Object.keys(metadata)) {
805
- if (key !== omit && !OWNED_PAYLOAD_KEYS.includes(key) && !isEntryStructureKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
864
+ if (key !== omit && !isOwnedKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
806
865
  Reflect.set(safe, key, Reflect.get(metadata, key));
807
866
  }
808
867
  }
@@ -907,7 +966,7 @@ exports.PinoLoggerService = class PinoLoggerService {
907
966
  if (isErrorLike(message)) {
908
967
  const payload2 = { err: message };
909
968
  assignIfDefined(payload2, "context", this.resolveContext(optionalParams));
910
- this.pino.error(payload2, safeErrorMessage(message));
969
+ this.pino.error(payload2, this.errorText(message));
911
970
  return;
912
971
  }
913
972
  const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
@@ -916,7 +975,7 @@ exports.PinoLoggerService = class PinoLoggerService {
916
975
  assignIfDefined(payload, "context", context);
917
976
  assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
918
977
  assignIfDefined(payload, "err", findErrorParam(optionalParams));
919
- this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
978
+ this.pino.error(payload, this.nestStyleMessage("error", void 0, fields, text, message));
920
979
  }
921
980
  /**
922
981
  * NestJS `warn` (warn level).
@@ -1002,7 +1061,7 @@ exports.PinoLoggerService = class PinoLoggerService {
1002
1061
  };
1003
1062
  assignIfDefined(payload, "userId", userId);
1004
1063
  assignIfDefined(payload, "context", this.context);
1005
- this.pino.error(payload, safeErrorMessage(error));
1064
+ this.pino.error(payload, this.errorText(error));
1006
1065
  }
1007
1066
  // ─── Helpers / escape hatches ─────────────────────────────────────────────
1008
1067
  /**
@@ -1068,30 +1127,57 @@ exports.PinoLoggerService = class PinoLoggerService {
1068
1127
  }
1069
1128
  }
1070
1129
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1071
- nestStyleMessage(leading, fields, text, message) {
1072
- if (leading !== void 0) return safeErrorMessage(leading);
1073
- if (fields !== void 0) return toBoundedMessage(this.censorText(text));
1130
+ nestStyleMessage(level, leading, fields, text, message) {
1131
+ if (leading !== void 0) return this.errorText(leading);
1132
+ if (fields !== void 0) {
1133
+ return toBoundedMessage(this.censorText(text, { emitted: this.pino.isLevelEnabled(level) }));
1134
+ }
1074
1135
  return safeLogMessage(message);
1075
1136
  }
1137
+ /**
1138
+ * Censor a text as the `message` of an entry is: under the name `message`, by the rules of
1139
+ * `redactPaths` and `redactCensor`, and neither cut nor counted. The lines the library writes to
1140
+ * `stderr` about a failure use it for the message of the error they carry.
1141
+ *
1142
+ * @internal Used by `PinoUnexpectedErrorSink`. NOT part of the supported API.
1143
+ * @param text - The text to censor.
1144
+ * @returns The text, or what hides it, and an empty text when the censor itself fails.
1145
+ */
1146
+ censorMessageText(text) {
1147
+ return this.censorText({ key: "message", text });
1148
+ }
1149
+ /**
1150
+ * The entry text of an `Error`: its `message`, read without letting a hostile getter escape, then
1151
+ * censored under the name `message`, as the field `err.message` it is a copy of. It is not cut at
1152
+ * `maxStringLength`: the option does not apply to the log message, which is capped at 16384.
1153
+ *
1154
+ * @param error - The error being logged.
1155
+ * @returns The text of the entry.
1156
+ */
1157
+ errorText(error) {
1158
+ return toBoundedMessage(this.censorText({ key: "message", text: safeErrorMessage(error) }));
1159
+ }
1076
1160
  /**
1077
1161
  * The entry text of an object message, censored under the names of the field it came from and cut
1078
1162
  * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1079
1163
  * value the pipeline censors or cuts in the field itself.
1080
1164
  *
1081
1165
  * @param text - The text and the member it came from.
1166
+ * @param cut - Present when the text is cut at `maxStringLength`; says whether the entry is
1167
+ * written, so that a cut of it is counted.
1082
1168
  * @returns The censored text, or an empty one when the redactor cannot be applied.
1083
1169
  */
1084
- censorText(text) {
1170
+ censorText(text, cut) {
1085
1171
  if (text === void 0) return "";
1086
1172
  const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
1087
- return finish(text.key, text.text);
1173
+ return finish(text.key, text.text, cut);
1088
1174
  }
1089
1175
  emitNestStyle(level, message, optionalParams) {
1090
1176
  const { fields, text, payload } = readObjectMessage(message);
1091
1177
  assignIfDefined(payload, "context", this.resolveContext(optionalParams));
1092
1178
  const leading = isErrorLike(message) ? message : void 0;
1093
1179
  assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
1094
- const msg = this.nestStyleMessage(leading, fields, text, message);
1180
+ const msg = this.nestStyleMessage(level, leading, fields, text, message);
1095
1181
  switch (level) {
1096
1182
  case "info":
1097
1183
  this.pino.info(payload, msg);
@@ -2163,25 +2249,26 @@ var DEFAULT_REDACT_PATHS = [
2163
2249
  ];
2164
2250
 
2165
2251
  // src/server/utils/report-destination-failure.util.ts
2166
- function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0) {
2252
+ function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0, censorMessage) {
2167
2253
  writeStderrSafely(
2168
2254
  JSON.stringify({
2169
2255
  level: "error",
2170
2256
  logKey,
2171
2257
  destination: toSingleLineMessage(name),
2172
- err: describeCause(cause),
2258
+ err: describeCause(cause, censorMessage),
2173
2259
  msg: toSingleLineMessage(msg),
2174
2260
  ...suppressed > 0 ? { suppressed } : {}
2175
2261
  }) + "\n"
2176
2262
  );
2177
2263
  }
2178
2264
  var UNREADABLE_CAUSE = { type: "UnknownError", message: "unreadable value" };
2179
- function describeCause(cause) {
2265
+ function describeCause(cause, censorMessage) {
2266
+ const censor = censorMessage ?? ((text) => text);
2180
2267
  try {
2181
2268
  return isError(cause) ? {
2182
2269
  type: toBoundedMessage(String(cause.name)),
2183
- message: toBoundedMessage(String(cause.message))
2184
- } : { type: "UnknownError", message: toBoundedMessage(String(cause)) };
2270
+ message: toBoundedMessage(censor(String(cause.message)))
2271
+ } : { type: "UnknownError", message: toBoundedMessage(censor(String(cause))) };
2185
2272
  } catch {
2186
2273
  return UNREADABLE_CAUSE;
2187
2274
  }
@@ -2239,7 +2326,7 @@ function loadTraceApiFrom(anchor) {
2239
2326
  return isOtelApiMissing(cause) ? { api: void 0 } : { api: void 0, broken: { cause } };
2240
2327
  }
2241
2328
  }
2242
- function warnBrokenInstallOnce(cause) {
2329
+ function warnBrokenInstallOnce(cause, censorMessage) {
2243
2330
  if (brokenInstallWarned) {
2244
2331
  return;
2245
2332
  }
@@ -2249,7 +2336,7 @@ function warnBrokenInstallOnce(cause) {
2249
2336
  level: "warn",
2250
2337
  logKey: RESERVED_LOG_KEYS.LOGGER_OTEL_API_BROKEN,
2251
2338
  msg: "@opentelemetry/api is installed but could not be loaded, so traceId and spanId are absent from every entry. Reinstall it, or set otel.shouldAutoInjectTraceContext to false.",
2252
- err: describeCause(cause)
2339
+ err: describeCause(cause, censorMessage)
2253
2340
  }) + "\n"
2254
2341
  );
2255
2342
  }
@@ -2257,7 +2344,7 @@ var DEFAULT_ANCHORS = [
2257
2344
  () => __filename,
2258
2345
  () => path.join(process.cwd(), "noop.cjs")
2259
2346
  ];
2260
- function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
2347
+ function detectOtelTraceApi(anchors = DEFAULT_ANCHORS, censorMessage) {
2261
2348
  let broken;
2262
2349
  for (const anchor of anchors) {
2263
2350
  const attempt = loadTraceApiFrom(anchor);
@@ -2267,7 +2354,7 @@ function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
2267
2354
  broken ??= attempt.broken;
2268
2355
  }
2269
2356
  if (broken !== void 0) {
2270
- warnBrokenInstallOnce(broken.cause);
2357
+ warnBrokenInstallOnce(broken.cause, censorMessage);
2271
2358
  }
2272
2359
  return void 0;
2273
2360
  }
@@ -2280,7 +2367,7 @@ function isValidSpanId(spanId) {
2280
2367
 
2281
2368
  // src/server/mixins/trace-context.mixin.ts
2282
2369
  function createTraceContextMixin(logContext, opts) {
2283
- const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi() : void 0;
2370
+ const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi(void 0, opts.censorMessage) : void 0;
2284
2371
  return function mixin(_mergeObject, _level, _logger) {
2285
2372
  const merged = {};
2286
2373
  const store = logContext.getStore();
@@ -2302,7 +2389,7 @@ function createTraceContextMixin(logContext, opts) {
2302
2389
  }
2303
2390
  }
2304
2391
  } catch (cause) {
2305
- warnBrokenInstallOnce(cause);
2392
+ warnBrokenInstallOnce(cause, opts.censorMessage);
2306
2393
  }
2307
2394
  }
2308
2395
  return merged;
@@ -2316,34 +2403,45 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
2316
2403
  }
2317
2404
 
2318
2405
  // src/server/utils/cut-strings.util.ts
2319
- function cutNode(node, limit) {
2320
- if (typeof node === "string") return cutText(node, false, limit);
2321
- if (Array.isArray(node)) return node.map((child) => cutNode(child, limit));
2406
+ function cutNode(node, limit, onCut) {
2407
+ if (typeof node === "string") {
2408
+ const cut = cutText(node, false, limit);
2409
+ if (cut !== node) onCut?.();
2410
+ return cut;
2411
+ }
2412
+ if (Array.isArray(node)) return node.map((child) => cutNode(child, limit, onCut));
2322
2413
  if (isPlainRecord(node)) {
2323
2414
  return Object.fromEntries(
2324
- Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
2415
+ Object.entries(node).map(([key, child]) => [key, cutNode(child, limit, onCut)])
2325
2416
  );
2326
2417
  }
2327
2418
  return node;
2328
2419
  }
2329
- function cutStrings(record, limit, exempt) {
2420
+ function cutStrings(record, limit, exempt, onCut) {
2330
2421
  return Object.fromEntries(
2331
2422
  Object.entries(record).map(([key, child]) => [
2332
2423
  key,
2333
- exempt.has(key) ? child : cutNode(child, limit)
2424
+ exempt.has(key) ? child : cutNode(child, limit, onCut)
2334
2425
  ])
2335
2426
  );
2336
2427
  }
2337
- function reportWriteFailure(destination, cause, due) {
2428
+ function reportWriteFailure(destination, cause, due, censorMessage) {
2338
2429
  const name = safeDestinationName(destination);
2339
2430
  reportDestinationFailure(
2340
2431
  RESERVED_LOG_KEYS.LOGGER_DESTINATION_WRITE_FAILED,
2341
2432
  name,
2342
2433
  cause,
2343
- `Log destination "${name}" failed to write; the entry was dropped`,
2344
- due - 1
2434
+ "A log destination failed to write; the entry was dropped",
2435
+ due - 1,
2436
+ censorMessage
2345
2437
  );
2346
2438
  }
2439
+ function recordWriteFailure(destination, health, cause, censorMessage) {
2440
+ const due = health.recordWriteFailure(destination, performance.now());
2441
+ if (due !== void 0) {
2442
+ reportWriteFailure(destination, cause, due, censorMessage);
2443
+ }
2444
+ }
2347
2445
  function rescueToStdout(payload) {
2348
2446
  writeStdoutSafely(payload);
2349
2447
  }
@@ -2417,7 +2515,7 @@ var BoundedWritable = class extends stream.Writable {
2417
2515
  );
2418
2516
  }
2419
2517
  };
2420
- function destinationToStream(destination, health, maxQueueBytes = 0) {
2518
+ function destinationToStream(destination, health, maxQueueBytes = 0, censorMessage) {
2421
2519
  const queue = { bytes: 0 };
2422
2520
  const stream = new BoundedWritable(destination, health, maxQueueBytes, queue, {
2423
2521
  // Keep string chunks as strings (Node's default re-encodes them to Buffers
@@ -2432,10 +2530,7 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
2432
2530
  settled(error);
2433
2531
  };
2434
2532
  const onFailure = (cause) => {
2435
- const due = health.recordWriteFailure(destination, performance.now());
2436
- if (due !== void 0) {
2437
- reportWriteFailure(destination, cause, due);
2438
- }
2533
+ recordWriteFailure(destination, health, cause, censorMessage);
2439
2534
  callback();
2440
2535
  };
2441
2536
  try {
@@ -2477,8 +2572,14 @@ var EXPLICIT_USER_KEY = "userId";
2477
2572
  function mergeMixinSafely(mergeObject, mixinObject) {
2478
2573
  try {
2479
2574
  const merged = {};
2575
+ const written = /* @__PURE__ */ new Set();
2576
+ for (const [key, value] of Object.entries(mixinObject)) {
2577
+ if (value !== void 0) written.add(foldKey(key));
2578
+ }
2480
2579
  for (const key of Object.keys(mergeObject)) {
2481
- if (key !== PROTOTYPE_KEY) Reflect.set(merged, key, Reflect.get(mergeObject, key));
2580
+ if (key === PROTOTYPE_KEY) continue;
2581
+ if (key !== EXPLICIT_USER_KEY && written.has(foldKey(key))) continue;
2582
+ Reflect.set(merged, key, Reflect.get(mergeObject, key));
2482
2583
  }
2483
2584
  for (const [key, value] of Object.entries(mixinObject)) {
2484
2585
  if (value === void 0) continue;
@@ -2942,6 +3043,46 @@ function extraServiceFields(service) {
2942
3043
  return extras;
2943
3044
  }
2944
3045
 
3046
+ // src/server/utils/semconv-exception.util.ts
3047
+ function deriveExceptionFields(record, maxBytes, onCut, censorMessage) {
3048
+ const bounded = (text) => {
3049
+ const cut = cutBytes(text, maxBytes);
3050
+ if (cut !== text) onCut?.();
3051
+ return cut;
3052
+ };
3053
+ const candidate = record["err"];
3054
+ if (typeof candidate?.name === "string") {
3055
+ record["exception.type"] = bounded(cutText(candidate.name));
3056
+ record["error.type"] = bounded(cutText(candidate.name));
3057
+ }
3058
+ const header = headerCensor(candidate?.name, candidate?.message, censorMessage);
3059
+ if (header !== void 0) {
3060
+ record["exception.message"] = bounded(cutText(header.censored));
3061
+ }
3062
+ if (typeof candidate?.stack === "string") {
3063
+ record["exception.stacktrace"] = bounded(scrubStack(candidate.stack, header));
3064
+ }
3065
+ }
3066
+ function withSemconvException(record, format, maxBytes = Number.POSITIVE_INFINITY, onCut, censorMessage = (text) => text) {
3067
+ if (format === "pino") {
3068
+ return record;
3069
+ }
3070
+ try {
3071
+ deriveExceptionFields(record, maxBytes, onCut, censorMessage);
3072
+ if (format === "semconv") {
3073
+ const withoutErr = {};
3074
+ for (const [key, value] of Object.entries(record)) {
3075
+ if (key !== "err") {
3076
+ Reflect.set(withoutErr, key, value);
3077
+ }
3078
+ }
3079
+ return withoutErr;
3080
+ }
3081
+ } catch {
3082
+ }
3083
+ return record;
3084
+ }
3085
+
2945
3086
  // src/server/utils/serialize-request.util.ts
2946
3087
  function isObject2(value) {
2947
3088
  return typeof value === "object" && value !== null;
@@ -2977,20 +3118,34 @@ function withSerializedRequest(record, secretSegments = []) {
2977
3118
 
2978
3119
  // src/server/utils/truncate-large-entries.ts
2979
3120
  var PREVIEW_LENGTH = 200;
2980
- function createSizeBoundedSerializer(baseSerializer, maxBytes) {
3121
+ function measurableJson(value) {
3122
+ const parents = /* @__PURE__ */ new WeakMap();
3123
+ return JSON.stringify(value, function(_key, inner) {
3124
+ if (typeof inner === "bigint") return inner.toString();
3125
+ if (typeof inner !== "object" || inner === null) return inner;
3126
+ for (let holder = this; holder !== void 0; holder = parents.get(holder)) {
3127
+ if (holder === inner) return "[Circular]";
3128
+ }
3129
+ parents.set(inner, this);
3130
+ return inner;
3131
+ });
3132
+ }
3133
+ function createSizeBoundedSerializer(baseSerializer, maxBytes, onTruncate) {
2981
3134
  return (input) => {
2982
3135
  const serialized = baseSerializer(input);
2983
3136
  let json;
2984
3137
  try {
2985
- json = JSON.stringify(serialized);
3138
+ json = measurableJson(serialized);
2986
3139
  } catch {
2987
- return serialized;
3140
+ onTruncate?.();
3141
+ return unmeasurableEnvelope();
2988
3142
  }
2989
3143
  if (json === void 0) {
2990
3144
  return serialized;
2991
3145
  }
2992
3146
  const byteSize = Buffer.byteLength(json, "utf-8");
2993
3147
  if (byteSize > maxBytes) {
3148
+ onTruncate?.();
2994
3149
  return {
2995
3150
  _truncated: true,
2996
3151
  _logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
@@ -3001,6 +3156,14 @@ function createSizeBoundedSerializer(baseSerializer, maxBytes) {
3001
3156
  return serialized;
3002
3157
  };
3003
3158
  }
3159
+ function unmeasurableEnvelope() {
3160
+ return {
3161
+ _truncated: true,
3162
+ _logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
3163
+ _originalSize: -1,
3164
+ _preview: ""
3165
+ };
3166
+ }
3004
3167
 
3005
3168
  // src/server/pino-factory.ts
3006
3169
  var PATH_SEGMENT = /\[\s*['"]([^'"]+)['"]\s*\]|([^.[\]]+)/g;
@@ -3016,8 +3179,8 @@ function leafNameOf(path) {
3016
3179
  }
3017
3180
  return leaf;
3018
3181
  }
3019
- function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
3020
- const sanitized = sanitizeError(value_, { ownFields });
3182
+ function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS, censorMessage) {
3183
+ const sanitized = sanitizeError(value_, { ownFields, censorMessage });
3021
3184
  const serialized = {
3022
3185
  // `type` rather than `name`: the field consumers already query.
3023
3186
  type: sanitized.name,
@@ -3035,35 +3198,6 @@ function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
3035
3198
  assignOwnErrorFields(serialized, sanitized);
3036
3199
  return serialized;
3037
3200
  }
3038
- function withSemconvException(record, format) {
3039
- if (format === "pino") {
3040
- return record;
3041
- }
3042
- try {
3043
- const candidate = record["err"];
3044
- if (typeof candidate?.name === "string") {
3045
- record["exception.type"] = cutText(candidate.name);
3046
- record["error.type"] = cutText(candidate.name);
3047
- }
3048
- if (typeof candidate?.message === "string") {
3049
- record["exception.message"] = cutText(candidate.message);
3050
- }
3051
- if (typeof candidate?.stack === "string") {
3052
- record["exception.stacktrace"] = scrubStack(candidate.stack);
3053
- }
3054
- if (format === "semconv") {
3055
- const withoutErr = {};
3056
- for (const [key, value] of Object.entries(record)) {
3057
- if (key !== "err") {
3058
- Reflect.set(withoutErr, key, value);
3059
- }
3060
- }
3061
- return withoutErr;
3062
- }
3063
- } catch {
3064
- }
3065
- return record;
3066
- }
3067
3201
  function toEventName(logKey) {
3068
3202
  return logKey.toLowerCase().replaceAll("_", ".");
3069
3203
  }
@@ -3134,11 +3268,16 @@ function resolveRedactOption(options) {
3134
3268
  }
3135
3269
  return { paths, censor: options.redactCensor };
3136
3270
  }
3137
- function buildSerializers(options, redactSerialized, ownFields) {
3271
+ function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
3138
3272
  const maxBytes = options.maxEntrySizeBytes;
3139
- const bound = (serializer) => createSizeBoundedSerializer((input) => redactSerialized(serializer(input)), maxBytes);
3273
+ const censorMessage = buildMessageCensor(options);
3274
+ const bound = (serializer) => createSizeBoundedSerializer(
3275
+ (input) => redactSerialized(serializer(input)),
3276
+ maxBytes,
3277
+ () => onTruncate("max_entry_size")
3278
+ );
3140
3279
  return {
3141
- err: bound((error) => serializeErrorValue(error, ownFields)),
3280
+ err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
3142
3281
  ...Object.fromEntries(
3143
3282
  Object.entries(options.serializers).map(
3144
3283
  ([key, serializer]) => [key, bound(serializer)]
@@ -3146,14 +3285,35 @@ function buildSerializers(options, redactSerialized, ownFields) {
3146
3285
  )
3147
3286
  };
3148
3287
  }
3149
- function withEntryTextFinisher(logger, options) {
3288
+ function buildMessageCensor(options) {
3289
+ const censor = createTextCensor(buildNameRedactor(options));
3290
+ return (text) => censor("message", text);
3291
+ }
3292
+ function withEntryTextFinisher(logger, options, onTruncate) {
3150
3293
  const redact = buildNameRedactor(options);
3151
- Reflect.set(logger, ENTRY_TEXT_FINISHER, createEntryTextFinisher(redact, options.maxStringLength));
3294
+ const finisher = createEntryTextFinisher(
3295
+ redact,
3296
+ options.maxStringLength,
3297
+ () => onTruncate("max_string_length")
3298
+ );
3299
+ Reflect.set(logger, ENTRY_TEXT_FINISHER, finisher);
3152
3300
  return logger;
3153
3301
  }
3302
+ function buildTraceMixin(logContext, options) {
3303
+ return createTraceContextMixin(logContext, {
3304
+ ...options.otel,
3305
+ censorMessage: buildMessageCensor(options)
3306
+ });
3307
+ }
3154
3308
  function buildStreams(options, destinations, health) {
3309
+ const censorMessage = buildMessageCensor(options);
3155
3310
  return destinations.map((destination) => {
3156
- const stream = destinationToStream(destination, health, options.destinationQueue.maxBytes);
3311
+ const stream = destinationToStream(
3312
+ destination,
3313
+ health,
3314
+ options.destinationQueue.maxBytes,
3315
+ censorMessage
3316
+ );
3157
3317
  health.registerStream(destination, stream);
3158
3318
  return {
3159
3319
  // Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
@@ -3165,20 +3325,27 @@ function buildStreams(options, destinations, health) {
3165
3325
  };
3166
3326
  });
3167
3327
  }
3168
- function buildRecordFormatter(options, redactRecord) {
3328
+ function buildRecordFormatter(options, redactRecord, onTruncate) {
3169
3329
  const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
3170
3330
  const maxStringLength = options.maxStringLength;
3171
3331
  const wholeRoots = wholeRootKeys(options);
3332
+ const censorMessage = buildMessageCensor(options);
3172
3333
  return (record) => {
3173
3334
  const redacted = redactRecord(
3174
3335
  hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
3175
3336
  true
3176
3337
  );
3177
- const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
3178
- return withSemconvException(withEventName(bounded, options.eventNameField), options.errorFormat);
3338
+ const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots, () => onTruncate("max_string_length"));
3339
+ return withSemconvException(
3340
+ withEventName(bounded, options.eventNameField),
3341
+ options.errorFormat,
3342
+ options.maxEntrySizeBytes,
3343
+ () => onTruncate("max_entry_size"),
3344
+ censorMessage
3345
+ );
3179
3346
  };
3180
3347
  }
3181
- function buildFormatters(options, redactRecord, redactBindings) {
3348
+ function buildFormatters(options, redactRecord, redactBindings, onTruncate) {
3182
3349
  return {
3183
3350
  // Emit the level as a string label instead of the numeric code — easier
3184
3351
  // for log aggregators. Trace context is injected via `mixin`, never via
@@ -3199,7 +3366,7 @@ function buildFormatters(options, redactRecord, redactBindings) {
3199
3366
  // `base` and child bindings are NOT visible at this hook — they are
3200
3367
  // library-owned (`service`, the `@InjectLogger` context) and carry nothing
3201
3368
  // sensitive, which `pino-factory.spec.ts` pins.
3202
- log: buildRecordFormatter(options, redactRecord)
3369
+ log: buildRecordFormatter(options, redactRecord, onTruncate)
3203
3370
  };
3204
3371
  }
3205
3372
  function buildPinoInstance(options, logContext, destinations, health) {
@@ -3210,6 +3377,7 @@ function buildPinoInstance(options, logContext, destinations, health) {
3210
3377
  const redactSerialized = buildNameRedactor(options);
3211
3378
  const ownFields = ownFieldPolicyOf(options);
3212
3379
  const redactOption = resolveRedactOption(options);
3380
+ const onTruncate = (reason) => health.recordTruncation(reason);
3213
3381
  const pinoOptions = {
3214
3382
  level: options.level,
3215
3383
  ...redactOption === void 0 ? {} : { redact: redactOption },
@@ -3226,13 +3394,13 @@ function buildPinoInstance(options, logContext, destinations, health) {
3226
3394
  // is encoded as a JSON string here: a quote, a backslash or a newline in it must
3227
3395
  // neither break the line nor add fields to it.
3228
3396
  timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
3229
- formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
3230
- serializers: buildSerializers(options, redactSerialized, ownFields),
3231
- mixin: createTraceContextMixin(logContext, options.otel),
3397
+ formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options), onTruncate),
3398
+ serializers: buildSerializers(options, redactSerialized, ownFields, onTruncate),
3399
+ mixin: buildTraceMixin(logContext, options),
3232
3400
  mixinMergeStrategy: mergeMixinSafely
3233
3401
  };
3234
3402
  const streams = pino__default.default.multistream(buildStreams(options, destinations, health));
3235
- return withEntryTextFinisher(pino__default.default(pinoOptions, streams), options);
3403
+ return withEntryTextFinisher(pino__default.default(pinoOptions, streams), options, onTruncate);
3236
3404
  }
3237
3405
  var DROP_REPORT_INTERVAL_MS = 1e4;
3238
3406
  function countInWindow(records, destination, now) {
@@ -3250,6 +3418,9 @@ function countInWindow(records, destination, now) {
3250
3418
  }
3251
3419
  var DestinationHealth = class {
3252
3420
  constructor() {
3421
+ /** How many fields were cut or replaced for the entry-size ceiling, and for the string limit. */
3422
+ this.entrySizeTruncations = 0;
3423
+ this.stringLengthTruncations = 0;
3253
3424
  /** Destinations whose `onInit()` rejected. Identity-keyed, not name-keyed. */
3254
3425
  this.failed = /* @__PURE__ */ new Set();
3255
3426
  /**
@@ -3348,6 +3519,34 @@ var DestinationHealth = class {
3348
3519
  this.writeFailed.add(destination);
3349
3520
  return countInWindow(this.writeFailures, destination, now);
3350
3521
  }
3522
+ /**
3523
+ * Record one field cut or replaced for a size bound.
3524
+ *
3525
+ * @param reason - Which bound: the entry-size ceiling or the string limit.
3526
+ */
3527
+ recordTruncation(reason) {
3528
+ if (reason === "max_entry_size") this.entrySizeTruncations += 1;
3529
+ else this.stringLengthTruncations += 1;
3530
+ }
3531
+ /** @inheritDoc */
3532
+ truncatedTotal(reason) {
3533
+ return reason === "max_entry_size" ? this.entrySizeTruncations : this.stringLengthTruncations;
3534
+ }
3535
+ /** @inheritDoc */
3536
+ destinationErrorTotal() {
3537
+ let total = 0;
3538
+ for (const count of this.writeFailures.values()) total += count.total;
3539
+ return total;
3540
+ }
3541
+ /** @inheritDoc */
3542
+ deliveryState() {
3543
+ return {
3544
+ destinations: this.healthy.size + this.failed.size,
3545
+ failedInit: this.failed.size,
3546
+ writeFailing: this.writeFailed.size,
3547
+ hasHealthySink: this.healthy.size > 0
3548
+ };
3549
+ }
3351
3550
  /**
3352
3551
  * How many writes a destination has refused since startup.
3353
3552
  *
@@ -3549,6 +3748,7 @@ var DestinationRegistry = class {
3549
3748
  * `onInit` runs and cannot be rebuilt afterwards; see `DestinationHealth`.
3550
3749
  */
3551
3750
  this.active = [];
3751
+ this.censorMessage = buildMessageCensor(options);
3552
3752
  }
3553
3753
  /**
3554
3754
  * Initialize every registered destination. A destination whose `onInit`
@@ -3650,12 +3850,13 @@ var DestinationRegistry = class {
3650
3850
  * @param cause - The thrown or rejected value.
3651
3851
  */
3652
3852
  reportInitFailure(destination, cause) {
3653
- const name = safeDestinationName(destination);
3654
3853
  reportDestinationFailure(
3655
3854
  RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
3656
- name,
3855
+ safeDestinationName(destination),
3657
3856
  cause,
3658
- `Log destination "${name}" failed to initialize and will receive no entries. If no destination initializes, entries fall back to raw NDJSON on stdout.`
3857
+ "A log destination failed to initialize and will receive no entries. If no destination initializes, entries fall back to raw NDJSON on stdout.",
3858
+ 0,
3859
+ this.censorMessage
3659
3860
  );
3660
3861
  }
3661
3862
  /**
@@ -3674,12 +3875,13 @@ var DestinationRegistry = class {
3674
3875
  */
3675
3876
  reportHookFailure(destination, cause) {
3676
3877
  const stillActive = !this.health.isFailed(destination);
3677
- const name = safeDestinationName(destination);
3678
3878
  reportDestinationFailure(
3679
3879
  RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
3680
- name,
3880
+ safeDestinationName(destination),
3681
3881
  cause,
3682
- `Log destination "${name}" threw from onRegistryReady. ` + (stillActive ? "It initialized successfully and keeps receiving entries; only anything it was holding from before init may be affected." : "It had already failed to initialize and receives no entries; anything it was still holding is lost.")
3882
+ "A log destination threw from onRegistryReady. " + (stillActive ? "It initialized successfully and keeps receiving entries; only anything it was holding from before init may be affected." : "It had already failed to initialize and receives no entries; anything it was still holding is lost."),
3883
+ 0,
3884
+ this.censorMessage
3683
3885
  );
3684
3886
  }
3685
3887
  /**
@@ -3709,7 +3911,7 @@ var DestinationRegistry = class {
3709
3911
  }
3710
3912
  );
3711
3913
  }
3712
- if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi() === void 0) {
3914
+ if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi(void 0, this.censorMessage) === void 0) {
3713
3915
  this.logger.warnStructured(
3714
3916
  RESERVED_LOG_KEYS.LOGGER_BOOTSTRAP_WARNING,
3715
3917
  "Trace-context auto-injection is enabled but @opentelemetry/api could not be resolved \u2014 traceId and spanId will be absent from every entry",
@@ -3829,44 +4031,32 @@ var DestinationRegistry = class {
3829
4031
  }
3830
4032
  }
3831
4033
  /**
3832
- * Report a failing `onShutdown` on stderr without letting the report itself
3833
- * abort the teardown of the destinations still queued behind it.
3834
- *
3835
- * The coercion is INSIDE the guard, not above it. Reading `stack`/`message` on
3836
- * an `Error` with hostile getters, and `String(cause)` on a value with a
3837
- * throwing `toString`/`Symbol.toPrimitive`, both throw — and this runs inside
3838
- * the `catch` that exists to keep one bad sink from mattering, so an escape
3839
- * here would propagate out of `onApplicationShutdown` and skip every remaining
3840
- * destination's flush. The never-throw contract has to cover READING the value,
3841
- * not just writing it, which is the same correction `reportDestinationFailure`
3842
- * already carries.
3843
- *
3844
- * The text is escaped for the same reason every other terminal-bound path is:
3845
- * a stack is legitimately multi-line, so `escapeControlCharacters` keeps its
3846
- * newlines and neutralizes everything else that can drive a terminal.
4034
+ * Report a failing `onShutdown` on stderr, as a structured line like the other stages, without
4035
+ * letting the report itself abort the teardown of the destinations still queued behind it.
3847
4036
  *
3848
- * The DESTINATION is passed rather than its name, so that read happens in here
3849
- * too. `name` is declared `readonly name: string` but nothing stops a consumer
3850
- * implementing it as a getter, and reading it at the call site would put it back
3851
- * outside the guard — inside the `catch`, where a throw has the same cost.
4037
+ * The line is written by {@link reportDestinationFailure}, which holds every guard the report
4038
+ * needs: the cause is read inside a guard (a hostile getter or `toPrimitive` degrades the detail
4039
+ * and never the line), the text is escaped for a terminal, and the message of the error passes
4040
+ * the censor of the `message` of an entry. The error is a field (`err`) and never part of `msg`,
4041
+ * which is library text, and its stack is not written: a stack is text a host error carries
4042
+ * whole, and the type and the censored message identify the failure.
3852
4043
  *
3853
- * Two separate guards, not one: a name that cannot be read must not also cost
3854
- * the failure detail, and a detail that cannot be read must not cost the name.
3855
- * Either alone still identifies which sink failed.
4044
+ * The DESTINATION is passed rather than its name, so that read happens inside the guard too:
4045
+ * `name` is declared `readonly name: string` but nothing stops a consumer implementing it as a
4046
+ * getter, and reading it at the call site would put it back outside the guard.
3856
4047
  *
3857
4048
  * @param destination - The destination whose `onShutdown` threw.
3858
4049
  * @param cause - The thrown value, of any shape.
3859
4050
  */
3860
4051
  reportShutdownFailure(destination, cause) {
3861
- const name = toSingleLineMessage(safeDestinationName(destination));
3862
- let detail = "UnknownError";
3863
- try {
3864
- const stack = isErrorLike(cause) ? cause.stack : void 0;
3865
- detail = stack === void 0 ? toBoundedMessage(isErrorLike(cause) ? String(cause.message) : String(cause)) : escapeControlCharacters(cutText(String(stack)));
3866
- } catch {
3867
- }
3868
- writeStderrSafely(`[DestinationRegistry] Shutdown failed for "${name}": ${detail}
3869
- `);
4052
+ reportDestinationFailure(
4053
+ RESERVED_LOG_KEYS.LOGGER_DESTINATION_SHUTDOWN_FAILED,
4054
+ safeDestinationName(destination),
4055
+ cause,
4056
+ "A log destination failed to shut down; anything it was still holding is lost.",
4057
+ 0,
4058
+ this.censorMessage
4059
+ );
3870
4060
  }
3871
4061
  /**
3872
4062
  * The destinations that initialized successfully.
@@ -3897,6 +4087,8 @@ function buildCommonProviders() {
3897
4087
  // and by DestinationRegistry (which writes to it during onModuleInit). Both
3898
4088
  // depend on this provider and it depends on nothing, so there is no cycle.
3899
4089
  DestinationHealth,
4090
+ // The counters and the delivery state of the logger, for the `/observability` subpath.
4091
+ { provide: LOGGER_OBSERVABILITY_TOKEN, useExisting: DestinationHealth },
3900
4092
  {
3901
4093
  // The DEFAULT-coverage redactor, shared by the Pino factory's hooks and by
3902
4094
  // `PinoLoggerService.child()`. The latter needs it as a provider because
@@ -3946,6 +4138,7 @@ function augmentLoggerModule(base, providers) {
3946
4138
  LOGGER_PINO_INSTANCE_TOKEN,
3947
4139
  LOGGER_DESTINATIONS_TOKEN,
3948
4140
  LOGGER_REDACTOR_TOKEN,
4141
+ LOGGER_OBSERVABILITY_TOKEN,
3949
4142
  LOG_CONTEXT_TOKEN,
3950
4143
  exports.LogContextService,
3951
4144
  exports.PinoLoggerService,
@@ -4545,7 +4738,9 @@ exports.PinoUnexpectedErrorSink = class PinoUnexpectedErrorSink {
4545
4738
  RESERVED_LOG_KEYS.HTTP_UNEXPECTED_ERROR_DROPPED,
4546
4739
  "PinoUnexpectedErrorSink",
4547
4740
  cause,
4548
- "An unexpected-error report could not be logged and was dropped."
4741
+ "An unexpected-error report could not be logged and was dropped.",
4742
+ 0,
4743
+ (text) => this.logger.censorMessageText(text)
4549
4744
  );
4550
4745
  }
4551
4746
  }
@@ -4654,6 +4849,7 @@ var LOG_KEYS_CONVENTION_REGEX = /^[A-Z][A-Z0-9_]+_[A-Z][A-Z0-9_]+(_[A-Z][A-Z0-9_
4654
4849
  exports.DEFAULT_REDACT_PATHS = DEFAULT_REDACT_PATHS;
4655
4850
  exports.InjectLogger = InjectLogger;
4656
4851
  exports.LOGGER_DESTINATIONS_TOKEN = LOGGER_DESTINATIONS_TOKEN;
4852
+ exports.LOGGER_OBSERVABILITY_TOKEN = LOGGER_OBSERVABILITY_TOKEN;
4657
4853
  exports.LOGGER_OPTIONS_TOKEN = LOGGER_OPTIONS_TOKEN;
4658
4854
  exports.LOGGER_PINO_INSTANCE_TOKEN = LOGGER_PINO_INSTANCE_TOKEN;
4659
4855
  exports.LOGGER_REDACTOR_TOKEN = LOGGER_REDACTOR_TOKEN;