@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.mjs
CHANGED
|
@@ -372,7 +372,7 @@ function validateCustomization(options) {
|
|
|
372
372
|
if (!isRecord2(serializers)) reject("serializers", "must be an object", serializers);
|
|
373
373
|
for (const serializer of Object.values(serializers)) {
|
|
374
374
|
if (typeof serializer !== "function") {
|
|
375
|
-
reject("serializers", "must map every serializer key to a function", serializer);
|
|
375
|
+
reject("serializers", "must map every serializer key to a function", serializer, true);
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
}
|
|
@@ -486,6 +486,7 @@ var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
|
|
|
486
486
|
var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
|
|
487
487
|
var LOGGER_DESTINATIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_DESTINATIONS");
|
|
488
488
|
var LOGGER_REDACTOR_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_REDACTOR");
|
|
489
|
+
var LOGGER_OBSERVABILITY_TOKEN = /* @__PURE__ */ Symbol.for("BYMAX_LOGGER_OBSERVABILITY");
|
|
489
490
|
var LOG_CONTEXT_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_LOG_CONTEXT");
|
|
490
491
|
|
|
491
492
|
// src/shared/constants/reserved-log-keys.constants.ts
|
|
@@ -508,6 +509,7 @@ var RESERVED_LOG_KEYS = Object.freeze({
|
|
|
508
509
|
METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION",
|
|
509
510
|
LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED",
|
|
510
511
|
LOGGER_DESTINATION_WRITE_FAILED: "LOGGER_DESTINATION_WRITE_FAILED",
|
|
512
|
+
LOGGER_DESTINATION_SHUTDOWN_FAILED: "LOGGER_DESTINATION_SHUTDOWN_FAILED",
|
|
511
513
|
LOGGER_ENTRY_TRUNCATED: "LOGGER_ENTRY_TRUNCATED",
|
|
512
514
|
LOGGER_REDACTION_FAILED: "LOGGER_REDACTION_FAILED",
|
|
513
515
|
LOGGER_OTEL_API_BROKEN: "LOGGER_OTEL_API_BROKEN"
|
|
@@ -544,20 +546,38 @@ function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
|
|
|
544
546
|
const whole = last >= 55296 && last <= 56319 ? head.slice(0, -1) : head;
|
|
545
547
|
return whole + TEXT_TRUNCATED;
|
|
546
548
|
}
|
|
549
|
+
function cutBytes(text, maxBytes) {
|
|
550
|
+
if (Buffer.byteLength(text, "utf-8") <= maxBytes) return text;
|
|
551
|
+
const markerBytes = Buffer.byteLength(TEXT_TRUNCATED, "utf-8");
|
|
552
|
+
const marked = maxBytes >= markerBytes;
|
|
553
|
+
const bytes = Buffer.from(text, "utf-8");
|
|
554
|
+
let end = Math.min(marked ? maxBytes - markerBytes : maxBytes, bytes.length);
|
|
555
|
+
while ((bytes.readUInt8(end) & 192) === 128) end -= 1;
|
|
556
|
+
return bytes.subarray(0, end).toString("utf-8") + (marked ? TEXT_TRUNCATED : "");
|
|
557
|
+
}
|
|
547
558
|
|
|
548
559
|
// src/server/utils/entry-text-finisher.util.ts
|
|
549
560
|
var ENTRY_TEXT_FINISHER = /* @__PURE__ */ Symbol("bymax.entryTextFinisher");
|
|
550
|
-
function
|
|
561
|
+
function createTextCensor(redact) {
|
|
551
562
|
return (key, text) => {
|
|
552
563
|
try {
|
|
553
564
|
const censored = Reflect.get(redact({ [key]: text }, true), key);
|
|
554
|
-
|
|
555
|
-
return limit === void 0 ? censored : cutText(censored, false, limit);
|
|
565
|
+
return typeof censored === "string" ? censored : "";
|
|
556
566
|
} catch {
|
|
557
567
|
return "";
|
|
558
568
|
}
|
|
559
569
|
};
|
|
560
570
|
}
|
|
571
|
+
function createEntryTextFinisher(redact, limit, onCut) {
|
|
572
|
+
const censor = createTextCensor(redact);
|
|
573
|
+
return (key, text, cut) => {
|
|
574
|
+
const censored = censor(key, text);
|
|
575
|
+
if (limit === void 0 || cut === void 0) return censored;
|
|
576
|
+
const cutOff = cutText(censored, false, limit);
|
|
577
|
+
if (cut.emitted && cutOff !== censored) onCut?.();
|
|
578
|
+
return cutOff;
|
|
579
|
+
};
|
|
580
|
+
}
|
|
561
581
|
|
|
562
582
|
// src/server/utils/escape-log-text.util.ts
|
|
563
583
|
var LINE_TERMINATORS = /* @__PURE__ */ new Set(["\r", "\n", "\x85", "\u2028", "\u2029"]);
|
|
@@ -579,6 +599,35 @@ function escapeControlCharacters(text) {
|
|
|
579
599
|
return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
|
|
580
600
|
}
|
|
581
601
|
|
|
602
|
+
// src/server/utils/fold-key.util.ts
|
|
603
|
+
var IGNORED = /[\s._\p{Cf}-]/gu;
|
|
604
|
+
var DOT_ABOVE = /\u0307/g;
|
|
605
|
+
var PLAIN = /^[\x21-\x7e]*$/;
|
|
606
|
+
var LOOKALIKES = new Map(
|
|
607
|
+
Object.entries({
|
|
608
|
+
a: "\u0430\u03B1",
|
|
609
|
+
c: "\u0441\u03F2",
|
|
610
|
+
d: "\u0501",
|
|
611
|
+
e: "\u0435",
|
|
612
|
+
i: "\u0456\u03B9",
|
|
613
|
+
j: "\u0458",
|
|
614
|
+
o: "\u043E\u03BF",
|
|
615
|
+
p: "\u0440\u03C1",
|
|
616
|
+
q: "\u051B",
|
|
617
|
+
s: "\u0455",
|
|
618
|
+
v: "\u03BD",
|
|
619
|
+
w: "\u051D",
|
|
620
|
+
x: "\u0445",
|
|
621
|
+
y: "\u0443"
|
|
622
|
+
}).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
|
|
623
|
+
);
|
|
624
|
+
function foldKey(key) {
|
|
625
|
+
if (PLAIN.test(key)) return key.replace(IGNORED, "").toLowerCase();
|
|
626
|
+
let folded = key.normalize("NFKC").replace(IGNORED, "").toLowerCase().replace(DOT_ABOVE, "");
|
|
627
|
+
for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
|
|
628
|
+
return folded;
|
|
629
|
+
}
|
|
630
|
+
|
|
582
631
|
// src/server/utils/is-plain-record.util.ts
|
|
583
632
|
function isPlainRecord(node) {
|
|
584
633
|
try {
|
|
@@ -588,6 +637,25 @@ function isPlainRecord(node) {
|
|
|
588
637
|
return false;
|
|
589
638
|
}
|
|
590
639
|
}
|
|
640
|
+
|
|
641
|
+
// src/server/utils/censor-stack-header.util.ts
|
|
642
|
+
var NAME_SEPARATOR = ": ";
|
|
643
|
+
function endsHeader(stack, message, from) {
|
|
644
|
+
const end = from + message.length;
|
|
645
|
+
return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
|
|
646
|
+
}
|
|
647
|
+
function censorStackHeader(stack, name, message, censored) {
|
|
648
|
+
if (message === "" || censored === message) return stack;
|
|
649
|
+
const separator = stack.indexOf(NAME_SEPARATOR);
|
|
650
|
+
if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
|
|
651
|
+
const from = separator + NAME_SEPARATOR.length;
|
|
652
|
+
if (endsHeader(stack, message, from)) {
|
|
653
|
+
return stack.slice(0, from) + censored + stack.slice(from + message.length);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
|
|
657
|
+
return name === "" ? censored : name + NAME_SEPARATOR + censored;
|
|
658
|
+
}
|
|
591
659
|
function isError(value) {
|
|
592
660
|
try {
|
|
593
661
|
return types.isNativeError(value) || value instanceof Error;
|
|
@@ -651,7 +719,8 @@ function sanitizeError(err, options) {
|
|
|
651
719
|
const maxCauseDepth = options?.maxCauseDepth ?? DEFAULT_MAX_CAUSE_DEPTH;
|
|
652
720
|
return toSanitizedError(err, /* @__PURE__ */ new WeakSet(), 0, {
|
|
653
721
|
maxDepth: maxCauseDepth,
|
|
654
|
-
ownFields: options?.ownFields ?? ALL_OWN_FIELDS
|
|
722
|
+
ownFields: options?.ownFields ?? ALL_OWN_FIELDS,
|
|
723
|
+
censorMessage: options?.censorMessage
|
|
655
724
|
});
|
|
656
725
|
}
|
|
657
726
|
function isErrorLike(value) {
|
|
@@ -668,17 +737,24 @@ function readsAsError(value) {
|
|
|
668
737
|
const candidate = value;
|
|
669
738
|
return typeof candidate.name === "string" && typeof candidate.message === "string";
|
|
670
739
|
}
|
|
740
|
+
function readScrubbedStack(value, name, message, result, walk2) {
|
|
741
|
+
const stack = readOptional(() => value.stack, result);
|
|
742
|
+
return stack === void 0 ? void 0 : scrubStack(stack, headerCensor(name, message, walk2.censorMessage));
|
|
743
|
+
}
|
|
671
744
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
672
745
|
try {
|
|
673
746
|
if (!readsAsError(value)) {
|
|
674
747
|
return { name: "UnknownError", message: cutText(String(value)) };
|
|
675
748
|
}
|
|
676
749
|
seen.add(value);
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
750
|
+
const message = value.message;
|
|
751
|
+
const name = cutText(value.name);
|
|
752
|
+
const result = {
|
|
753
|
+
name: censorName(name, walk2.censorMessage),
|
|
754
|
+
message: cutText(message)
|
|
755
|
+
};
|
|
756
|
+
const stack = readScrubbedStack(value, name, message, result, walk2);
|
|
757
|
+
if (stack !== void 0) result.stack = stack;
|
|
682
758
|
const isAtDepthLimit = depth2 >= walk2.maxDepth;
|
|
683
759
|
const cause = readOptional(() => value.cause, result);
|
|
684
760
|
if (cause !== void 0) {
|
|
@@ -766,9 +842,39 @@ function readAggregatedErrors(value) {
|
|
|
766
842
|
return Array.isArray(candidate) ? candidate : void 0;
|
|
767
843
|
}
|
|
768
844
|
var MAX_STACK_SCAN = 8 * MAX_TEXT_LENGTH;
|
|
769
|
-
|
|
845
|
+
var MAX_PLAIN_NAME = 64;
|
|
846
|
+
var PLAIN_NAME = /^[A-Za-z_$][\w$.-]*$/;
|
|
847
|
+
function censorName(name, censorMessage) {
|
|
848
|
+
if (censorMessage === void 0 || name === "") return name;
|
|
849
|
+
if (name.length <= MAX_PLAIN_NAME && PLAIN_NAME.test(name)) return name;
|
|
850
|
+
try {
|
|
851
|
+
return censorMessage(name);
|
|
852
|
+
} catch {
|
|
853
|
+
return "";
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function headerCensor(name, message, censorMessage) {
|
|
857
|
+
if (typeof message !== "string" || censorMessage === void 0) return void 0;
|
|
858
|
+
const named = typeof name === "string" ? name : "";
|
|
859
|
+
const censoredName = censorName(named, censorMessage);
|
|
860
|
+
try {
|
|
861
|
+
return { name: named, censoredName, message, censored: censorMessage(message) };
|
|
862
|
+
} catch {
|
|
863
|
+
return { name: named, censoredName, message, censored: "" };
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function censorStackName(stack, header) {
|
|
867
|
+
return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
|
|
868
|
+
}
|
|
869
|
+
function scrubStack(stack, header) {
|
|
870
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
770
871
|
const scrubbed = escapeControlCharacters(
|
|
771
|
-
|
|
872
|
+
(header === void 0 ? head : censorStackHeader(
|
|
873
|
+
censorStackName(head, header),
|
|
874
|
+
header.censoredName,
|
|
875
|
+
header.message,
|
|
876
|
+
header.censored
|
|
877
|
+
)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
772
878
|
);
|
|
773
879
|
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
774
880
|
}
|
|
@@ -784,14 +890,21 @@ function createWidthMarker(omitted) {
|
|
|
784
890
|
|
|
785
891
|
// src/server/services/pino-logger.service.ts
|
|
786
892
|
var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
|
|
787
|
-
var ENTRY_STRUCTURE_KEYS =
|
|
788
|
-
|
|
789
|
-
"
|
|
790
|
-
"
|
|
791
|
-
"service",
|
|
792
|
-
"
|
|
793
|
-
|
|
794
|
-
|
|
893
|
+
var ENTRY_STRUCTURE_KEYS = ["level", "time", "msg", "service", "deployment"];
|
|
894
|
+
var RESOURCE_KEYS = [
|
|
895
|
+
"service.name",
|
|
896
|
+
"service.version",
|
|
897
|
+
"service.namespace",
|
|
898
|
+
"service.instance.id",
|
|
899
|
+
"deployment.environment.name"
|
|
900
|
+
];
|
|
901
|
+
var OWNED_KEY_SPELLINGS = new Set(
|
|
902
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
|
|
903
|
+
);
|
|
904
|
+
var isOwnedKey = (key) => {
|
|
905
|
+
const lower = key.toLowerCase();
|
|
906
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
907
|
+
};
|
|
795
908
|
function withoutOwnedKeys(metadata, omit) {
|
|
796
909
|
if (metadata === void 0) {
|
|
797
910
|
return {};
|
|
@@ -799,7 +912,7 @@ function withoutOwnedKeys(metadata, omit) {
|
|
|
799
912
|
try {
|
|
800
913
|
const safe = {};
|
|
801
914
|
for (const key of Object.keys(metadata)) {
|
|
802
|
-
if (key !== omit && !
|
|
915
|
+
if (key !== omit && !isOwnedKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
|
|
803
916
|
Reflect.set(safe, key, Reflect.get(metadata, key));
|
|
804
917
|
}
|
|
805
918
|
}
|
|
@@ -904,7 +1017,7 @@ var PinoLoggerService = class {
|
|
|
904
1017
|
if (isErrorLike(message)) {
|
|
905
1018
|
const payload2 = { err: message };
|
|
906
1019
|
assignIfDefined(payload2, "context", this.resolveContext(optionalParams));
|
|
907
|
-
this.pino.error(payload2,
|
|
1020
|
+
this.pino.error(payload2, this.errorText(message));
|
|
908
1021
|
return;
|
|
909
1022
|
}
|
|
910
1023
|
const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
|
|
@@ -913,7 +1026,7 @@ var PinoLoggerService = class {
|
|
|
913
1026
|
assignIfDefined(payload, "context", context);
|
|
914
1027
|
assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
|
|
915
1028
|
assignIfDefined(payload, "err", findErrorParam(optionalParams));
|
|
916
|
-
this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
|
|
1029
|
+
this.pino.error(payload, this.nestStyleMessage("error", void 0, fields, text, message));
|
|
917
1030
|
}
|
|
918
1031
|
/**
|
|
919
1032
|
* NestJS `warn` (warn level).
|
|
@@ -999,7 +1112,7 @@ var PinoLoggerService = class {
|
|
|
999
1112
|
};
|
|
1000
1113
|
assignIfDefined(payload, "userId", userId);
|
|
1001
1114
|
assignIfDefined(payload, "context", this.context);
|
|
1002
|
-
this.pino.error(payload,
|
|
1115
|
+
this.pino.error(payload, this.errorText(error));
|
|
1003
1116
|
}
|
|
1004
1117
|
// ─── Helpers / escape hatches ─────────────────────────────────────────────
|
|
1005
1118
|
/**
|
|
@@ -1065,30 +1178,57 @@ var PinoLoggerService = class {
|
|
|
1065
1178
|
}
|
|
1066
1179
|
}
|
|
1067
1180
|
/** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
|
|
1068
|
-
nestStyleMessage(leading, fields, text, message) {
|
|
1069
|
-
if (leading !== void 0) return
|
|
1070
|
-
if (fields !== void 0)
|
|
1181
|
+
nestStyleMessage(level, leading, fields, text, message) {
|
|
1182
|
+
if (leading !== void 0) return this.errorText(leading);
|
|
1183
|
+
if (fields !== void 0) {
|
|
1184
|
+
return toBoundedMessage(this.censorText(text, { emitted: this.pino.isLevelEnabled(level) }));
|
|
1185
|
+
}
|
|
1071
1186
|
return safeLogMessage(message);
|
|
1072
1187
|
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Censor a text as the `message` of an entry is: under the name `message`, by the rules of
|
|
1190
|
+
* `redactPaths` and `redactCensor`, and neither cut nor counted. The lines the library writes to
|
|
1191
|
+
* `stderr` about a failure use it for the message of the error they carry.
|
|
1192
|
+
*
|
|
1193
|
+
* @internal Used by `PinoUnexpectedErrorSink`. NOT part of the supported API.
|
|
1194
|
+
* @param text - The text to censor.
|
|
1195
|
+
* @returns The text, or what hides it, and an empty text when the censor itself fails.
|
|
1196
|
+
*/
|
|
1197
|
+
censorMessageText(text) {
|
|
1198
|
+
return this.censorText({ key: "message", text });
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* The entry text of an `Error`: its `message`, read without letting a hostile getter escape, then
|
|
1202
|
+
* censored under the name `message`, as the field `err.message` it is a copy of. It is not cut at
|
|
1203
|
+
* `maxStringLength`: the option does not apply to the log message, which is capped at 16384.
|
|
1204
|
+
*
|
|
1205
|
+
* @param error - The error being logged.
|
|
1206
|
+
* @returns The text of the entry.
|
|
1207
|
+
*/
|
|
1208
|
+
errorText(error) {
|
|
1209
|
+
return toBoundedMessage(this.censorText({ key: "message", text: safeErrorMessage(error) }));
|
|
1210
|
+
}
|
|
1073
1211
|
/**
|
|
1074
1212
|
* The entry text of an object message, censored under the names of the field it came from and cut
|
|
1075
1213
|
* like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
|
|
1076
1214
|
* value the pipeline censors or cuts in the field itself.
|
|
1077
1215
|
*
|
|
1078
1216
|
* @param text - The text and the member it came from.
|
|
1217
|
+
* @param cut - Present when the text is cut at `maxStringLength`; says whether the entry is
|
|
1218
|
+
* written, so that a cut of it is counted.
|
|
1079
1219
|
* @returns The censored text, or an empty one when the redactor cannot be applied.
|
|
1080
1220
|
*/
|
|
1081
|
-
censorText(text) {
|
|
1221
|
+
censorText(text, cut) {
|
|
1082
1222
|
if (text === void 0) return "";
|
|
1083
1223
|
const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
|
|
1084
|
-
return finish(text.key, text.text);
|
|
1224
|
+
return finish(text.key, text.text, cut);
|
|
1085
1225
|
}
|
|
1086
1226
|
emitNestStyle(level, message, optionalParams) {
|
|
1087
1227
|
const { fields, text, payload } = readObjectMessage(message);
|
|
1088
1228
|
assignIfDefined(payload, "context", this.resolveContext(optionalParams));
|
|
1089
1229
|
const leading = isErrorLike(message) ? message : void 0;
|
|
1090
1230
|
assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
|
|
1091
|
-
const msg = this.nestStyleMessage(leading, fields, text, message);
|
|
1231
|
+
const msg = this.nestStyleMessage(level, leading, fields, text, message);
|
|
1092
1232
|
switch (level) {
|
|
1093
1233
|
case "info":
|
|
1094
1234
|
this.pino.info(payload, msg);
|
|
@@ -2160,25 +2300,26 @@ var DEFAULT_REDACT_PATHS = [
|
|
|
2160
2300
|
];
|
|
2161
2301
|
|
|
2162
2302
|
// src/server/utils/report-destination-failure.util.ts
|
|
2163
|
-
function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0) {
|
|
2303
|
+
function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0, censorMessage) {
|
|
2164
2304
|
writeStderrSafely(
|
|
2165
2305
|
JSON.stringify({
|
|
2166
2306
|
level: "error",
|
|
2167
2307
|
logKey,
|
|
2168
2308
|
destination: toSingleLineMessage(name),
|
|
2169
|
-
err: describeCause(cause),
|
|
2309
|
+
err: describeCause(cause, censorMessage),
|
|
2170
2310
|
msg: toSingleLineMessage(msg),
|
|
2171
2311
|
...suppressed > 0 ? { suppressed } : {}
|
|
2172
2312
|
}) + "\n"
|
|
2173
2313
|
);
|
|
2174
2314
|
}
|
|
2175
2315
|
var UNREADABLE_CAUSE = { type: "UnknownError", message: "unreadable value" };
|
|
2176
|
-
function describeCause(cause) {
|
|
2316
|
+
function describeCause(cause, censorMessage) {
|
|
2317
|
+
const censor = censorMessage ?? ((text) => text);
|
|
2177
2318
|
try {
|
|
2178
2319
|
return isError(cause) ? {
|
|
2179
|
-
type: toBoundedMessage(String(cause.name)),
|
|
2180
|
-
message: toBoundedMessage(String(cause.message))
|
|
2181
|
-
} : { type: "UnknownError", message: toBoundedMessage(String(cause)) };
|
|
2320
|
+
type: toBoundedMessage(censorName(String(cause.name), censorMessage)),
|
|
2321
|
+
message: toBoundedMessage(censor(String(cause.message)))
|
|
2322
|
+
} : { type: "UnknownError", message: toBoundedMessage(censor(String(cause))) };
|
|
2182
2323
|
} catch {
|
|
2183
2324
|
return UNREADABLE_CAUSE;
|
|
2184
2325
|
}
|
|
@@ -2236,7 +2377,7 @@ function loadTraceApiFrom(anchor) {
|
|
|
2236
2377
|
return isOtelApiMissing(cause) ? { api: void 0 } : { api: void 0, broken: { cause } };
|
|
2237
2378
|
}
|
|
2238
2379
|
}
|
|
2239
|
-
function warnBrokenInstallOnce(cause) {
|
|
2380
|
+
function warnBrokenInstallOnce(cause, censorMessage) {
|
|
2240
2381
|
if (brokenInstallWarned) {
|
|
2241
2382
|
return;
|
|
2242
2383
|
}
|
|
@@ -2246,7 +2387,7 @@ function warnBrokenInstallOnce(cause) {
|
|
|
2246
2387
|
level: "warn",
|
|
2247
2388
|
logKey: RESERVED_LOG_KEYS.LOGGER_OTEL_API_BROKEN,
|
|
2248
2389
|
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.",
|
|
2249
|
-
err: describeCause(cause)
|
|
2390
|
+
err: describeCause(cause, censorMessage)
|
|
2250
2391
|
}) + "\n"
|
|
2251
2392
|
);
|
|
2252
2393
|
}
|
|
@@ -2254,7 +2395,7 @@ var DEFAULT_ANCHORS = [
|
|
|
2254
2395
|
() => __filename$1,
|
|
2255
2396
|
() => join(process.cwd(), "noop.cjs")
|
|
2256
2397
|
];
|
|
2257
|
-
function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
|
|
2398
|
+
function detectOtelTraceApi(anchors = DEFAULT_ANCHORS, censorMessage) {
|
|
2258
2399
|
let broken;
|
|
2259
2400
|
for (const anchor of anchors) {
|
|
2260
2401
|
const attempt = loadTraceApiFrom(anchor);
|
|
@@ -2264,7 +2405,7 @@ function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
|
|
|
2264
2405
|
broken ??= attempt.broken;
|
|
2265
2406
|
}
|
|
2266
2407
|
if (broken !== void 0) {
|
|
2267
|
-
warnBrokenInstallOnce(broken.cause);
|
|
2408
|
+
warnBrokenInstallOnce(broken.cause, censorMessage);
|
|
2268
2409
|
}
|
|
2269
2410
|
return void 0;
|
|
2270
2411
|
}
|
|
@@ -2277,7 +2418,7 @@ function isValidSpanId(spanId) {
|
|
|
2277
2418
|
|
|
2278
2419
|
// src/server/mixins/trace-context.mixin.ts
|
|
2279
2420
|
function createTraceContextMixin(logContext, opts) {
|
|
2280
|
-
const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi() : void 0;
|
|
2421
|
+
const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi(void 0, opts.censorMessage) : void 0;
|
|
2281
2422
|
return function mixin(_mergeObject, _level, _logger) {
|
|
2282
2423
|
const merged = {};
|
|
2283
2424
|
const store = logContext.getStore();
|
|
@@ -2299,7 +2440,7 @@ function createTraceContextMixin(logContext, opts) {
|
|
|
2299
2440
|
}
|
|
2300
2441
|
}
|
|
2301
2442
|
} catch (cause) {
|
|
2302
|
-
warnBrokenInstallOnce(cause);
|
|
2443
|
+
warnBrokenInstallOnce(cause, opts.censorMessage);
|
|
2303
2444
|
}
|
|
2304
2445
|
}
|
|
2305
2446
|
return merged;
|
|
@@ -2313,34 +2454,45 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
|
|
|
2313
2454
|
}
|
|
2314
2455
|
|
|
2315
2456
|
// src/server/utils/cut-strings.util.ts
|
|
2316
|
-
function cutNode(node, limit) {
|
|
2317
|
-
if (typeof node === "string")
|
|
2318
|
-
|
|
2457
|
+
function cutNode(node, limit, onCut) {
|
|
2458
|
+
if (typeof node === "string") {
|
|
2459
|
+
const cut = cutText(node, false, limit);
|
|
2460
|
+
if (cut !== node) onCut?.();
|
|
2461
|
+
return cut;
|
|
2462
|
+
}
|
|
2463
|
+
if (Array.isArray(node)) return node.map((child) => cutNode(child, limit, onCut));
|
|
2319
2464
|
if (isPlainRecord(node)) {
|
|
2320
2465
|
return Object.fromEntries(
|
|
2321
|
-
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
|
|
2466
|
+
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit, onCut)])
|
|
2322
2467
|
);
|
|
2323
2468
|
}
|
|
2324
2469
|
return node;
|
|
2325
2470
|
}
|
|
2326
|
-
function cutStrings(record, limit, exempt) {
|
|
2471
|
+
function cutStrings(record, limit, exempt, onCut) {
|
|
2327
2472
|
return Object.fromEntries(
|
|
2328
2473
|
Object.entries(record).map(([key, child]) => [
|
|
2329
2474
|
key,
|
|
2330
|
-
exempt.has(key) ? child : cutNode(child, limit)
|
|
2475
|
+
exempt.has(key) ? child : cutNode(child, limit, onCut)
|
|
2331
2476
|
])
|
|
2332
2477
|
);
|
|
2333
2478
|
}
|
|
2334
|
-
function reportWriteFailure(destination, cause, due) {
|
|
2479
|
+
function reportWriteFailure(destination, cause, due, censorMessage) {
|
|
2335
2480
|
const name = safeDestinationName(destination);
|
|
2336
2481
|
reportDestinationFailure(
|
|
2337
2482
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_WRITE_FAILED,
|
|
2338
2483
|
name,
|
|
2339
2484
|
cause,
|
|
2340
|
-
|
|
2341
|
-
due - 1
|
|
2485
|
+
"A log destination failed to write; the entry was dropped",
|
|
2486
|
+
due - 1,
|
|
2487
|
+
censorMessage
|
|
2342
2488
|
);
|
|
2343
2489
|
}
|
|
2490
|
+
function recordWriteFailure(destination, health, cause, censorMessage) {
|
|
2491
|
+
const due = health.recordWriteFailure(destination, performance.now());
|
|
2492
|
+
if (due !== void 0) {
|
|
2493
|
+
reportWriteFailure(destination, cause, due, censorMessage);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2344
2496
|
function rescueToStdout(payload) {
|
|
2345
2497
|
writeStdoutSafely(payload);
|
|
2346
2498
|
}
|
|
@@ -2414,7 +2566,7 @@ var BoundedWritable = class extends Writable {
|
|
|
2414
2566
|
);
|
|
2415
2567
|
}
|
|
2416
2568
|
};
|
|
2417
|
-
function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
2569
|
+
function destinationToStream(destination, health, maxQueueBytes = 0, censorMessage) {
|
|
2418
2570
|
const queue = { bytes: 0 };
|
|
2419
2571
|
const stream = new BoundedWritable(destination, health, maxQueueBytes, queue, {
|
|
2420
2572
|
// Keep string chunks as strings (Node's default re-encodes them to Buffers
|
|
@@ -2429,10 +2581,7 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
|
2429
2581
|
settled(error);
|
|
2430
2582
|
};
|
|
2431
2583
|
const onFailure = (cause) => {
|
|
2432
|
-
|
|
2433
|
-
if (due !== void 0) {
|
|
2434
|
-
reportWriteFailure(destination, cause, due);
|
|
2435
|
-
}
|
|
2584
|
+
recordWriteFailure(destination, health, cause, censorMessage);
|
|
2436
2585
|
callback();
|
|
2437
2586
|
};
|
|
2438
2587
|
try {
|
|
@@ -2474,8 +2623,14 @@ var EXPLICIT_USER_KEY = "userId";
|
|
|
2474
2623
|
function mergeMixinSafely(mergeObject, mixinObject) {
|
|
2475
2624
|
try {
|
|
2476
2625
|
const merged = {};
|
|
2626
|
+
const written = /* @__PURE__ */ new Set();
|
|
2627
|
+
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2628
|
+
if (value !== void 0) written.add(foldKey(key));
|
|
2629
|
+
}
|
|
2477
2630
|
for (const key of Object.keys(mergeObject)) {
|
|
2478
|
-
if (key
|
|
2631
|
+
if (key === PROTOTYPE_KEY) continue;
|
|
2632
|
+
if (key !== EXPLICIT_USER_KEY && written.has(foldKey(key))) continue;
|
|
2633
|
+
Reflect.set(merged, key, Reflect.get(mergeObject, key));
|
|
2479
2634
|
}
|
|
2480
2635
|
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2481
2636
|
if (value === void 0) continue;
|
|
@@ -2749,11 +2904,11 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
2749
2904
|
defineOwn(
|
|
2750
2905
|
copy,
|
|
2751
2906
|
key,
|
|
2752
|
-
rules.sensitive.has(key.toLowerCase()) ? rules.censor : censorHeaderArray(
|
|
2907
|
+
rules.sensitive.has(key.toLowerCase()) && !rules.exemptKeys?.has(key.toLowerCase()) ? rules.censor : censorHeaderArray(
|
|
2753
2908
|
key,
|
|
2754
2909
|
walk(
|
|
2755
2910
|
scrubbed && ERROR_TEXT_FIELDS.has(key) ? cutIfText(current) : current,
|
|
2756
|
-
rules,
|
|
2911
|
+
rulesBelow(rules, key, current, honorToJson),
|
|
2757
2912
|
depth2 + 1,
|
|
2758
2913
|
ancestors,
|
|
2759
2914
|
true,
|
|
@@ -2769,6 +2924,16 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
2769
2924
|
}
|
|
2770
2925
|
return copy;
|
|
2771
2926
|
}
|
|
2927
|
+
function leavesErrorText(rules, key, value, honorToJson) {
|
|
2928
|
+
return rules.errorTextToSerializer && !honorToJson && key === "err" && !isError(value) && isErrorLike(value);
|
|
2929
|
+
}
|
|
2930
|
+
function rulesBelow(rules, key, value, honorToJson) {
|
|
2931
|
+
if (leavesErrorText(rules, key, value, honorToJson)) {
|
|
2932
|
+
return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
|
|
2933
|
+
}
|
|
2934
|
+
return rules.exemptKeys === void 0 ? rules : { ...rules, exemptKeys: void 0 };
|
|
2935
|
+
}
|
|
2936
|
+
var ERROR_TEXT_KEYS = /* @__PURE__ */ new Set(["message"]);
|
|
2772
2937
|
function without(keys, omitted) {
|
|
2773
2938
|
return keys.filter((key) => !omitted.has(key));
|
|
2774
2939
|
}
|
|
@@ -2789,13 +2954,14 @@ function errorPartsHost(rules, ancestors, inSerialized) {
|
|
|
2789
2954
|
hasToJson: (value) => !rules.ownFields.safe && resolveToJson(value).method !== void 0
|
|
2790
2955
|
};
|
|
2791
2956
|
}
|
|
2792
|
-
function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames) {
|
|
2957
|
+
function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames, headerNames, errorTextToSerializer = false) {
|
|
2793
2958
|
const rules = {
|
|
2794
2959
|
sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
|
|
2795
2960
|
headerNames: new Set(Array.from(headerNames ?? fieldNames, (name) => name.toLowerCase())),
|
|
2796
2961
|
censor,
|
|
2797
2962
|
serializedKeys: new Set(serializedKeys),
|
|
2798
2963
|
errorsAsData: serializedKeys !== void 0,
|
|
2964
|
+
errorTextToSerializer,
|
|
2799
2965
|
maxVisits,
|
|
2800
2966
|
ownFields
|
|
2801
2967
|
};
|
|
@@ -2939,6 +3105,48 @@ function extraServiceFields(service) {
|
|
|
2939
3105
|
return extras;
|
|
2940
3106
|
}
|
|
2941
3107
|
|
|
3108
|
+
// src/server/utils/semconv-exception.util.ts
|
|
3109
|
+
function deriveExceptionFields(record, maxBytes, onCut, censorMessage, redactStack) {
|
|
3110
|
+
const bounded = (text) => {
|
|
3111
|
+
const cut = cutBytes(text, maxBytes);
|
|
3112
|
+
if (cut !== text) onCut?.();
|
|
3113
|
+
return cut;
|
|
3114
|
+
};
|
|
3115
|
+
const candidate = record["err"];
|
|
3116
|
+
if (typeof candidate?.name === "string") {
|
|
3117
|
+
const type = bounded(censorName(cutText(candidate.name), censorMessage));
|
|
3118
|
+
record["exception.type"] = type;
|
|
3119
|
+
record["error.type"] = type;
|
|
3120
|
+
}
|
|
3121
|
+
const message = candidate?.message;
|
|
3122
|
+
const header = headerCensor(candidate?.name, message, censorMessage);
|
|
3123
|
+
if (header !== void 0) {
|
|
3124
|
+
record["exception.message"] = bounded(cutText(header.censored));
|
|
3125
|
+
}
|
|
3126
|
+
if (typeof candidate?.name === "string" && typeof message === "string" && typeof candidate.stack === "string") {
|
|
3127
|
+
record["exception.stacktrace"] = bounded(redactStack(scrubStack(candidate.stack, header)));
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
function withSemconvException(record, format, maxBytes = Number.POSITIVE_INFINITY, onCut, censorMessage = (text) => text, redactStack = (stack) => stack) {
|
|
3131
|
+
if (format === "pino") {
|
|
3132
|
+
return record;
|
|
3133
|
+
}
|
|
3134
|
+
try {
|
|
3135
|
+
deriveExceptionFields(record, maxBytes, onCut, censorMessage, redactStack);
|
|
3136
|
+
if (format === "semconv") {
|
|
3137
|
+
const withoutErr = {};
|
|
3138
|
+
for (const [key, value] of Object.entries(record)) {
|
|
3139
|
+
if (key !== "err") {
|
|
3140
|
+
Reflect.set(withoutErr, key, value);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
return withoutErr;
|
|
3144
|
+
}
|
|
3145
|
+
} catch {
|
|
3146
|
+
}
|
|
3147
|
+
return record;
|
|
3148
|
+
}
|
|
3149
|
+
|
|
2942
3150
|
// src/server/utils/serialize-request.util.ts
|
|
2943
3151
|
function isObject2(value) {
|
|
2944
3152
|
return typeof value === "object" && value !== null;
|
|
@@ -2974,20 +3182,34 @@ function withSerializedRequest(record, secretSegments = []) {
|
|
|
2974
3182
|
|
|
2975
3183
|
// src/server/utils/truncate-large-entries.ts
|
|
2976
3184
|
var PREVIEW_LENGTH = 200;
|
|
2977
|
-
function
|
|
3185
|
+
function measurableJson(value) {
|
|
3186
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
3187
|
+
return JSON.stringify(value, function(_key, inner) {
|
|
3188
|
+
if (typeof inner === "bigint") return inner.toString();
|
|
3189
|
+
if (typeof inner !== "object" || inner === null) return inner;
|
|
3190
|
+
for (let holder = this; holder !== void 0; holder = parents.get(holder)) {
|
|
3191
|
+
if (holder === inner) return "[Circular]";
|
|
3192
|
+
}
|
|
3193
|
+
parents.set(inner, this);
|
|
3194
|
+
return inner;
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
function createSizeBoundedSerializer(baseSerializer, maxBytes, onTruncate) {
|
|
2978
3198
|
return (input) => {
|
|
2979
3199
|
const serialized = baseSerializer(input);
|
|
2980
3200
|
let json;
|
|
2981
3201
|
try {
|
|
2982
|
-
json =
|
|
3202
|
+
json = measurableJson(serialized);
|
|
2983
3203
|
} catch {
|
|
2984
|
-
|
|
3204
|
+
onTruncate?.();
|
|
3205
|
+
return unmeasurableEnvelope();
|
|
2985
3206
|
}
|
|
2986
3207
|
if (json === void 0) {
|
|
2987
3208
|
return serialized;
|
|
2988
3209
|
}
|
|
2989
3210
|
const byteSize = Buffer.byteLength(json, "utf-8");
|
|
2990
3211
|
if (byteSize > maxBytes) {
|
|
3212
|
+
onTruncate?.();
|
|
2991
3213
|
return {
|
|
2992
3214
|
_truncated: true,
|
|
2993
3215
|
_logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
|
|
@@ -2998,6 +3220,14 @@ function createSizeBoundedSerializer(baseSerializer, maxBytes) {
|
|
|
2998
3220
|
return serialized;
|
|
2999
3221
|
};
|
|
3000
3222
|
}
|
|
3223
|
+
function unmeasurableEnvelope() {
|
|
3224
|
+
return {
|
|
3225
|
+
_truncated: true,
|
|
3226
|
+
_logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
|
|
3227
|
+
_originalSize: -1,
|
|
3228
|
+
_preview: ""
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
3001
3231
|
|
|
3002
3232
|
// src/server/pino-factory.ts
|
|
3003
3233
|
var PATH_SEGMENT = /\[\s*['"]([^'"]+)['"]\s*\]|([^.[\]]+)/g;
|
|
@@ -3013,8 +3243,8 @@ function leafNameOf(path2) {
|
|
|
3013
3243
|
}
|
|
3014
3244
|
return leaf;
|
|
3015
3245
|
}
|
|
3016
|
-
function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
|
|
3017
|
-
const sanitized = sanitizeError(value_, { ownFields });
|
|
3246
|
+
function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS, censorMessage) {
|
|
3247
|
+
const sanitized = sanitizeError(value_, { ownFields, censorMessage });
|
|
3018
3248
|
const serialized = {
|
|
3019
3249
|
// `type` rather than `name`: the field consumers already query.
|
|
3020
3250
|
type: sanitized.name,
|
|
@@ -3032,35 +3262,6 @@ function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
|
|
|
3032
3262
|
assignOwnErrorFields(serialized, sanitized);
|
|
3033
3263
|
return serialized;
|
|
3034
3264
|
}
|
|
3035
|
-
function withSemconvException(record, format) {
|
|
3036
|
-
if (format === "pino") {
|
|
3037
|
-
return record;
|
|
3038
|
-
}
|
|
3039
|
-
try {
|
|
3040
|
-
const candidate = record["err"];
|
|
3041
|
-
if (typeof candidate?.name === "string") {
|
|
3042
|
-
record["exception.type"] = cutText(candidate.name);
|
|
3043
|
-
record["error.type"] = cutText(candidate.name);
|
|
3044
|
-
}
|
|
3045
|
-
if (typeof candidate?.message === "string") {
|
|
3046
|
-
record["exception.message"] = cutText(candidate.message);
|
|
3047
|
-
}
|
|
3048
|
-
if (typeof candidate?.stack === "string") {
|
|
3049
|
-
record["exception.stacktrace"] = scrubStack(candidate.stack);
|
|
3050
|
-
}
|
|
3051
|
-
if (format === "semconv") {
|
|
3052
|
-
const withoutErr = {};
|
|
3053
|
-
for (const [key, value] of Object.entries(record)) {
|
|
3054
|
-
if (key !== "err") {
|
|
3055
|
-
Reflect.set(withoutErr, key, value);
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
return withoutErr;
|
|
3059
|
-
}
|
|
3060
|
-
} catch {
|
|
3061
|
-
}
|
|
3062
|
-
return record;
|
|
3063
|
-
}
|
|
3064
3265
|
function toEventName(logKey) {
|
|
3065
3266
|
return logKey.toLowerCase().replaceAll("_", ".");
|
|
3066
3267
|
}
|
|
@@ -3113,7 +3314,8 @@ function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = tr
|
|
|
3113
3314
|
void 0,
|
|
3114
3315
|
ownFields,
|
|
3115
3316
|
coversNames ? void 0 : namesInsideErrors(options),
|
|
3116
|
-
allNames
|
|
3317
|
+
allNames,
|
|
3318
|
+
!Object.hasOwn(options.serializers, "err")
|
|
3117
3319
|
) : createNameRedactor(
|
|
3118
3320
|
names,
|
|
3119
3321
|
options.redactCensor,
|
|
@@ -3131,11 +3333,16 @@ function resolveRedactOption(options) {
|
|
|
3131
3333
|
}
|
|
3132
3334
|
return { paths, censor: options.redactCensor };
|
|
3133
3335
|
}
|
|
3134
|
-
function buildSerializers(options, redactSerialized, ownFields) {
|
|
3336
|
+
function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
|
|
3135
3337
|
const maxBytes = options.maxEntrySizeBytes;
|
|
3136
|
-
const
|
|
3338
|
+
const censorMessage = buildMessageCensor(options);
|
|
3339
|
+
const bound = (serializer) => createSizeBoundedSerializer(
|
|
3340
|
+
(input) => redactSerialized(serializer(input)),
|
|
3341
|
+
maxBytes,
|
|
3342
|
+
() => onTruncate("max_entry_size")
|
|
3343
|
+
);
|
|
3137
3344
|
return {
|
|
3138
|
-
err: bound((error) => serializeErrorValue(error, ownFields)),
|
|
3345
|
+
err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
|
|
3139
3346
|
...Object.fromEntries(
|
|
3140
3347
|
Object.entries(options.serializers).map(
|
|
3141
3348
|
([key, serializer]) => [key, bound(serializer)]
|
|
@@ -3143,14 +3350,35 @@ function buildSerializers(options, redactSerialized, ownFields) {
|
|
|
3143
3350
|
)
|
|
3144
3351
|
};
|
|
3145
3352
|
}
|
|
3146
|
-
function
|
|
3353
|
+
function buildMessageCensor(options) {
|
|
3354
|
+
const censor = createTextCensor(buildNameRedactor(options));
|
|
3355
|
+
return (text) => censor("message", text);
|
|
3356
|
+
}
|
|
3357
|
+
function withEntryTextFinisher(logger, options, onTruncate) {
|
|
3147
3358
|
const redact = buildNameRedactor(options);
|
|
3148
|
-
|
|
3359
|
+
const finisher = createEntryTextFinisher(
|
|
3360
|
+
redact,
|
|
3361
|
+
options.maxStringLength,
|
|
3362
|
+
() => onTruncate("max_string_length")
|
|
3363
|
+
);
|
|
3364
|
+
Reflect.set(logger, ENTRY_TEXT_FINISHER, finisher);
|
|
3149
3365
|
return logger;
|
|
3150
3366
|
}
|
|
3367
|
+
function buildTraceMixin(logContext, options) {
|
|
3368
|
+
return createTraceContextMixin(logContext, {
|
|
3369
|
+
...options.otel,
|
|
3370
|
+
censorMessage: buildMessageCensor(options)
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3151
3373
|
function buildStreams(options, destinations, health) {
|
|
3374
|
+
const censorMessage = buildMessageCensor(options);
|
|
3152
3375
|
return destinations.map((destination) => {
|
|
3153
|
-
const stream = destinationToStream(
|
|
3376
|
+
const stream = destinationToStream(
|
|
3377
|
+
destination,
|
|
3378
|
+
health,
|
|
3379
|
+
options.destinationQueue.maxBytes,
|
|
3380
|
+
censorMessage
|
|
3381
|
+
);
|
|
3154
3382
|
health.registerStream(destination, stream);
|
|
3155
3383
|
return {
|
|
3156
3384
|
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
@@ -3162,20 +3390,30 @@ function buildStreams(options, destinations, health) {
|
|
|
3162
3390
|
};
|
|
3163
3391
|
});
|
|
3164
3392
|
}
|
|
3165
|
-
function buildRecordFormatter(options, redactRecord) {
|
|
3393
|
+
function buildRecordFormatter(options, redactRecord, onTruncate) {
|
|
3166
3394
|
const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
|
|
3167
3395
|
const maxStringLength = options.maxStringLength;
|
|
3168
3396
|
const wholeRoots = wholeRootKeys(options);
|
|
3397
|
+
const censorMessage = buildMessageCensor(options);
|
|
3398
|
+
const redactSerialized = buildNameRedactor(options);
|
|
3399
|
+
const redactStack = (stack) => redactSerialized({ stack }).stack;
|
|
3169
3400
|
return (record) => {
|
|
3170
3401
|
const redacted = redactRecord(
|
|
3171
3402
|
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
3172
3403
|
true
|
|
3173
3404
|
);
|
|
3174
|
-
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
|
|
3175
|
-
return withSemconvException(
|
|
3405
|
+
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots, () => onTruncate("max_string_length"));
|
|
3406
|
+
return withSemconvException(
|
|
3407
|
+
withEventName(bounded, options.eventNameField),
|
|
3408
|
+
options.errorFormat,
|
|
3409
|
+
options.maxEntrySizeBytes,
|
|
3410
|
+
() => onTruncate("max_entry_size"),
|
|
3411
|
+
censorMessage,
|
|
3412
|
+
redactStack
|
|
3413
|
+
);
|
|
3176
3414
|
};
|
|
3177
3415
|
}
|
|
3178
|
-
function buildFormatters(options, redactRecord, redactBindings) {
|
|
3416
|
+
function buildFormatters(options, redactRecord, redactBindings, onTruncate) {
|
|
3179
3417
|
return {
|
|
3180
3418
|
// Emit the level as a string label instead of the numeric code — easier
|
|
3181
3419
|
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
@@ -3196,7 +3434,7 @@ function buildFormatters(options, redactRecord, redactBindings) {
|
|
|
3196
3434
|
// `base` and child bindings are NOT visible at this hook — they are
|
|
3197
3435
|
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
3198
3436
|
// sensitive, which `pino-factory.spec.ts` pins.
|
|
3199
|
-
log: buildRecordFormatter(options, redactRecord)
|
|
3437
|
+
log: buildRecordFormatter(options, redactRecord, onTruncate)
|
|
3200
3438
|
};
|
|
3201
3439
|
}
|
|
3202
3440
|
function buildPinoInstance(options, logContext, destinations, health) {
|
|
@@ -3207,6 +3445,7 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3207
3445
|
const redactSerialized = buildNameRedactor(options);
|
|
3208
3446
|
const ownFields = ownFieldPolicyOf(options);
|
|
3209
3447
|
const redactOption = resolveRedactOption(options);
|
|
3448
|
+
const onTruncate = (reason) => health.recordTruncation(reason);
|
|
3210
3449
|
const pinoOptions = {
|
|
3211
3450
|
level: options.level,
|
|
3212
3451
|
...redactOption === void 0 ? {} : { redact: redactOption },
|
|
@@ -3223,13 +3462,13 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3223
3462
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
3224
3463
|
// neither break the line nor add fields to it.
|
|
3225
3464
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
3226
|
-
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
|
|
3227
|
-
serializers: buildSerializers(options, redactSerialized, ownFields),
|
|
3228
|
-
mixin:
|
|
3465
|
+
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options), onTruncate),
|
|
3466
|
+
serializers: buildSerializers(options, redactSerialized, ownFields, onTruncate),
|
|
3467
|
+
mixin: buildTraceMixin(logContext, options),
|
|
3229
3468
|
mixinMergeStrategy: mergeMixinSafely
|
|
3230
3469
|
};
|
|
3231
3470
|
const streams = pino.multistream(buildStreams(options, destinations, health));
|
|
3232
|
-
return withEntryTextFinisher(pino(pinoOptions, streams), options);
|
|
3471
|
+
return withEntryTextFinisher(pino(pinoOptions, streams), options, onTruncate);
|
|
3233
3472
|
}
|
|
3234
3473
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
3235
3474
|
function countInWindow(records, destination, now) {
|
|
@@ -3247,6 +3486,9 @@ function countInWindow(records, destination, now) {
|
|
|
3247
3486
|
}
|
|
3248
3487
|
var DestinationHealth = class {
|
|
3249
3488
|
constructor() {
|
|
3489
|
+
/** How many fields were cut or replaced for the entry-size ceiling, and for the string limit. */
|
|
3490
|
+
this.entrySizeTruncations = 0;
|
|
3491
|
+
this.stringLengthTruncations = 0;
|
|
3250
3492
|
/** Destinations whose `onInit()` rejected. Identity-keyed, not name-keyed. */
|
|
3251
3493
|
this.failed = /* @__PURE__ */ new Set();
|
|
3252
3494
|
/**
|
|
@@ -3345,6 +3587,34 @@ var DestinationHealth = class {
|
|
|
3345
3587
|
this.writeFailed.add(destination);
|
|
3346
3588
|
return countInWindow(this.writeFailures, destination, now);
|
|
3347
3589
|
}
|
|
3590
|
+
/**
|
|
3591
|
+
* Record one field cut or replaced for a size bound.
|
|
3592
|
+
*
|
|
3593
|
+
* @param reason - Which bound: the entry-size ceiling or the string limit.
|
|
3594
|
+
*/
|
|
3595
|
+
recordTruncation(reason) {
|
|
3596
|
+
if (reason === "max_entry_size") this.entrySizeTruncations += 1;
|
|
3597
|
+
else this.stringLengthTruncations += 1;
|
|
3598
|
+
}
|
|
3599
|
+
/** @inheritDoc */
|
|
3600
|
+
truncatedTotal(reason) {
|
|
3601
|
+
return reason === "max_entry_size" ? this.entrySizeTruncations : this.stringLengthTruncations;
|
|
3602
|
+
}
|
|
3603
|
+
/** @inheritDoc */
|
|
3604
|
+
destinationErrorTotal() {
|
|
3605
|
+
let total = 0;
|
|
3606
|
+
for (const count of this.writeFailures.values()) total += count.total;
|
|
3607
|
+
return total;
|
|
3608
|
+
}
|
|
3609
|
+
/** @inheritDoc */
|
|
3610
|
+
deliveryState() {
|
|
3611
|
+
return {
|
|
3612
|
+
destinations: this.healthy.size + this.failed.size,
|
|
3613
|
+
failedInit: this.failed.size,
|
|
3614
|
+
writeFailing: this.writeFailed.size,
|
|
3615
|
+
hasHealthySink: this.healthy.size > 0
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3348
3618
|
/**
|
|
3349
3619
|
* How many writes a destination has refused since startup.
|
|
3350
3620
|
*
|
|
@@ -3546,6 +3816,7 @@ var DestinationRegistry = class {
|
|
|
3546
3816
|
* `onInit` runs and cannot be rebuilt afterwards; see `DestinationHealth`.
|
|
3547
3817
|
*/
|
|
3548
3818
|
this.active = [];
|
|
3819
|
+
this.censorMessage = buildMessageCensor(options);
|
|
3549
3820
|
}
|
|
3550
3821
|
/**
|
|
3551
3822
|
* Initialize every registered destination. A destination whose `onInit`
|
|
@@ -3647,12 +3918,13 @@ var DestinationRegistry = class {
|
|
|
3647
3918
|
* @param cause - The thrown or rejected value.
|
|
3648
3919
|
*/
|
|
3649
3920
|
reportInitFailure(destination, cause) {
|
|
3650
|
-
const name = safeDestinationName(destination);
|
|
3651
3921
|
reportDestinationFailure(
|
|
3652
3922
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
|
|
3653
|
-
|
|
3923
|
+
safeDestinationName(destination),
|
|
3654
3924
|
cause,
|
|
3655
|
-
|
|
3925
|
+
"A log destination failed to initialize and will receive no entries. If no destination initializes, entries fall back to raw NDJSON on stdout.",
|
|
3926
|
+
0,
|
|
3927
|
+
this.censorMessage
|
|
3656
3928
|
);
|
|
3657
3929
|
}
|
|
3658
3930
|
/**
|
|
@@ -3671,12 +3943,13 @@ var DestinationRegistry = class {
|
|
|
3671
3943
|
*/
|
|
3672
3944
|
reportHookFailure(destination, cause) {
|
|
3673
3945
|
const stillActive = !this.health.isFailed(destination);
|
|
3674
|
-
const name = safeDestinationName(destination);
|
|
3675
3946
|
reportDestinationFailure(
|
|
3676
3947
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
|
|
3677
|
-
|
|
3948
|
+
safeDestinationName(destination),
|
|
3678
3949
|
cause,
|
|
3679
|
-
|
|
3950
|
+
"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."),
|
|
3951
|
+
0,
|
|
3952
|
+
this.censorMessage
|
|
3680
3953
|
);
|
|
3681
3954
|
}
|
|
3682
3955
|
/**
|
|
@@ -3706,7 +3979,7 @@ var DestinationRegistry = class {
|
|
|
3706
3979
|
}
|
|
3707
3980
|
);
|
|
3708
3981
|
}
|
|
3709
|
-
if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi() === void 0) {
|
|
3982
|
+
if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi(void 0, this.censorMessage) === void 0) {
|
|
3710
3983
|
this.logger.warnStructured(
|
|
3711
3984
|
RESERVED_LOG_KEYS.LOGGER_BOOTSTRAP_WARNING,
|
|
3712
3985
|
"Trace-context auto-injection is enabled but @opentelemetry/api could not be resolved \u2014 traceId and spanId will be absent from every entry",
|
|
@@ -3826,44 +4099,32 @@ var DestinationRegistry = class {
|
|
|
3826
4099
|
}
|
|
3827
4100
|
}
|
|
3828
4101
|
/**
|
|
3829
|
-
* Report a failing `onShutdown` on stderr
|
|
3830
|
-
* abort the teardown of the destinations still queued behind it.
|
|
3831
|
-
*
|
|
3832
|
-
* The coercion is INSIDE the guard, not above it. Reading `stack`/`message` on
|
|
3833
|
-
* an `Error` with hostile getters, and `String(cause)` on a value with a
|
|
3834
|
-
* throwing `toString`/`Symbol.toPrimitive`, both throw — and this runs inside
|
|
3835
|
-
* the `catch` that exists to keep one bad sink from mattering, so an escape
|
|
3836
|
-
* here would propagate out of `onApplicationShutdown` and skip every remaining
|
|
3837
|
-
* destination's flush. The never-throw contract has to cover READING the value,
|
|
3838
|
-
* not just writing it, which is the same correction `reportDestinationFailure`
|
|
3839
|
-
* already carries.
|
|
4102
|
+
* Report a failing `onShutdown` on stderr, as a structured line like the other stages, without
|
|
4103
|
+
* letting the report itself abort the teardown of the destinations still queued behind it.
|
|
3840
4104
|
*
|
|
3841
|
-
* The
|
|
3842
|
-
*
|
|
3843
|
-
*
|
|
4105
|
+
* The line is written by {@link reportDestinationFailure}, which holds every guard the report
|
|
4106
|
+
* needs: the cause is read inside a guard (a hostile getter or `toPrimitive` degrades the detail
|
|
4107
|
+
* and never the line), the text is escaped for a terminal, and the message of the error passes
|
|
4108
|
+
* the censor of the `message` of an entry. The error is a field (`err`) and never part of `msg`,
|
|
4109
|
+
* which is library text, and its stack is not written: a stack is text a host error carries
|
|
4110
|
+
* whole, and the type and the censored message identify the failure.
|
|
3844
4111
|
*
|
|
3845
|
-
* The DESTINATION is passed rather than its name, so that read happens
|
|
3846
|
-
*
|
|
3847
|
-
*
|
|
3848
|
-
* outside the guard — inside the `catch`, where a throw has the same cost.
|
|
3849
|
-
*
|
|
3850
|
-
* Two separate guards, not one: a name that cannot be read must not also cost
|
|
3851
|
-
* the failure detail, and a detail that cannot be read must not cost the name.
|
|
3852
|
-
* Either alone still identifies which sink failed.
|
|
4112
|
+
* The DESTINATION is passed rather than its name, so that read happens inside the guard too:
|
|
4113
|
+
* `name` is declared `readonly name: string` but nothing stops a consumer implementing it as a
|
|
4114
|
+
* getter, and reading it at the call site would put it back outside the guard.
|
|
3853
4115
|
*
|
|
3854
4116
|
* @param destination - The destination whose `onShutdown` threw.
|
|
3855
4117
|
* @param cause - The thrown value, of any shape.
|
|
3856
4118
|
*/
|
|
3857
4119
|
reportShutdownFailure(destination, cause) {
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
`);
|
|
4120
|
+
reportDestinationFailure(
|
|
4121
|
+
RESERVED_LOG_KEYS.LOGGER_DESTINATION_SHUTDOWN_FAILED,
|
|
4122
|
+
safeDestinationName(destination),
|
|
4123
|
+
cause,
|
|
4124
|
+
"A log destination failed to shut down; anything it was still holding is lost.",
|
|
4125
|
+
0,
|
|
4126
|
+
this.censorMessage
|
|
4127
|
+
);
|
|
3867
4128
|
}
|
|
3868
4129
|
/**
|
|
3869
4130
|
* The destinations that initialized successfully.
|
|
@@ -3894,6 +4155,8 @@ function buildCommonProviders() {
|
|
|
3894
4155
|
// and by DestinationRegistry (which writes to it during onModuleInit). Both
|
|
3895
4156
|
// depend on this provider and it depends on nothing, so there is no cycle.
|
|
3896
4157
|
DestinationHealth,
|
|
4158
|
+
// The counters and the delivery state of the logger, for the `/observability` subpath.
|
|
4159
|
+
{ provide: LOGGER_OBSERVABILITY_TOKEN, useExisting: DestinationHealth },
|
|
3897
4160
|
{
|
|
3898
4161
|
// The DEFAULT-coverage redactor, shared by the Pino factory's hooks and by
|
|
3899
4162
|
// `PinoLoggerService.child()`. The latter needs it as a provider because
|
|
@@ -3943,6 +4206,7 @@ function augmentLoggerModule(base, providers) {
|
|
|
3943
4206
|
LOGGER_PINO_INSTANCE_TOKEN,
|
|
3944
4207
|
LOGGER_DESTINATIONS_TOKEN,
|
|
3945
4208
|
LOGGER_REDACTOR_TOKEN,
|
|
4209
|
+
LOGGER_OBSERVABILITY_TOKEN,
|
|
3946
4210
|
LOG_CONTEXT_TOKEN,
|
|
3947
4211
|
LogContextService,
|
|
3948
4212
|
PinoLoggerService,
|
|
@@ -4542,7 +4806,9 @@ var PinoUnexpectedErrorSink = class {
|
|
|
4542
4806
|
RESERVED_LOG_KEYS.HTTP_UNEXPECTED_ERROR_DROPPED,
|
|
4543
4807
|
"PinoUnexpectedErrorSink",
|
|
4544
4808
|
cause,
|
|
4545
|
-
"An unexpected-error report could not be logged and was dropped."
|
|
4809
|
+
"An unexpected-error report could not be logged and was dropped.",
|
|
4810
|
+
0,
|
|
4811
|
+
(text) => this.logger.censorMessageText(text)
|
|
4546
4812
|
);
|
|
4547
4813
|
}
|
|
4548
4814
|
}
|
|
@@ -4648,4 +4914,4 @@ function LogPerformance(thresholdMs = DEFAULT_THRESHOLD_MS) {
|
|
|
4648
4914
|
// src/shared/constants/log-keys-convention.constants.ts
|
|
4649
4915
|
var LOG_KEYS_CONVENTION_REGEX = /^[A-Z][A-Z0-9_]+_[A-Z][A-Z0-9_]+(_[A-Z][A-Z0-9_]+)?$/;
|
|
4650
4916
|
|
|
4651
|
-
export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOGGER_REDACTOR_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, REDACT_COMMON_FIELDS, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware, isValidTraceId };
|
|
4917
|
+
export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OBSERVABILITY_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOGGER_REDACTOR_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, REDACT_COMMON_FIELDS, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware, isValidTraceId };
|