@bymax-one/nest-logger 1.4.23 → 1.4.25
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 +220 -1
- package/README.md +158 -58
- 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 +416 -149
- package/dist/server/index.d.cts +82 -4
- package/dist/server/index.d.ts +82 -4
- package/dist/server/index.mjs +416 -150
- 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/dist/server/index.cjs
CHANGED
|
@@ -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
|
|
564
|
+
function createTextCensor(redact) {
|
|
554
565
|
return (key, text) => {
|
|
555
566
|
try {
|
|
556
567
|
const censored = Reflect.get(redact({ [key]: text }, true), key);
|
|
557
|
-
|
|
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,35 @@ 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 IGNORED = /[\s._\p{Cf}-]/gu;
|
|
607
|
+
var DOT_ABOVE = /\u0307/g;
|
|
608
|
+
var PLAIN = /^[\x21-\x7e]*$/;
|
|
609
|
+
var LOOKALIKES = new Map(
|
|
610
|
+
Object.entries({
|
|
611
|
+
a: "\u0430\u03B1",
|
|
612
|
+
c: "\u0441\u03F2",
|
|
613
|
+
d: "\u0501",
|
|
614
|
+
e: "\u0435",
|
|
615
|
+
i: "\u0456\u03B9",
|
|
616
|
+
j: "\u0458",
|
|
617
|
+
o: "\u043E\u03BF",
|
|
618
|
+
p: "\u0440\u03C1",
|
|
619
|
+
q: "\u051B",
|
|
620
|
+
s: "\u0455",
|
|
621
|
+
v: "\u03BD",
|
|
622
|
+
w: "\u051D",
|
|
623
|
+
x: "\u0445",
|
|
624
|
+
y: "\u0443"
|
|
625
|
+
}).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
|
|
626
|
+
);
|
|
627
|
+
function foldKey(key) {
|
|
628
|
+
if (PLAIN.test(key)) return key.replace(IGNORED, "").toLowerCase();
|
|
629
|
+
let folded = key.normalize("NFKC").replace(IGNORED, "").toLowerCase().replace(DOT_ABOVE, "");
|
|
630
|
+
for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
|
|
631
|
+
return folded;
|
|
632
|
+
}
|
|
633
|
+
|
|
585
634
|
// src/server/utils/is-plain-record.util.ts
|
|
586
635
|
function isPlainRecord(node) {
|
|
587
636
|
try {
|
|
@@ -591,6 +640,25 @@ function isPlainRecord(node) {
|
|
|
591
640
|
return false;
|
|
592
641
|
}
|
|
593
642
|
}
|
|
643
|
+
|
|
644
|
+
// src/server/utils/censor-stack-header.util.ts
|
|
645
|
+
var NAME_SEPARATOR = ": ";
|
|
646
|
+
function endsHeader(stack, message, from) {
|
|
647
|
+
const end = from + message.length;
|
|
648
|
+
return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
|
|
649
|
+
}
|
|
650
|
+
function censorStackHeader(stack, name, message, censored) {
|
|
651
|
+
if (message === "" || censored === message) return stack;
|
|
652
|
+
const separator = stack.indexOf(NAME_SEPARATOR);
|
|
653
|
+
if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
|
|
654
|
+
const from = separator + NAME_SEPARATOR.length;
|
|
655
|
+
if (endsHeader(stack, message, from)) {
|
|
656
|
+
return stack.slice(0, from) + censored + stack.slice(from + message.length);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
|
|
660
|
+
return name === "" ? censored : name + NAME_SEPARATOR + censored;
|
|
661
|
+
}
|
|
594
662
|
function isError(value) {
|
|
595
663
|
try {
|
|
596
664
|
return util.types.isNativeError(value) || value instanceof Error;
|
|
@@ -654,7 +722,8 @@ function sanitizeError(err, options) {
|
|
|
654
722
|
const maxCauseDepth = options?.maxCauseDepth ?? DEFAULT_MAX_CAUSE_DEPTH;
|
|
655
723
|
return toSanitizedError(err, /* @__PURE__ */ new WeakSet(), 0, {
|
|
656
724
|
maxDepth: maxCauseDepth,
|
|
657
|
-
ownFields: options?.ownFields ?? ALL_OWN_FIELDS
|
|
725
|
+
ownFields: options?.ownFields ?? ALL_OWN_FIELDS,
|
|
726
|
+
censorMessage: options?.censorMessage
|
|
658
727
|
});
|
|
659
728
|
}
|
|
660
729
|
function isErrorLike(value) {
|
|
@@ -671,17 +740,24 @@ function readsAsError(value) {
|
|
|
671
740
|
const candidate = value;
|
|
672
741
|
return typeof candidate.name === "string" && typeof candidate.message === "string";
|
|
673
742
|
}
|
|
743
|
+
function readScrubbedStack(value, name, message, result, walk2) {
|
|
744
|
+
const stack = readOptional(() => value.stack, result);
|
|
745
|
+
return stack === void 0 ? void 0 : scrubStack(stack, headerCensor(name, message, walk2.censorMessage));
|
|
746
|
+
}
|
|
674
747
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
675
748
|
try {
|
|
676
749
|
if (!readsAsError(value)) {
|
|
677
750
|
return { name: "UnknownError", message: cutText(String(value)) };
|
|
678
751
|
}
|
|
679
752
|
seen.add(value);
|
|
680
|
-
const
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
753
|
+
const message = value.message;
|
|
754
|
+
const name = cutText(value.name);
|
|
755
|
+
const result = {
|
|
756
|
+
name: censorName(name, walk2.censorMessage),
|
|
757
|
+
message: cutText(message)
|
|
758
|
+
};
|
|
759
|
+
const stack = readScrubbedStack(value, name, message, result, walk2);
|
|
760
|
+
if (stack !== void 0) result.stack = stack;
|
|
685
761
|
const isAtDepthLimit = depth2 >= walk2.maxDepth;
|
|
686
762
|
const cause = readOptional(() => value.cause, result);
|
|
687
763
|
if (cause !== void 0) {
|
|
@@ -769,9 +845,39 @@ function readAggregatedErrors(value) {
|
|
|
769
845
|
return Array.isArray(candidate) ? candidate : void 0;
|
|
770
846
|
}
|
|
771
847
|
var MAX_STACK_SCAN = 8 * MAX_TEXT_LENGTH;
|
|
772
|
-
|
|
848
|
+
var MAX_PLAIN_NAME = 64;
|
|
849
|
+
var PLAIN_NAME = /^[A-Za-z_$][\w$.-]*$/;
|
|
850
|
+
function censorName(name, censorMessage) {
|
|
851
|
+
if (censorMessage === void 0 || name === "") return name;
|
|
852
|
+
if (name.length <= MAX_PLAIN_NAME && PLAIN_NAME.test(name)) return name;
|
|
853
|
+
try {
|
|
854
|
+
return censorMessage(name);
|
|
855
|
+
} catch {
|
|
856
|
+
return "";
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function headerCensor(name, message, censorMessage) {
|
|
860
|
+
if (typeof message !== "string" || censorMessage === void 0) return void 0;
|
|
861
|
+
const named = typeof name === "string" ? name : "";
|
|
862
|
+
const censoredName = censorName(named, censorMessage);
|
|
863
|
+
try {
|
|
864
|
+
return { name: named, censoredName, message, censored: censorMessage(message) };
|
|
865
|
+
} catch {
|
|
866
|
+
return { name: named, censoredName, message, censored: "" };
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function censorStackName(stack, header) {
|
|
870
|
+
return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
|
|
871
|
+
}
|
|
872
|
+
function scrubStack(stack, header) {
|
|
873
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
773
874
|
const scrubbed = escapeControlCharacters(
|
|
774
|
-
|
|
875
|
+
(header === void 0 ? head : censorStackHeader(
|
|
876
|
+
censorStackName(head, header),
|
|
877
|
+
header.censoredName,
|
|
878
|
+
header.message,
|
|
879
|
+
header.censored
|
|
880
|
+
)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
775
881
|
);
|
|
776
882
|
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
777
883
|
}
|
|
@@ -787,14 +893,21 @@ function createWidthMarker(omitted) {
|
|
|
787
893
|
|
|
788
894
|
// src/server/services/pino-logger.service.ts
|
|
789
895
|
var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
|
|
790
|
-
var ENTRY_STRUCTURE_KEYS =
|
|
791
|
-
|
|
792
|
-
"
|
|
793
|
-
"
|
|
794
|
-
"service",
|
|
795
|
-
"
|
|
796
|
-
|
|
797
|
-
|
|
896
|
+
var ENTRY_STRUCTURE_KEYS = ["level", "time", "msg", "service", "deployment"];
|
|
897
|
+
var RESOURCE_KEYS = [
|
|
898
|
+
"service.name",
|
|
899
|
+
"service.version",
|
|
900
|
+
"service.namespace",
|
|
901
|
+
"service.instance.id",
|
|
902
|
+
"deployment.environment.name"
|
|
903
|
+
];
|
|
904
|
+
var OWNED_KEY_SPELLINGS = new Set(
|
|
905
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
|
|
906
|
+
);
|
|
907
|
+
var isOwnedKey = (key) => {
|
|
908
|
+
const lower = key.toLowerCase();
|
|
909
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
910
|
+
};
|
|
798
911
|
function withoutOwnedKeys(metadata, omit) {
|
|
799
912
|
if (metadata === void 0) {
|
|
800
913
|
return {};
|
|
@@ -802,7 +915,7 @@ function withoutOwnedKeys(metadata, omit) {
|
|
|
802
915
|
try {
|
|
803
916
|
const safe = {};
|
|
804
917
|
for (const key of Object.keys(metadata)) {
|
|
805
|
-
if (key !== omit && !
|
|
918
|
+
if (key !== omit && !isOwnedKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
|
|
806
919
|
Reflect.set(safe, key, Reflect.get(metadata, key));
|
|
807
920
|
}
|
|
808
921
|
}
|
|
@@ -907,7 +1020,7 @@ exports.PinoLoggerService = class PinoLoggerService {
|
|
|
907
1020
|
if (isErrorLike(message)) {
|
|
908
1021
|
const payload2 = { err: message };
|
|
909
1022
|
assignIfDefined(payload2, "context", this.resolveContext(optionalParams));
|
|
910
|
-
this.pino.error(payload2,
|
|
1023
|
+
this.pino.error(payload2, this.errorText(message));
|
|
911
1024
|
return;
|
|
912
1025
|
}
|
|
913
1026
|
const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
|
|
@@ -916,7 +1029,7 @@ exports.PinoLoggerService = class PinoLoggerService {
|
|
|
916
1029
|
assignIfDefined(payload, "context", context);
|
|
917
1030
|
assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
|
|
918
1031
|
assignIfDefined(payload, "err", findErrorParam(optionalParams));
|
|
919
|
-
this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
|
|
1032
|
+
this.pino.error(payload, this.nestStyleMessage("error", void 0, fields, text, message));
|
|
920
1033
|
}
|
|
921
1034
|
/**
|
|
922
1035
|
* NestJS `warn` (warn level).
|
|
@@ -1002,7 +1115,7 @@ exports.PinoLoggerService = class PinoLoggerService {
|
|
|
1002
1115
|
};
|
|
1003
1116
|
assignIfDefined(payload, "userId", userId);
|
|
1004
1117
|
assignIfDefined(payload, "context", this.context);
|
|
1005
|
-
this.pino.error(payload,
|
|
1118
|
+
this.pino.error(payload, this.errorText(error));
|
|
1006
1119
|
}
|
|
1007
1120
|
// ─── Helpers / escape hatches ─────────────────────────────────────────────
|
|
1008
1121
|
/**
|
|
@@ -1068,30 +1181,57 @@ exports.PinoLoggerService = class PinoLoggerService {
|
|
|
1068
1181
|
}
|
|
1069
1182
|
}
|
|
1070
1183
|
/** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
|
|
1071
|
-
nestStyleMessage(leading, fields, text, message) {
|
|
1072
|
-
if (leading !== void 0) return
|
|
1073
|
-
if (fields !== void 0)
|
|
1184
|
+
nestStyleMessage(level, leading, fields, text, message) {
|
|
1185
|
+
if (leading !== void 0) return this.errorText(leading);
|
|
1186
|
+
if (fields !== void 0) {
|
|
1187
|
+
return toBoundedMessage(this.censorText(text, { emitted: this.pino.isLevelEnabled(level) }));
|
|
1188
|
+
}
|
|
1074
1189
|
return safeLogMessage(message);
|
|
1075
1190
|
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Censor a text as the `message` of an entry is: under the name `message`, by the rules of
|
|
1193
|
+
* `redactPaths` and `redactCensor`, and neither cut nor counted. The lines the library writes to
|
|
1194
|
+
* `stderr` about a failure use it for the message of the error they carry.
|
|
1195
|
+
*
|
|
1196
|
+
* @internal Used by `PinoUnexpectedErrorSink`. NOT part of the supported API.
|
|
1197
|
+
* @param text - The text to censor.
|
|
1198
|
+
* @returns The text, or what hides it, and an empty text when the censor itself fails.
|
|
1199
|
+
*/
|
|
1200
|
+
censorMessageText(text) {
|
|
1201
|
+
return this.censorText({ key: "message", text });
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* The entry text of an `Error`: its `message`, read without letting a hostile getter escape, then
|
|
1205
|
+
* censored under the name `message`, as the field `err.message` it is a copy of. It is not cut at
|
|
1206
|
+
* `maxStringLength`: the option does not apply to the log message, which is capped at 16384.
|
|
1207
|
+
*
|
|
1208
|
+
* @param error - The error being logged.
|
|
1209
|
+
* @returns The text of the entry.
|
|
1210
|
+
*/
|
|
1211
|
+
errorText(error) {
|
|
1212
|
+
return toBoundedMessage(this.censorText({ key: "message", text: safeErrorMessage(error) }));
|
|
1213
|
+
}
|
|
1076
1214
|
/**
|
|
1077
1215
|
* The entry text of an object message, censored under the names of the field it came from and cut
|
|
1078
1216
|
* like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
|
|
1079
1217
|
* value the pipeline censors or cuts in the field itself.
|
|
1080
1218
|
*
|
|
1081
1219
|
* @param text - The text and the member it came from.
|
|
1220
|
+
* @param cut - Present when the text is cut at `maxStringLength`; says whether the entry is
|
|
1221
|
+
* written, so that a cut of it is counted.
|
|
1082
1222
|
* @returns The censored text, or an empty one when the redactor cannot be applied.
|
|
1083
1223
|
*/
|
|
1084
|
-
censorText(text) {
|
|
1224
|
+
censorText(text, cut) {
|
|
1085
1225
|
if (text === void 0) return "";
|
|
1086
1226
|
const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
|
|
1087
|
-
return finish(text.key, text.text);
|
|
1227
|
+
return finish(text.key, text.text, cut);
|
|
1088
1228
|
}
|
|
1089
1229
|
emitNestStyle(level, message, optionalParams) {
|
|
1090
1230
|
const { fields, text, payload } = readObjectMessage(message);
|
|
1091
1231
|
assignIfDefined(payload, "context", this.resolveContext(optionalParams));
|
|
1092
1232
|
const leading = isErrorLike(message) ? message : void 0;
|
|
1093
1233
|
assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
|
|
1094
|
-
const msg = this.nestStyleMessage(leading, fields, text, message);
|
|
1234
|
+
const msg = this.nestStyleMessage(level, leading, fields, text, message);
|
|
1095
1235
|
switch (level) {
|
|
1096
1236
|
case "info":
|
|
1097
1237
|
this.pino.info(payload, msg);
|
|
@@ -2163,25 +2303,26 @@ var DEFAULT_REDACT_PATHS = [
|
|
|
2163
2303
|
];
|
|
2164
2304
|
|
|
2165
2305
|
// src/server/utils/report-destination-failure.util.ts
|
|
2166
|
-
function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0) {
|
|
2306
|
+
function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0, censorMessage) {
|
|
2167
2307
|
writeStderrSafely(
|
|
2168
2308
|
JSON.stringify({
|
|
2169
2309
|
level: "error",
|
|
2170
2310
|
logKey,
|
|
2171
2311
|
destination: toSingleLineMessage(name),
|
|
2172
|
-
err: describeCause(cause),
|
|
2312
|
+
err: describeCause(cause, censorMessage),
|
|
2173
2313
|
msg: toSingleLineMessage(msg),
|
|
2174
2314
|
...suppressed > 0 ? { suppressed } : {}
|
|
2175
2315
|
}) + "\n"
|
|
2176
2316
|
);
|
|
2177
2317
|
}
|
|
2178
2318
|
var UNREADABLE_CAUSE = { type: "UnknownError", message: "unreadable value" };
|
|
2179
|
-
function describeCause(cause) {
|
|
2319
|
+
function describeCause(cause, censorMessage) {
|
|
2320
|
+
const censor = censorMessage ?? ((text) => text);
|
|
2180
2321
|
try {
|
|
2181
2322
|
return isError(cause) ? {
|
|
2182
|
-
type: toBoundedMessage(String(cause.name)),
|
|
2183
|
-
message: toBoundedMessage(String(cause.message))
|
|
2184
|
-
} : { type: "UnknownError", message: toBoundedMessage(String(cause)) };
|
|
2323
|
+
type: toBoundedMessage(censorName(String(cause.name), censorMessage)),
|
|
2324
|
+
message: toBoundedMessage(censor(String(cause.message)))
|
|
2325
|
+
} : { type: "UnknownError", message: toBoundedMessage(censor(String(cause))) };
|
|
2185
2326
|
} catch {
|
|
2186
2327
|
return UNREADABLE_CAUSE;
|
|
2187
2328
|
}
|
|
@@ -2239,7 +2380,7 @@ function loadTraceApiFrom(anchor) {
|
|
|
2239
2380
|
return isOtelApiMissing(cause) ? { api: void 0 } : { api: void 0, broken: { cause } };
|
|
2240
2381
|
}
|
|
2241
2382
|
}
|
|
2242
|
-
function warnBrokenInstallOnce(cause) {
|
|
2383
|
+
function warnBrokenInstallOnce(cause, censorMessage) {
|
|
2243
2384
|
if (brokenInstallWarned) {
|
|
2244
2385
|
return;
|
|
2245
2386
|
}
|
|
@@ -2249,7 +2390,7 @@ function warnBrokenInstallOnce(cause) {
|
|
|
2249
2390
|
level: "warn",
|
|
2250
2391
|
logKey: RESERVED_LOG_KEYS.LOGGER_OTEL_API_BROKEN,
|
|
2251
2392
|
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)
|
|
2393
|
+
err: describeCause(cause, censorMessage)
|
|
2253
2394
|
}) + "\n"
|
|
2254
2395
|
);
|
|
2255
2396
|
}
|
|
@@ -2257,7 +2398,7 @@ var DEFAULT_ANCHORS = [
|
|
|
2257
2398
|
() => __filename,
|
|
2258
2399
|
() => path.join(process.cwd(), "noop.cjs")
|
|
2259
2400
|
];
|
|
2260
|
-
function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
|
|
2401
|
+
function detectOtelTraceApi(anchors = DEFAULT_ANCHORS, censorMessage) {
|
|
2261
2402
|
let broken;
|
|
2262
2403
|
for (const anchor of anchors) {
|
|
2263
2404
|
const attempt = loadTraceApiFrom(anchor);
|
|
@@ -2267,7 +2408,7 @@ function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
|
|
|
2267
2408
|
broken ??= attempt.broken;
|
|
2268
2409
|
}
|
|
2269
2410
|
if (broken !== void 0) {
|
|
2270
|
-
warnBrokenInstallOnce(broken.cause);
|
|
2411
|
+
warnBrokenInstallOnce(broken.cause, censorMessage);
|
|
2271
2412
|
}
|
|
2272
2413
|
return void 0;
|
|
2273
2414
|
}
|
|
@@ -2280,7 +2421,7 @@ function isValidSpanId(spanId) {
|
|
|
2280
2421
|
|
|
2281
2422
|
// src/server/mixins/trace-context.mixin.ts
|
|
2282
2423
|
function createTraceContextMixin(logContext, opts) {
|
|
2283
|
-
const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi() : void 0;
|
|
2424
|
+
const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi(void 0, opts.censorMessage) : void 0;
|
|
2284
2425
|
return function mixin(_mergeObject, _level, _logger) {
|
|
2285
2426
|
const merged = {};
|
|
2286
2427
|
const store = logContext.getStore();
|
|
@@ -2302,7 +2443,7 @@ function createTraceContextMixin(logContext, opts) {
|
|
|
2302
2443
|
}
|
|
2303
2444
|
}
|
|
2304
2445
|
} catch (cause) {
|
|
2305
|
-
warnBrokenInstallOnce(cause);
|
|
2446
|
+
warnBrokenInstallOnce(cause, opts.censorMessage);
|
|
2306
2447
|
}
|
|
2307
2448
|
}
|
|
2308
2449
|
return merged;
|
|
@@ -2316,34 +2457,45 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
|
|
|
2316
2457
|
}
|
|
2317
2458
|
|
|
2318
2459
|
// src/server/utils/cut-strings.util.ts
|
|
2319
|
-
function cutNode(node, limit) {
|
|
2320
|
-
if (typeof node === "string")
|
|
2321
|
-
|
|
2460
|
+
function cutNode(node, limit, onCut) {
|
|
2461
|
+
if (typeof node === "string") {
|
|
2462
|
+
const cut = cutText(node, false, limit);
|
|
2463
|
+
if (cut !== node) onCut?.();
|
|
2464
|
+
return cut;
|
|
2465
|
+
}
|
|
2466
|
+
if (Array.isArray(node)) return node.map((child) => cutNode(child, limit, onCut));
|
|
2322
2467
|
if (isPlainRecord(node)) {
|
|
2323
2468
|
return Object.fromEntries(
|
|
2324
|
-
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
|
|
2469
|
+
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit, onCut)])
|
|
2325
2470
|
);
|
|
2326
2471
|
}
|
|
2327
2472
|
return node;
|
|
2328
2473
|
}
|
|
2329
|
-
function cutStrings(record, limit, exempt) {
|
|
2474
|
+
function cutStrings(record, limit, exempt, onCut) {
|
|
2330
2475
|
return Object.fromEntries(
|
|
2331
2476
|
Object.entries(record).map(([key, child]) => [
|
|
2332
2477
|
key,
|
|
2333
|
-
exempt.has(key) ? child : cutNode(child, limit)
|
|
2478
|
+
exempt.has(key) ? child : cutNode(child, limit, onCut)
|
|
2334
2479
|
])
|
|
2335
2480
|
);
|
|
2336
2481
|
}
|
|
2337
|
-
function reportWriteFailure(destination, cause, due) {
|
|
2482
|
+
function reportWriteFailure(destination, cause, due, censorMessage) {
|
|
2338
2483
|
const name = safeDestinationName(destination);
|
|
2339
2484
|
reportDestinationFailure(
|
|
2340
2485
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_WRITE_FAILED,
|
|
2341
2486
|
name,
|
|
2342
2487
|
cause,
|
|
2343
|
-
|
|
2344
|
-
due - 1
|
|
2488
|
+
"A log destination failed to write; the entry was dropped",
|
|
2489
|
+
due - 1,
|
|
2490
|
+
censorMessage
|
|
2345
2491
|
);
|
|
2346
2492
|
}
|
|
2493
|
+
function recordWriteFailure(destination, health, cause, censorMessage) {
|
|
2494
|
+
const due = health.recordWriteFailure(destination, performance.now());
|
|
2495
|
+
if (due !== void 0) {
|
|
2496
|
+
reportWriteFailure(destination, cause, due, censorMessage);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2347
2499
|
function rescueToStdout(payload) {
|
|
2348
2500
|
writeStdoutSafely(payload);
|
|
2349
2501
|
}
|
|
@@ -2417,7 +2569,7 @@ var BoundedWritable = class extends stream.Writable {
|
|
|
2417
2569
|
);
|
|
2418
2570
|
}
|
|
2419
2571
|
};
|
|
2420
|
-
function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
2572
|
+
function destinationToStream(destination, health, maxQueueBytes = 0, censorMessage) {
|
|
2421
2573
|
const queue = { bytes: 0 };
|
|
2422
2574
|
const stream = new BoundedWritable(destination, health, maxQueueBytes, queue, {
|
|
2423
2575
|
// Keep string chunks as strings (Node's default re-encodes them to Buffers
|
|
@@ -2432,10 +2584,7 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
|
2432
2584
|
settled(error);
|
|
2433
2585
|
};
|
|
2434
2586
|
const onFailure = (cause) => {
|
|
2435
|
-
|
|
2436
|
-
if (due !== void 0) {
|
|
2437
|
-
reportWriteFailure(destination, cause, due);
|
|
2438
|
-
}
|
|
2587
|
+
recordWriteFailure(destination, health, cause, censorMessage);
|
|
2439
2588
|
callback();
|
|
2440
2589
|
};
|
|
2441
2590
|
try {
|
|
@@ -2477,8 +2626,14 @@ var EXPLICIT_USER_KEY = "userId";
|
|
|
2477
2626
|
function mergeMixinSafely(mergeObject, mixinObject) {
|
|
2478
2627
|
try {
|
|
2479
2628
|
const merged = {};
|
|
2629
|
+
const written = /* @__PURE__ */ new Set();
|
|
2630
|
+
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2631
|
+
if (value !== void 0) written.add(foldKey(key));
|
|
2632
|
+
}
|
|
2480
2633
|
for (const key of Object.keys(mergeObject)) {
|
|
2481
|
-
if (key
|
|
2634
|
+
if (key === PROTOTYPE_KEY) continue;
|
|
2635
|
+
if (key !== EXPLICIT_USER_KEY && written.has(foldKey(key))) continue;
|
|
2636
|
+
Reflect.set(merged, key, Reflect.get(mergeObject, key));
|
|
2482
2637
|
}
|
|
2483
2638
|
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2484
2639
|
if (value === void 0) continue;
|
|
@@ -2752,11 +2907,11 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
2752
2907
|
defineOwn(
|
|
2753
2908
|
copy,
|
|
2754
2909
|
key,
|
|
2755
|
-
rules.sensitive.has(key.toLowerCase()) ? rules.censor : censorHeaderArray(
|
|
2910
|
+
rules.sensitive.has(key.toLowerCase()) && !rules.exemptKeys?.has(key.toLowerCase()) ? rules.censor : censorHeaderArray(
|
|
2756
2911
|
key,
|
|
2757
2912
|
walk(
|
|
2758
2913
|
scrubbed && ERROR_TEXT_FIELDS.has(key) ? cutIfText(current) : current,
|
|
2759
|
-
rules,
|
|
2914
|
+
rulesBelow(rules, key, current, honorToJson),
|
|
2760
2915
|
depth2 + 1,
|
|
2761
2916
|
ancestors,
|
|
2762
2917
|
true,
|
|
@@ -2772,6 +2927,16 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
2772
2927
|
}
|
|
2773
2928
|
return copy;
|
|
2774
2929
|
}
|
|
2930
|
+
function leavesErrorText(rules, key, value, honorToJson) {
|
|
2931
|
+
return rules.errorTextToSerializer && !honorToJson && key === "err" && !isError(value) && isErrorLike(value);
|
|
2932
|
+
}
|
|
2933
|
+
function rulesBelow(rules, key, value, honorToJson) {
|
|
2934
|
+
if (leavesErrorText(rules, key, value, honorToJson)) {
|
|
2935
|
+
return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
|
|
2936
|
+
}
|
|
2937
|
+
return rules.exemptKeys === void 0 ? rules : { ...rules, exemptKeys: void 0 };
|
|
2938
|
+
}
|
|
2939
|
+
var ERROR_TEXT_KEYS = /* @__PURE__ */ new Set(["message"]);
|
|
2775
2940
|
function without(keys, omitted) {
|
|
2776
2941
|
return keys.filter((key) => !omitted.has(key));
|
|
2777
2942
|
}
|
|
@@ -2792,13 +2957,14 @@ function errorPartsHost(rules, ancestors, inSerialized) {
|
|
|
2792
2957
|
hasToJson: (value) => !rules.ownFields.safe && resolveToJson(value).method !== void 0
|
|
2793
2958
|
};
|
|
2794
2959
|
}
|
|
2795
|
-
function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames) {
|
|
2960
|
+
function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames, errorTextToSerializer = false) {
|
|
2796
2961
|
const rules = {
|
|
2797
2962
|
sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
|
|
2798
2963
|
headerNames: new Set(Array.from(headerNames ?? fieldNames, (name) => name.toLowerCase())),
|
|
2799
2964
|
censor,
|
|
2800
2965
|
serializedKeys: new Set(serializedKeys),
|
|
2801
2966
|
errorsAsData: serializedKeys !== void 0,
|
|
2967
|
+
errorTextToSerializer,
|
|
2802
2968
|
maxVisits,
|
|
2803
2969
|
ownFields
|
|
2804
2970
|
};
|
|
@@ -2942,6 +3108,48 @@ function extraServiceFields(service) {
|
|
|
2942
3108
|
return extras;
|
|
2943
3109
|
}
|
|
2944
3110
|
|
|
3111
|
+
// src/server/utils/semconv-exception.util.ts
|
|
3112
|
+
function deriveExceptionFields(record, maxBytes, onCut, censorMessage, redactStack) {
|
|
3113
|
+
const bounded = (text) => {
|
|
3114
|
+
const cut = cutBytes(text, maxBytes);
|
|
3115
|
+
if (cut !== text) onCut?.();
|
|
3116
|
+
return cut;
|
|
3117
|
+
};
|
|
3118
|
+
const candidate = record["err"];
|
|
3119
|
+
if (typeof candidate?.name === "string") {
|
|
3120
|
+
const type = bounded(censorName(cutText(candidate.name), censorMessage));
|
|
3121
|
+
record["exception.type"] = type;
|
|
3122
|
+
record["error.type"] = type;
|
|
3123
|
+
}
|
|
3124
|
+
const message = candidate?.message;
|
|
3125
|
+
const header = headerCensor(candidate?.name, message, censorMessage);
|
|
3126
|
+
if (header !== void 0) {
|
|
3127
|
+
record["exception.message"] = bounded(cutText(header.censored));
|
|
3128
|
+
}
|
|
3129
|
+
if (typeof candidate?.name === "string" && typeof message === "string" && typeof candidate.stack === "string") {
|
|
3130
|
+
record["exception.stacktrace"] = bounded(redactStack(scrubStack(candidate.stack, header)));
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
function withSemconvException(record, format, maxBytes = Number.POSITIVE_INFINITY, onCut, censorMessage = (text) => text, redactStack = (stack) => stack) {
|
|
3134
|
+
if (format === "pino") {
|
|
3135
|
+
return record;
|
|
3136
|
+
}
|
|
3137
|
+
try {
|
|
3138
|
+
deriveExceptionFields(record, maxBytes, onCut, censorMessage, redactStack);
|
|
3139
|
+
if (format === "semconv") {
|
|
3140
|
+
const withoutErr = {};
|
|
3141
|
+
for (const [key, value] of Object.entries(record)) {
|
|
3142
|
+
if (key !== "err") {
|
|
3143
|
+
Reflect.set(withoutErr, key, value);
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
return withoutErr;
|
|
3147
|
+
}
|
|
3148
|
+
} catch {
|
|
3149
|
+
}
|
|
3150
|
+
return record;
|
|
3151
|
+
}
|
|
3152
|
+
|
|
2945
3153
|
// src/server/utils/serialize-request.util.ts
|
|
2946
3154
|
function isObject2(value) {
|
|
2947
3155
|
return typeof value === "object" && value !== null;
|
|
@@ -2977,20 +3185,34 @@ function withSerializedRequest(record, secretSegments = []) {
|
|
|
2977
3185
|
|
|
2978
3186
|
// src/server/utils/truncate-large-entries.ts
|
|
2979
3187
|
var PREVIEW_LENGTH = 200;
|
|
2980
|
-
function
|
|
3188
|
+
function measurableJson(value) {
|
|
3189
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
3190
|
+
return JSON.stringify(value, function(_key, inner) {
|
|
3191
|
+
if (typeof inner === "bigint") return inner.toString();
|
|
3192
|
+
if (typeof inner !== "object" || inner === null) return inner;
|
|
3193
|
+
for (let holder = this; holder !== void 0; holder = parents.get(holder)) {
|
|
3194
|
+
if (holder === inner) return "[Circular]";
|
|
3195
|
+
}
|
|
3196
|
+
parents.set(inner, this);
|
|
3197
|
+
return inner;
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
function createSizeBoundedSerializer(baseSerializer, maxBytes, onTruncate) {
|
|
2981
3201
|
return (input) => {
|
|
2982
3202
|
const serialized = baseSerializer(input);
|
|
2983
3203
|
let json;
|
|
2984
3204
|
try {
|
|
2985
|
-
json =
|
|
3205
|
+
json = measurableJson(serialized);
|
|
2986
3206
|
} catch {
|
|
2987
|
-
|
|
3207
|
+
onTruncate?.();
|
|
3208
|
+
return unmeasurableEnvelope();
|
|
2988
3209
|
}
|
|
2989
3210
|
if (json === void 0) {
|
|
2990
3211
|
return serialized;
|
|
2991
3212
|
}
|
|
2992
3213
|
const byteSize = Buffer.byteLength(json, "utf-8");
|
|
2993
3214
|
if (byteSize > maxBytes) {
|
|
3215
|
+
onTruncate?.();
|
|
2994
3216
|
return {
|
|
2995
3217
|
_truncated: true,
|
|
2996
3218
|
_logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
|
|
@@ -3001,6 +3223,14 @@ function createSizeBoundedSerializer(baseSerializer, maxBytes) {
|
|
|
3001
3223
|
return serialized;
|
|
3002
3224
|
};
|
|
3003
3225
|
}
|
|
3226
|
+
function unmeasurableEnvelope() {
|
|
3227
|
+
return {
|
|
3228
|
+
_truncated: true,
|
|
3229
|
+
_logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
|
|
3230
|
+
_originalSize: -1,
|
|
3231
|
+
_preview: ""
|
|
3232
|
+
};
|
|
3233
|
+
}
|
|
3004
3234
|
|
|
3005
3235
|
// src/server/pino-factory.ts
|
|
3006
3236
|
var PATH_SEGMENT = /\[\s*['"]([^'"]+)['"]\s*\]|([^.[\]]+)/g;
|
|
@@ -3016,8 +3246,8 @@ function leafNameOf(path) {
|
|
|
3016
3246
|
}
|
|
3017
3247
|
return leaf;
|
|
3018
3248
|
}
|
|
3019
|
-
function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
|
|
3020
|
-
const sanitized = sanitizeError(value_, { ownFields });
|
|
3249
|
+
function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS, censorMessage) {
|
|
3250
|
+
const sanitized = sanitizeError(value_, { ownFields, censorMessage });
|
|
3021
3251
|
const serialized = {
|
|
3022
3252
|
// `type` rather than `name`: the field consumers already query.
|
|
3023
3253
|
type: sanitized.name,
|
|
@@ -3035,35 +3265,6 @@ function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
|
|
|
3035
3265
|
assignOwnErrorFields(serialized, sanitized);
|
|
3036
3266
|
return serialized;
|
|
3037
3267
|
}
|
|
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
3268
|
function toEventName(logKey) {
|
|
3068
3269
|
return logKey.toLowerCase().replaceAll("_", ".");
|
|
3069
3270
|
}
|
|
@@ -3116,7 +3317,8 @@ function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = tr
|
|
|
3116
3317
|
void 0,
|
|
3117
3318
|
ownFields,
|
|
3118
3319
|
coversNames ? void 0 : namesInsideErrors(options),
|
|
3119
|
-
allNames
|
|
3320
|
+
allNames,
|
|
3321
|
+
!Object.hasOwn(options.serializers, "err")
|
|
3120
3322
|
) : createNameRedactor(
|
|
3121
3323
|
names,
|
|
3122
3324
|
options.redactCensor,
|
|
@@ -3134,11 +3336,16 @@ function resolveRedactOption(options) {
|
|
|
3134
3336
|
}
|
|
3135
3337
|
return { paths, censor: options.redactCensor };
|
|
3136
3338
|
}
|
|
3137
|
-
function buildSerializers(options, redactSerialized, ownFields) {
|
|
3339
|
+
function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
|
|
3138
3340
|
const maxBytes = options.maxEntrySizeBytes;
|
|
3139
|
-
const
|
|
3341
|
+
const censorMessage = buildMessageCensor(options);
|
|
3342
|
+
const bound = (serializer) => createSizeBoundedSerializer(
|
|
3343
|
+
(input) => redactSerialized(serializer(input)),
|
|
3344
|
+
maxBytes,
|
|
3345
|
+
() => onTruncate("max_entry_size")
|
|
3346
|
+
);
|
|
3140
3347
|
return {
|
|
3141
|
-
err: bound((error) => serializeErrorValue(error, ownFields)),
|
|
3348
|
+
err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
|
|
3142
3349
|
...Object.fromEntries(
|
|
3143
3350
|
Object.entries(options.serializers).map(
|
|
3144
3351
|
([key, serializer]) => [key, bound(serializer)]
|
|
@@ -3146,14 +3353,35 @@ function buildSerializers(options, redactSerialized, ownFields) {
|
|
|
3146
3353
|
)
|
|
3147
3354
|
};
|
|
3148
3355
|
}
|
|
3149
|
-
function
|
|
3356
|
+
function buildMessageCensor(options) {
|
|
3357
|
+
const censor = createTextCensor(buildNameRedactor(options));
|
|
3358
|
+
return (text) => censor("message", text);
|
|
3359
|
+
}
|
|
3360
|
+
function withEntryTextFinisher(logger, options, onTruncate) {
|
|
3150
3361
|
const redact = buildNameRedactor(options);
|
|
3151
|
-
|
|
3362
|
+
const finisher = createEntryTextFinisher(
|
|
3363
|
+
redact,
|
|
3364
|
+
options.maxStringLength,
|
|
3365
|
+
() => onTruncate("max_string_length")
|
|
3366
|
+
);
|
|
3367
|
+
Reflect.set(logger, ENTRY_TEXT_FINISHER, finisher);
|
|
3152
3368
|
return logger;
|
|
3153
3369
|
}
|
|
3370
|
+
function buildTraceMixin(logContext, options) {
|
|
3371
|
+
return createTraceContextMixin(logContext, {
|
|
3372
|
+
...options.otel,
|
|
3373
|
+
censorMessage: buildMessageCensor(options)
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3154
3376
|
function buildStreams(options, destinations, health) {
|
|
3377
|
+
const censorMessage = buildMessageCensor(options);
|
|
3155
3378
|
return destinations.map((destination) => {
|
|
3156
|
-
const stream = destinationToStream(
|
|
3379
|
+
const stream = destinationToStream(
|
|
3380
|
+
destination,
|
|
3381
|
+
health,
|
|
3382
|
+
options.destinationQueue.maxBytes,
|
|
3383
|
+
censorMessage
|
|
3384
|
+
);
|
|
3157
3385
|
health.registerStream(destination, stream);
|
|
3158
3386
|
return {
|
|
3159
3387
|
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
@@ -3165,20 +3393,30 @@ function buildStreams(options, destinations, health) {
|
|
|
3165
3393
|
};
|
|
3166
3394
|
});
|
|
3167
3395
|
}
|
|
3168
|
-
function buildRecordFormatter(options, redactRecord) {
|
|
3396
|
+
function buildRecordFormatter(options, redactRecord, onTruncate) {
|
|
3169
3397
|
const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
|
|
3170
3398
|
const maxStringLength = options.maxStringLength;
|
|
3171
3399
|
const wholeRoots = wholeRootKeys(options);
|
|
3400
|
+
const censorMessage = buildMessageCensor(options);
|
|
3401
|
+
const redactSerialized = buildNameRedactor(options);
|
|
3402
|
+
const redactStack = (stack) => redactSerialized({ stack }).stack;
|
|
3172
3403
|
return (record) => {
|
|
3173
3404
|
const redacted = redactRecord(
|
|
3174
3405
|
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
3175
3406
|
true
|
|
3176
3407
|
);
|
|
3177
|
-
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
|
|
3178
|
-
return withSemconvException(
|
|
3408
|
+
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots, () => onTruncate("max_string_length"));
|
|
3409
|
+
return withSemconvException(
|
|
3410
|
+
withEventName(bounded, options.eventNameField),
|
|
3411
|
+
options.errorFormat,
|
|
3412
|
+
options.maxEntrySizeBytes,
|
|
3413
|
+
() => onTruncate("max_entry_size"),
|
|
3414
|
+
censorMessage,
|
|
3415
|
+
redactStack
|
|
3416
|
+
);
|
|
3179
3417
|
};
|
|
3180
3418
|
}
|
|
3181
|
-
function buildFormatters(options, redactRecord, redactBindings) {
|
|
3419
|
+
function buildFormatters(options, redactRecord, redactBindings, onTruncate) {
|
|
3182
3420
|
return {
|
|
3183
3421
|
// Emit the level as a string label instead of the numeric code — easier
|
|
3184
3422
|
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
@@ -3199,7 +3437,7 @@ function buildFormatters(options, redactRecord, redactBindings) {
|
|
|
3199
3437
|
// `base` and child bindings are NOT visible at this hook — they are
|
|
3200
3438
|
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
3201
3439
|
// sensitive, which `pino-factory.spec.ts` pins.
|
|
3202
|
-
log: buildRecordFormatter(options, redactRecord)
|
|
3440
|
+
log: buildRecordFormatter(options, redactRecord, onTruncate)
|
|
3203
3441
|
};
|
|
3204
3442
|
}
|
|
3205
3443
|
function buildPinoInstance(options, logContext, destinations, health) {
|
|
@@ -3210,6 +3448,7 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3210
3448
|
const redactSerialized = buildNameRedactor(options);
|
|
3211
3449
|
const ownFields = ownFieldPolicyOf(options);
|
|
3212
3450
|
const redactOption = resolveRedactOption(options);
|
|
3451
|
+
const onTruncate = (reason) => health.recordTruncation(reason);
|
|
3213
3452
|
const pinoOptions = {
|
|
3214
3453
|
level: options.level,
|
|
3215
3454
|
...redactOption === void 0 ? {} : { redact: redactOption },
|
|
@@ -3226,13 +3465,13 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3226
3465
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
3227
3466
|
// neither break the line nor add fields to it.
|
|
3228
3467
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
3229
|
-
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
|
|
3230
|
-
serializers: buildSerializers(options, redactSerialized, ownFields),
|
|
3231
|
-
mixin:
|
|
3468
|
+
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options), onTruncate),
|
|
3469
|
+
serializers: buildSerializers(options, redactSerialized, ownFields, onTruncate),
|
|
3470
|
+
mixin: buildTraceMixin(logContext, options),
|
|
3232
3471
|
mixinMergeStrategy: mergeMixinSafely
|
|
3233
3472
|
};
|
|
3234
3473
|
const streams = pino__default.default.multistream(buildStreams(options, destinations, health));
|
|
3235
|
-
return withEntryTextFinisher(pino__default.default(pinoOptions, streams), options);
|
|
3474
|
+
return withEntryTextFinisher(pino__default.default(pinoOptions, streams), options, onTruncate);
|
|
3236
3475
|
}
|
|
3237
3476
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
3238
3477
|
function countInWindow(records, destination, now) {
|
|
@@ -3250,6 +3489,9 @@ function countInWindow(records, destination, now) {
|
|
|
3250
3489
|
}
|
|
3251
3490
|
var DestinationHealth = class {
|
|
3252
3491
|
constructor() {
|
|
3492
|
+
/** How many fields were cut or replaced for the entry-size ceiling, and for the string limit. */
|
|
3493
|
+
this.entrySizeTruncations = 0;
|
|
3494
|
+
this.stringLengthTruncations = 0;
|
|
3253
3495
|
/** Destinations whose `onInit()` rejected. Identity-keyed, not name-keyed. */
|
|
3254
3496
|
this.failed = /* @__PURE__ */ new Set();
|
|
3255
3497
|
/**
|
|
@@ -3348,6 +3590,34 @@ var DestinationHealth = class {
|
|
|
3348
3590
|
this.writeFailed.add(destination);
|
|
3349
3591
|
return countInWindow(this.writeFailures, destination, now);
|
|
3350
3592
|
}
|
|
3593
|
+
/**
|
|
3594
|
+
* Record one field cut or replaced for a size bound.
|
|
3595
|
+
*
|
|
3596
|
+
* @param reason - Which bound: the entry-size ceiling or the string limit.
|
|
3597
|
+
*/
|
|
3598
|
+
recordTruncation(reason) {
|
|
3599
|
+
if (reason === "max_entry_size") this.entrySizeTruncations += 1;
|
|
3600
|
+
else this.stringLengthTruncations += 1;
|
|
3601
|
+
}
|
|
3602
|
+
/** @inheritDoc */
|
|
3603
|
+
truncatedTotal(reason) {
|
|
3604
|
+
return reason === "max_entry_size" ? this.entrySizeTruncations : this.stringLengthTruncations;
|
|
3605
|
+
}
|
|
3606
|
+
/** @inheritDoc */
|
|
3607
|
+
destinationErrorTotal() {
|
|
3608
|
+
let total = 0;
|
|
3609
|
+
for (const count of this.writeFailures.values()) total += count.total;
|
|
3610
|
+
return total;
|
|
3611
|
+
}
|
|
3612
|
+
/** @inheritDoc */
|
|
3613
|
+
deliveryState() {
|
|
3614
|
+
return {
|
|
3615
|
+
destinations: this.healthy.size + this.failed.size,
|
|
3616
|
+
failedInit: this.failed.size,
|
|
3617
|
+
writeFailing: this.writeFailed.size,
|
|
3618
|
+
hasHealthySink: this.healthy.size > 0
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3351
3621
|
/**
|
|
3352
3622
|
* How many writes a destination has refused since startup.
|
|
3353
3623
|
*
|
|
@@ -3549,6 +3819,7 @@ var DestinationRegistry = class {
|
|
|
3549
3819
|
* `onInit` runs and cannot be rebuilt afterwards; see `DestinationHealth`.
|
|
3550
3820
|
*/
|
|
3551
3821
|
this.active = [];
|
|
3822
|
+
this.censorMessage = buildMessageCensor(options);
|
|
3552
3823
|
}
|
|
3553
3824
|
/**
|
|
3554
3825
|
* Initialize every registered destination. A destination whose `onInit`
|
|
@@ -3650,12 +3921,13 @@ var DestinationRegistry = class {
|
|
|
3650
3921
|
* @param cause - The thrown or rejected value.
|
|
3651
3922
|
*/
|
|
3652
3923
|
reportInitFailure(destination, cause) {
|
|
3653
|
-
const name = safeDestinationName(destination);
|
|
3654
3924
|
reportDestinationFailure(
|
|
3655
3925
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
|
|
3656
|
-
|
|
3926
|
+
safeDestinationName(destination),
|
|
3657
3927
|
cause,
|
|
3658
|
-
|
|
3928
|
+
"A log destination failed to initialize and will receive no entries. If no destination initializes, entries fall back to raw NDJSON on stdout.",
|
|
3929
|
+
0,
|
|
3930
|
+
this.censorMessage
|
|
3659
3931
|
);
|
|
3660
3932
|
}
|
|
3661
3933
|
/**
|
|
@@ -3674,12 +3946,13 @@ var DestinationRegistry = class {
|
|
|
3674
3946
|
*/
|
|
3675
3947
|
reportHookFailure(destination, cause) {
|
|
3676
3948
|
const stillActive = !this.health.isFailed(destination);
|
|
3677
|
-
const name = safeDestinationName(destination);
|
|
3678
3949
|
reportDestinationFailure(
|
|
3679
3950
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
|
|
3680
|
-
|
|
3951
|
+
safeDestinationName(destination),
|
|
3681
3952
|
cause,
|
|
3682
|
-
|
|
3953
|
+
"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."),
|
|
3954
|
+
0,
|
|
3955
|
+
this.censorMessage
|
|
3683
3956
|
);
|
|
3684
3957
|
}
|
|
3685
3958
|
/**
|
|
@@ -3709,7 +3982,7 @@ var DestinationRegistry = class {
|
|
|
3709
3982
|
}
|
|
3710
3983
|
);
|
|
3711
3984
|
}
|
|
3712
|
-
if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi() === void 0) {
|
|
3985
|
+
if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi(void 0, this.censorMessage) === void 0) {
|
|
3713
3986
|
this.logger.warnStructured(
|
|
3714
3987
|
RESERVED_LOG_KEYS.LOGGER_BOOTSTRAP_WARNING,
|
|
3715
3988
|
"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 +4102,32 @@ var DestinationRegistry = class {
|
|
|
3829
4102
|
}
|
|
3830
4103
|
}
|
|
3831
4104
|
/**
|
|
3832
|
-
* Report a failing `onShutdown` on stderr
|
|
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.
|
|
4105
|
+
* Report a failing `onShutdown` on stderr, as a structured line like the other stages, without
|
|
4106
|
+
* letting the report itself abort the teardown of the destinations still queued behind it.
|
|
3843
4107
|
*
|
|
3844
|
-
* The
|
|
3845
|
-
*
|
|
3846
|
-
*
|
|
4108
|
+
* The line is written by {@link reportDestinationFailure}, which holds every guard the report
|
|
4109
|
+
* needs: the cause is read inside a guard (a hostile getter or `toPrimitive` degrades the detail
|
|
4110
|
+
* and never the line), the text is escaped for a terminal, and the message of the error passes
|
|
4111
|
+
* the censor of the `message` of an entry. The error is a field (`err`) and never part of `msg`,
|
|
4112
|
+
* which is library text, and its stack is not written: a stack is text a host error carries
|
|
4113
|
+
* whole, and the type and the censored message identify the failure.
|
|
3847
4114
|
*
|
|
3848
|
-
* The DESTINATION is passed rather than its name, so that read happens
|
|
3849
|
-
*
|
|
3850
|
-
*
|
|
3851
|
-
* outside the guard — inside the `catch`, where a throw has the same cost.
|
|
3852
|
-
*
|
|
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.
|
|
4115
|
+
* The DESTINATION is passed rather than its name, so that read happens inside the guard too:
|
|
4116
|
+
* `name` is declared `readonly name: string` but nothing stops a consumer implementing it as a
|
|
4117
|
+
* getter, and reading it at the call site would put it back outside the guard.
|
|
3856
4118
|
*
|
|
3857
4119
|
* @param destination - The destination whose `onShutdown` threw.
|
|
3858
4120
|
* @param cause - The thrown value, of any shape.
|
|
3859
4121
|
*/
|
|
3860
4122
|
reportShutdownFailure(destination, cause) {
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
`);
|
|
4123
|
+
reportDestinationFailure(
|
|
4124
|
+
RESERVED_LOG_KEYS.LOGGER_DESTINATION_SHUTDOWN_FAILED,
|
|
4125
|
+
safeDestinationName(destination),
|
|
4126
|
+
cause,
|
|
4127
|
+
"A log destination failed to shut down; anything it was still holding is lost.",
|
|
4128
|
+
0,
|
|
4129
|
+
this.censorMessage
|
|
4130
|
+
);
|
|
3870
4131
|
}
|
|
3871
4132
|
/**
|
|
3872
4133
|
* The destinations that initialized successfully.
|
|
@@ -3897,6 +4158,8 @@ function buildCommonProviders() {
|
|
|
3897
4158
|
// and by DestinationRegistry (which writes to it during onModuleInit). Both
|
|
3898
4159
|
// depend on this provider and it depends on nothing, so there is no cycle.
|
|
3899
4160
|
DestinationHealth,
|
|
4161
|
+
// The counters and the delivery state of the logger, for the `/observability` subpath.
|
|
4162
|
+
{ provide: LOGGER_OBSERVABILITY_TOKEN, useExisting: DestinationHealth },
|
|
3900
4163
|
{
|
|
3901
4164
|
// The DEFAULT-coverage redactor, shared by the Pino factory's hooks and by
|
|
3902
4165
|
// `PinoLoggerService.child()`. The latter needs it as a provider because
|
|
@@ -3946,6 +4209,7 @@ function augmentLoggerModule(base, providers) {
|
|
|
3946
4209
|
LOGGER_PINO_INSTANCE_TOKEN,
|
|
3947
4210
|
LOGGER_DESTINATIONS_TOKEN,
|
|
3948
4211
|
LOGGER_REDACTOR_TOKEN,
|
|
4212
|
+
LOGGER_OBSERVABILITY_TOKEN,
|
|
3949
4213
|
LOG_CONTEXT_TOKEN,
|
|
3950
4214
|
exports.LogContextService,
|
|
3951
4215
|
exports.PinoLoggerService,
|
|
@@ -4545,7 +4809,9 @@ exports.PinoUnexpectedErrorSink = class PinoUnexpectedErrorSink {
|
|
|
4545
4809
|
RESERVED_LOG_KEYS.HTTP_UNEXPECTED_ERROR_DROPPED,
|
|
4546
4810
|
"PinoUnexpectedErrorSink",
|
|
4547
4811
|
cause,
|
|
4548
|
-
"An unexpected-error report could not be logged and was dropped."
|
|
4812
|
+
"An unexpected-error report could not be logged and was dropped.",
|
|
4813
|
+
0,
|
|
4814
|
+
(text) => this.logger.censorMessageText(text)
|
|
4549
4815
|
);
|
|
4550
4816
|
}
|
|
4551
4817
|
}
|
|
@@ -4654,6 +4920,7 @@ var LOG_KEYS_CONVENTION_REGEX = /^[A-Z][A-Z0-9_]+_[A-Z][A-Z0-9_]+(_[A-Z][A-Z0-9_
|
|
|
4654
4920
|
exports.DEFAULT_REDACT_PATHS = DEFAULT_REDACT_PATHS;
|
|
4655
4921
|
exports.InjectLogger = InjectLogger;
|
|
4656
4922
|
exports.LOGGER_DESTINATIONS_TOKEN = LOGGER_DESTINATIONS_TOKEN;
|
|
4923
|
+
exports.LOGGER_OBSERVABILITY_TOKEN = LOGGER_OBSERVABILITY_TOKEN;
|
|
4657
4924
|
exports.LOGGER_OPTIONS_TOKEN = LOGGER_OPTIONS_TOKEN;
|
|
4658
4925
|
exports.LOGGER_PINO_INSTANCE_TOKEN = LOGGER_PINO_INSTANCE_TOKEN;
|
|
4659
4926
|
exports.LOGGER_REDACTOR_TOKEN = LOGGER_REDACTOR_TOKEN;
|