@bymax-one/nest-logger 1.4.23 → 1.4.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +154 -1
- package/README.md +90 -22
- package/dist/observability/index.cjs +112 -0
- package/dist/observability/index.d.cts +55 -0
- package/dist/observability/index.d.ts +55 -0
- package/dist/observability/index.mjs +110 -0
- package/dist/server/index.cjs +340 -144
- package/dist/server/index.d.cts +82 -4
- package/dist/server/index.d.ts +82 -4
- package/dist/server/index.mjs +340 -145
- 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,12 @@ 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 SEPARATORS = /[._-]/g;
|
|
604
|
+
function foldKey(key) {
|
|
605
|
+
return key.replace(SEPARATORS, "").toLowerCase();
|
|
606
|
+
}
|
|
607
|
+
|
|
582
608
|
// src/server/utils/is-plain-record.util.ts
|
|
583
609
|
function isPlainRecord(node) {
|
|
584
610
|
try {
|
|
@@ -588,6 +614,25 @@ function isPlainRecord(node) {
|
|
|
588
614
|
return false;
|
|
589
615
|
}
|
|
590
616
|
}
|
|
617
|
+
|
|
618
|
+
// src/server/utils/censor-stack-header.util.ts
|
|
619
|
+
var NAME_SEPARATOR = ": ";
|
|
620
|
+
function endsHeader(stack, message, from) {
|
|
621
|
+
const end = from + message.length;
|
|
622
|
+
return stack.startsWith(message, from) && (end === stack.length || stack.startsWith("\n", end));
|
|
623
|
+
}
|
|
624
|
+
function censorStackHeader(stack, name, message, censored) {
|
|
625
|
+
if (message === "" || censored === message) return stack;
|
|
626
|
+
const separator = stack.indexOf(NAME_SEPARATOR);
|
|
627
|
+
if (separator !== -1 && stack.lastIndexOf("\n", separator) === -1) {
|
|
628
|
+
const from = separator + NAME_SEPARATOR.length;
|
|
629
|
+
if (endsHeader(stack, message, from)) {
|
|
630
|
+
return stack.slice(0, from) + censored + stack.slice(from + message.length);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (endsHeader(stack, message, 0)) return censored + stack.slice(message.length);
|
|
634
|
+
return name === "" ? censored : name + NAME_SEPARATOR + censored;
|
|
635
|
+
}
|
|
591
636
|
function isError(value) {
|
|
592
637
|
try {
|
|
593
638
|
return types.isNativeError(value) || value instanceof Error;
|
|
@@ -651,7 +696,8 @@ function sanitizeError(err, options) {
|
|
|
651
696
|
const maxCauseDepth = options?.maxCauseDepth ?? DEFAULT_MAX_CAUSE_DEPTH;
|
|
652
697
|
return toSanitizedError(err, /* @__PURE__ */ new WeakSet(), 0, {
|
|
653
698
|
maxDepth: maxCauseDepth,
|
|
654
|
-
ownFields: options?.ownFields ?? ALL_OWN_FIELDS
|
|
699
|
+
ownFields: options?.ownFields ?? ALL_OWN_FIELDS,
|
|
700
|
+
censorMessage: options?.censorMessage
|
|
655
701
|
});
|
|
656
702
|
}
|
|
657
703
|
function isErrorLike(value) {
|
|
@@ -668,17 +714,20 @@ function readsAsError(value) {
|
|
|
668
714
|
const candidate = value;
|
|
669
715
|
return typeof candidate.name === "string" && typeof candidate.message === "string";
|
|
670
716
|
}
|
|
717
|
+
function readScrubbedStack(value, message, result, walk2) {
|
|
718
|
+
const stack = readOptional(() => value.stack, result);
|
|
719
|
+
return stack === void 0 ? void 0 : scrubStack(stack, headerCensor(result.name, message, walk2.censorMessage));
|
|
720
|
+
}
|
|
671
721
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
672
722
|
try {
|
|
673
723
|
if (!readsAsError(value)) {
|
|
674
724
|
return { name: "UnknownError", message: cutText(String(value)) };
|
|
675
725
|
}
|
|
676
726
|
seen.add(value);
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}
|
|
727
|
+
const message = value.message;
|
|
728
|
+
const result = { name: cutText(value.name), message: cutText(message) };
|
|
729
|
+
const stack = readScrubbedStack(value, message, result, walk2);
|
|
730
|
+
if (stack !== void 0) result.stack = stack;
|
|
682
731
|
const isAtDepthLimit = depth2 >= walk2.maxDepth;
|
|
683
732
|
const cause = readOptional(() => value.cause, result);
|
|
684
733
|
if (cause !== void 0) {
|
|
@@ -766,9 +815,19 @@ function readAggregatedErrors(value) {
|
|
|
766
815
|
return Array.isArray(candidate) ? candidate : void 0;
|
|
767
816
|
}
|
|
768
817
|
var MAX_STACK_SCAN = 8 * MAX_TEXT_LENGTH;
|
|
769
|
-
function
|
|
818
|
+
function headerCensor(name, message, censorMessage) {
|
|
819
|
+
if (typeof message !== "string" || censorMessage === void 0) return void 0;
|
|
820
|
+
const named = typeof name === "string" ? name : "";
|
|
821
|
+
try {
|
|
822
|
+
return { name: named, message, censored: censorMessage(message) };
|
|
823
|
+
} catch {
|
|
824
|
+
return { name: named, message, censored: "" };
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function scrubStack(stack, header) {
|
|
828
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
770
829
|
const scrubbed = escapeControlCharacters(
|
|
771
|
-
|
|
830
|
+
(header === void 0 ? head : censorStackHeader(head, header.name, header.message, header.censored)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
772
831
|
);
|
|
773
832
|
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
774
833
|
}
|
|
@@ -784,14 +843,14 @@ function createWidthMarker(omitted) {
|
|
|
784
843
|
|
|
785
844
|
// src/server/services/pino-logger.service.ts
|
|
786
845
|
var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
|
|
787
|
-
var ENTRY_STRUCTURE_KEYS =
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
846
|
+
var ENTRY_STRUCTURE_KEYS = ["level", "time", "msg", "service", "deployment"];
|
|
847
|
+
var OWNED_KEY_SPELLINGS = new Set(
|
|
848
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS].map(foldKey)
|
|
849
|
+
);
|
|
850
|
+
var isOwnedKey = (key) => {
|
|
851
|
+
const lower = key.toLowerCase();
|
|
852
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
853
|
+
};
|
|
795
854
|
function withoutOwnedKeys(metadata, omit) {
|
|
796
855
|
if (metadata === void 0) {
|
|
797
856
|
return {};
|
|
@@ -799,7 +858,7 @@ function withoutOwnedKeys(metadata, omit) {
|
|
|
799
858
|
try {
|
|
800
859
|
const safe = {};
|
|
801
860
|
for (const key of Object.keys(metadata)) {
|
|
802
|
-
if (key !== omit && !
|
|
861
|
+
if (key !== omit && !isOwnedKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
|
|
803
862
|
Reflect.set(safe, key, Reflect.get(metadata, key));
|
|
804
863
|
}
|
|
805
864
|
}
|
|
@@ -904,7 +963,7 @@ var PinoLoggerService = class {
|
|
|
904
963
|
if (isErrorLike(message)) {
|
|
905
964
|
const payload2 = { err: message };
|
|
906
965
|
assignIfDefined(payload2, "context", this.resolveContext(optionalParams));
|
|
907
|
-
this.pino.error(payload2,
|
|
966
|
+
this.pino.error(payload2, this.errorText(message));
|
|
908
967
|
return;
|
|
909
968
|
}
|
|
910
969
|
const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
|
|
@@ -913,7 +972,7 @@ var PinoLoggerService = class {
|
|
|
913
972
|
assignIfDefined(payload, "context", context);
|
|
914
973
|
assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
|
|
915
974
|
assignIfDefined(payload, "err", findErrorParam(optionalParams));
|
|
916
|
-
this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
|
|
975
|
+
this.pino.error(payload, this.nestStyleMessage("error", void 0, fields, text, message));
|
|
917
976
|
}
|
|
918
977
|
/**
|
|
919
978
|
* NestJS `warn` (warn level).
|
|
@@ -999,7 +1058,7 @@ var PinoLoggerService = class {
|
|
|
999
1058
|
};
|
|
1000
1059
|
assignIfDefined(payload, "userId", userId);
|
|
1001
1060
|
assignIfDefined(payload, "context", this.context);
|
|
1002
|
-
this.pino.error(payload,
|
|
1061
|
+
this.pino.error(payload, this.errorText(error));
|
|
1003
1062
|
}
|
|
1004
1063
|
// ─── Helpers / escape hatches ─────────────────────────────────────────────
|
|
1005
1064
|
/**
|
|
@@ -1065,30 +1124,57 @@ var PinoLoggerService = class {
|
|
|
1065
1124
|
}
|
|
1066
1125
|
}
|
|
1067
1126
|
/** 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)
|
|
1127
|
+
nestStyleMessage(level, leading, fields, text, message) {
|
|
1128
|
+
if (leading !== void 0) return this.errorText(leading);
|
|
1129
|
+
if (fields !== void 0) {
|
|
1130
|
+
return toBoundedMessage(this.censorText(text, { emitted: this.pino.isLevelEnabled(level) }));
|
|
1131
|
+
}
|
|
1071
1132
|
return safeLogMessage(message);
|
|
1072
1133
|
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Censor a text as the `message` of an entry is: under the name `message`, by the rules of
|
|
1136
|
+
* `redactPaths` and `redactCensor`, and neither cut nor counted. The lines the library writes to
|
|
1137
|
+
* `stderr` about a failure use it for the message of the error they carry.
|
|
1138
|
+
*
|
|
1139
|
+
* @internal Used by `PinoUnexpectedErrorSink`. NOT part of the supported API.
|
|
1140
|
+
* @param text - The text to censor.
|
|
1141
|
+
* @returns The text, or what hides it, and an empty text when the censor itself fails.
|
|
1142
|
+
*/
|
|
1143
|
+
censorMessageText(text) {
|
|
1144
|
+
return this.censorText({ key: "message", text });
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* The entry text of an `Error`: its `message`, read without letting a hostile getter escape, then
|
|
1148
|
+
* censored under the name `message`, as the field `err.message` it is a copy of. It is not cut at
|
|
1149
|
+
* `maxStringLength`: the option does not apply to the log message, which is capped at 16384.
|
|
1150
|
+
*
|
|
1151
|
+
* @param error - The error being logged.
|
|
1152
|
+
* @returns The text of the entry.
|
|
1153
|
+
*/
|
|
1154
|
+
errorText(error) {
|
|
1155
|
+
return toBoundedMessage(this.censorText({ key: "message", text: safeErrorMessage(error) }));
|
|
1156
|
+
}
|
|
1073
1157
|
/**
|
|
1074
1158
|
* The entry text of an object message, censored under the names of the field it came from and cut
|
|
1075
1159
|
* like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
|
|
1076
1160
|
* value the pipeline censors or cuts in the field itself.
|
|
1077
1161
|
*
|
|
1078
1162
|
* @param text - The text and the member it came from.
|
|
1163
|
+
* @param cut - Present when the text is cut at `maxStringLength`; says whether the entry is
|
|
1164
|
+
* written, so that a cut of it is counted.
|
|
1079
1165
|
* @returns The censored text, or an empty one when the redactor cannot be applied.
|
|
1080
1166
|
*/
|
|
1081
|
-
censorText(text) {
|
|
1167
|
+
censorText(text, cut) {
|
|
1082
1168
|
if (text === void 0) return "";
|
|
1083
1169
|
const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
|
|
1084
|
-
return finish(text.key, text.text);
|
|
1170
|
+
return finish(text.key, text.text, cut);
|
|
1085
1171
|
}
|
|
1086
1172
|
emitNestStyle(level, message, optionalParams) {
|
|
1087
1173
|
const { fields, text, payload } = readObjectMessage(message);
|
|
1088
1174
|
assignIfDefined(payload, "context", this.resolveContext(optionalParams));
|
|
1089
1175
|
const leading = isErrorLike(message) ? message : void 0;
|
|
1090
1176
|
assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
|
|
1091
|
-
const msg = this.nestStyleMessage(leading, fields, text, message);
|
|
1177
|
+
const msg = this.nestStyleMessage(level, leading, fields, text, message);
|
|
1092
1178
|
switch (level) {
|
|
1093
1179
|
case "info":
|
|
1094
1180
|
this.pino.info(payload, msg);
|
|
@@ -2160,25 +2246,26 @@ var DEFAULT_REDACT_PATHS = [
|
|
|
2160
2246
|
];
|
|
2161
2247
|
|
|
2162
2248
|
// src/server/utils/report-destination-failure.util.ts
|
|
2163
|
-
function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0) {
|
|
2249
|
+
function reportDestinationFailure(logKey, name, cause, msg, suppressed = 0, censorMessage) {
|
|
2164
2250
|
writeStderrSafely(
|
|
2165
2251
|
JSON.stringify({
|
|
2166
2252
|
level: "error",
|
|
2167
2253
|
logKey,
|
|
2168
2254
|
destination: toSingleLineMessage(name),
|
|
2169
|
-
err: describeCause(cause),
|
|
2255
|
+
err: describeCause(cause, censorMessage),
|
|
2170
2256
|
msg: toSingleLineMessage(msg),
|
|
2171
2257
|
...suppressed > 0 ? { suppressed } : {}
|
|
2172
2258
|
}) + "\n"
|
|
2173
2259
|
);
|
|
2174
2260
|
}
|
|
2175
2261
|
var UNREADABLE_CAUSE = { type: "UnknownError", message: "unreadable value" };
|
|
2176
|
-
function describeCause(cause) {
|
|
2262
|
+
function describeCause(cause, censorMessage) {
|
|
2263
|
+
const censor = censorMessage ?? ((text) => text);
|
|
2177
2264
|
try {
|
|
2178
2265
|
return isError(cause) ? {
|
|
2179
2266
|
type: toBoundedMessage(String(cause.name)),
|
|
2180
|
-
message: toBoundedMessage(String(cause.message))
|
|
2181
|
-
} : { type: "UnknownError", message: toBoundedMessage(String(cause)) };
|
|
2267
|
+
message: toBoundedMessage(censor(String(cause.message)))
|
|
2268
|
+
} : { type: "UnknownError", message: toBoundedMessage(censor(String(cause))) };
|
|
2182
2269
|
} catch {
|
|
2183
2270
|
return UNREADABLE_CAUSE;
|
|
2184
2271
|
}
|
|
@@ -2236,7 +2323,7 @@ function loadTraceApiFrom(anchor) {
|
|
|
2236
2323
|
return isOtelApiMissing(cause) ? { api: void 0 } : { api: void 0, broken: { cause } };
|
|
2237
2324
|
}
|
|
2238
2325
|
}
|
|
2239
|
-
function warnBrokenInstallOnce(cause) {
|
|
2326
|
+
function warnBrokenInstallOnce(cause, censorMessage) {
|
|
2240
2327
|
if (brokenInstallWarned) {
|
|
2241
2328
|
return;
|
|
2242
2329
|
}
|
|
@@ -2246,7 +2333,7 @@ function warnBrokenInstallOnce(cause) {
|
|
|
2246
2333
|
level: "warn",
|
|
2247
2334
|
logKey: RESERVED_LOG_KEYS.LOGGER_OTEL_API_BROKEN,
|
|
2248
2335
|
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)
|
|
2336
|
+
err: describeCause(cause, censorMessage)
|
|
2250
2337
|
}) + "\n"
|
|
2251
2338
|
);
|
|
2252
2339
|
}
|
|
@@ -2254,7 +2341,7 @@ var DEFAULT_ANCHORS = [
|
|
|
2254
2341
|
() => __filename$1,
|
|
2255
2342
|
() => join(process.cwd(), "noop.cjs")
|
|
2256
2343
|
];
|
|
2257
|
-
function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
|
|
2344
|
+
function detectOtelTraceApi(anchors = DEFAULT_ANCHORS, censorMessage) {
|
|
2258
2345
|
let broken;
|
|
2259
2346
|
for (const anchor of anchors) {
|
|
2260
2347
|
const attempt = loadTraceApiFrom(anchor);
|
|
@@ -2264,7 +2351,7 @@ function detectOtelTraceApi(anchors = DEFAULT_ANCHORS) {
|
|
|
2264
2351
|
broken ??= attempt.broken;
|
|
2265
2352
|
}
|
|
2266
2353
|
if (broken !== void 0) {
|
|
2267
|
-
warnBrokenInstallOnce(broken.cause);
|
|
2354
|
+
warnBrokenInstallOnce(broken.cause, censorMessage);
|
|
2268
2355
|
}
|
|
2269
2356
|
return void 0;
|
|
2270
2357
|
}
|
|
@@ -2277,7 +2364,7 @@ function isValidSpanId(spanId) {
|
|
|
2277
2364
|
|
|
2278
2365
|
// src/server/mixins/trace-context.mixin.ts
|
|
2279
2366
|
function createTraceContextMixin(logContext, opts) {
|
|
2280
|
-
const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi() : void 0;
|
|
2367
|
+
const traceApi = opts.shouldAutoInjectTraceContext ? detectOtelTraceApi(void 0, opts.censorMessage) : void 0;
|
|
2281
2368
|
return function mixin(_mergeObject, _level, _logger) {
|
|
2282
2369
|
const merged = {};
|
|
2283
2370
|
const store = logContext.getStore();
|
|
@@ -2299,7 +2386,7 @@ function createTraceContextMixin(logContext, opts) {
|
|
|
2299
2386
|
}
|
|
2300
2387
|
}
|
|
2301
2388
|
} catch (cause) {
|
|
2302
|
-
warnBrokenInstallOnce(cause);
|
|
2389
|
+
warnBrokenInstallOnce(cause, opts.censorMessage);
|
|
2303
2390
|
}
|
|
2304
2391
|
}
|
|
2305
2392
|
return merged;
|
|
@@ -2313,34 +2400,45 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
|
|
|
2313
2400
|
}
|
|
2314
2401
|
|
|
2315
2402
|
// src/server/utils/cut-strings.util.ts
|
|
2316
|
-
function cutNode(node, limit) {
|
|
2317
|
-
if (typeof node === "string")
|
|
2318
|
-
|
|
2403
|
+
function cutNode(node, limit, onCut) {
|
|
2404
|
+
if (typeof node === "string") {
|
|
2405
|
+
const cut = cutText(node, false, limit);
|
|
2406
|
+
if (cut !== node) onCut?.();
|
|
2407
|
+
return cut;
|
|
2408
|
+
}
|
|
2409
|
+
if (Array.isArray(node)) return node.map((child) => cutNode(child, limit, onCut));
|
|
2319
2410
|
if (isPlainRecord(node)) {
|
|
2320
2411
|
return Object.fromEntries(
|
|
2321
|
-
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
|
|
2412
|
+
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit, onCut)])
|
|
2322
2413
|
);
|
|
2323
2414
|
}
|
|
2324
2415
|
return node;
|
|
2325
2416
|
}
|
|
2326
|
-
function cutStrings(record, limit, exempt) {
|
|
2417
|
+
function cutStrings(record, limit, exempt, onCut) {
|
|
2327
2418
|
return Object.fromEntries(
|
|
2328
2419
|
Object.entries(record).map(([key, child]) => [
|
|
2329
2420
|
key,
|
|
2330
|
-
exempt.has(key) ? child : cutNode(child, limit)
|
|
2421
|
+
exempt.has(key) ? child : cutNode(child, limit, onCut)
|
|
2331
2422
|
])
|
|
2332
2423
|
);
|
|
2333
2424
|
}
|
|
2334
|
-
function reportWriteFailure(destination, cause, due) {
|
|
2425
|
+
function reportWriteFailure(destination, cause, due, censorMessage) {
|
|
2335
2426
|
const name = safeDestinationName(destination);
|
|
2336
2427
|
reportDestinationFailure(
|
|
2337
2428
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_WRITE_FAILED,
|
|
2338
2429
|
name,
|
|
2339
2430
|
cause,
|
|
2340
|
-
|
|
2341
|
-
due - 1
|
|
2431
|
+
"A log destination failed to write; the entry was dropped",
|
|
2432
|
+
due - 1,
|
|
2433
|
+
censorMessage
|
|
2342
2434
|
);
|
|
2343
2435
|
}
|
|
2436
|
+
function recordWriteFailure(destination, health, cause, censorMessage) {
|
|
2437
|
+
const due = health.recordWriteFailure(destination, performance.now());
|
|
2438
|
+
if (due !== void 0) {
|
|
2439
|
+
reportWriteFailure(destination, cause, due, censorMessage);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2344
2442
|
function rescueToStdout(payload) {
|
|
2345
2443
|
writeStdoutSafely(payload);
|
|
2346
2444
|
}
|
|
@@ -2414,7 +2512,7 @@ var BoundedWritable = class extends Writable {
|
|
|
2414
2512
|
);
|
|
2415
2513
|
}
|
|
2416
2514
|
};
|
|
2417
|
-
function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
2515
|
+
function destinationToStream(destination, health, maxQueueBytes = 0, censorMessage) {
|
|
2418
2516
|
const queue = { bytes: 0 };
|
|
2419
2517
|
const stream = new BoundedWritable(destination, health, maxQueueBytes, queue, {
|
|
2420
2518
|
// Keep string chunks as strings (Node's default re-encodes them to Buffers
|
|
@@ -2429,10 +2527,7 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
|
2429
2527
|
settled(error);
|
|
2430
2528
|
};
|
|
2431
2529
|
const onFailure = (cause) => {
|
|
2432
|
-
|
|
2433
|
-
if (due !== void 0) {
|
|
2434
|
-
reportWriteFailure(destination, cause, due);
|
|
2435
|
-
}
|
|
2530
|
+
recordWriteFailure(destination, health, cause, censorMessage);
|
|
2436
2531
|
callback();
|
|
2437
2532
|
};
|
|
2438
2533
|
try {
|
|
@@ -2474,8 +2569,14 @@ var EXPLICIT_USER_KEY = "userId";
|
|
|
2474
2569
|
function mergeMixinSafely(mergeObject, mixinObject) {
|
|
2475
2570
|
try {
|
|
2476
2571
|
const merged = {};
|
|
2572
|
+
const written = /* @__PURE__ */ new Set();
|
|
2573
|
+
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2574
|
+
if (value !== void 0) written.add(foldKey(key));
|
|
2575
|
+
}
|
|
2477
2576
|
for (const key of Object.keys(mergeObject)) {
|
|
2478
|
-
if (key
|
|
2577
|
+
if (key === PROTOTYPE_KEY) continue;
|
|
2578
|
+
if (key !== EXPLICIT_USER_KEY && written.has(foldKey(key))) continue;
|
|
2579
|
+
Reflect.set(merged, key, Reflect.get(mergeObject, key));
|
|
2479
2580
|
}
|
|
2480
2581
|
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2481
2582
|
if (value === void 0) continue;
|
|
@@ -2939,6 +3040,46 @@ function extraServiceFields(service) {
|
|
|
2939
3040
|
return extras;
|
|
2940
3041
|
}
|
|
2941
3042
|
|
|
3043
|
+
// src/server/utils/semconv-exception.util.ts
|
|
3044
|
+
function deriveExceptionFields(record, maxBytes, onCut, censorMessage) {
|
|
3045
|
+
const bounded = (text) => {
|
|
3046
|
+
const cut = cutBytes(text, maxBytes);
|
|
3047
|
+
if (cut !== text) onCut?.();
|
|
3048
|
+
return cut;
|
|
3049
|
+
};
|
|
3050
|
+
const candidate = record["err"];
|
|
3051
|
+
if (typeof candidate?.name === "string") {
|
|
3052
|
+
record["exception.type"] = bounded(cutText(candidate.name));
|
|
3053
|
+
record["error.type"] = bounded(cutText(candidate.name));
|
|
3054
|
+
}
|
|
3055
|
+
const header = headerCensor(candidate?.name, candidate?.message, censorMessage);
|
|
3056
|
+
if (header !== void 0) {
|
|
3057
|
+
record["exception.message"] = bounded(cutText(header.censored));
|
|
3058
|
+
}
|
|
3059
|
+
if (typeof candidate?.stack === "string") {
|
|
3060
|
+
record["exception.stacktrace"] = bounded(scrubStack(candidate.stack, header));
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
function withSemconvException(record, format, maxBytes = Number.POSITIVE_INFINITY, onCut, censorMessage = (text) => text) {
|
|
3064
|
+
if (format === "pino") {
|
|
3065
|
+
return record;
|
|
3066
|
+
}
|
|
3067
|
+
try {
|
|
3068
|
+
deriveExceptionFields(record, maxBytes, onCut, censorMessage);
|
|
3069
|
+
if (format === "semconv") {
|
|
3070
|
+
const withoutErr = {};
|
|
3071
|
+
for (const [key, value] of Object.entries(record)) {
|
|
3072
|
+
if (key !== "err") {
|
|
3073
|
+
Reflect.set(withoutErr, key, value);
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
return withoutErr;
|
|
3077
|
+
}
|
|
3078
|
+
} catch {
|
|
3079
|
+
}
|
|
3080
|
+
return record;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
2942
3083
|
// src/server/utils/serialize-request.util.ts
|
|
2943
3084
|
function isObject2(value) {
|
|
2944
3085
|
return typeof value === "object" && value !== null;
|
|
@@ -2974,20 +3115,34 @@ function withSerializedRequest(record, secretSegments = []) {
|
|
|
2974
3115
|
|
|
2975
3116
|
// src/server/utils/truncate-large-entries.ts
|
|
2976
3117
|
var PREVIEW_LENGTH = 200;
|
|
2977
|
-
function
|
|
3118
|
+
function measurableJson(value) {
|
|
3119
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
3120
|
+
return JSON.stringify(value, function(_key, inner) {
|
|
3121
|
+
if (typeof inner === "bigint") return inner.toString();
|
|
3122
|
+
if (typeof inner !== "object" || inner === null) return inner;
|
|
3123
|
+
for (let holder = this; holder !== void 0; holder = parents.get(holder)) {
|
|
3124
|
+
if (holder === inner) return "[Circular]";
|
|
3125
|
+
}
|
|
3126
|
+
parents.set(inner, this);
|
|
3127
|
+
return inner;
|
|
3128
|
+
});
|
|
3129
|
+
}
|
|
3130
|
+
function createSizeBoundedSerializer(baseSerializer, maxBytes, onTruncate) {
|
|
2978
3131
|
return (input) => {
|
|
2979
3132
|
const serialized = baseSerializer(input);
|
|
2980
3133
|
let json;
|
|
2981
3134
|
try {
|
|
2982
|
-
json =
|
|
3135
|
+
json = measurableJson(serialized);
|
|
2983
3136
|
} catch {
|
|
2984
|
-
|
|
3137
|
+
onTruncate?.();
|
|
3138
|
+
return unmeasurableEnvelope();
|
|
2985
3139
|
}
|
|
2986
3140
|
if (json === void 0) {
|
|
2987
3141
|
return serialized;
|
|
2988
3142
|
}
|
|
2989
3143
|
const byteSize = Buffer.byteLength(json, "utf-8");
|
|
2990
3144
|
if (byteSize > maxBytes) {
|
|
3145
|
+
onTruncate?.();
|
|
2991
3146
|
return {
|
|
2992
3147
|
_truncated: true,
|
|
2993
3148
|
_logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
|
|
@@ -2998,6 +3153,14 @@ function createSizeBoundedSerializer(baseSerializer, maxBytes) {
|
|
|
2998
3153
|
return serialized;
|
|
2999
3154
|
};
|
|
3000
3155
|
}
|
|
3156
|
+
function unmeasurableEnvelope() {
|
|
3157
|
+
return {
|
|
3158
|
+
_truncated: true,
|
|
3159
|
+
_logKey: RESERVED_LOG_KEYS.LOGGER_ENTRY_TRUNCATED,
|
|
3160
|
+
_originalSize: -1,
|
|
3161
|
+
_preview: ""
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3001
3164
|
|
|
3002
3165
|
// src/server/pino-factory.ts
|
|
3003
3166
|
var PATH_SEGMENT = /\[\s*['"]([^'"]+)['"]\s*\]|([^.[\]]+)/g;
|
|
@@ -3013,8 +3176,8 @@ function leafNameOf(path2) {
|
|
|
3013
3176
|
}
|
|
3014
3177
|
return leaf;
|
|
3015
3178
|
}
|
|
3016
|
-
function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
|
|
3017
|
-
const sanitized = sanitizeError(value_, { ownFields });
|
|
3179
|
+
function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS, censorMessage) {
|
|
3180
|
+
const sanitized = sanitizeError(value_, { ownFields, censorMessage });
|
|
3018
3181
|
const serialized = {
|
|
3019
3182
|
// `type` rather than `name`: the field consumers already query.
|
|
3020
3183
|
type: sanitized.name,
|
|
@@ -3032,35 +3195,6 @@ function serializeErrorValue(value_, ownFields = ALL_OWN_FIELDS) {
|
|
|
3032
3195
|
assignOwnErrorFields(serialized, sanitized);
|
|
3033
3196
|
return serialized;
|
|
3034
3197
|
}
|
|
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
3198
|
function toEventName(logKey) {
|
|
3065
3199
|
return logKey.toLowerCase().replaceAll("_", ".");
|
|
3066
3200
|
}
|
|
@@ -3131,11 +3265,16 @@ function resolveRedactOption(options) {
|
|
|
3131
3265
|
}
|
|
3132
3266
|
return { paths, censor: options.redactCensor };
|
|
3133
3267
|
}
|
|
3134
|
-
function buildSerializers(options, redactSerialized, ownFields) {
|
|
3268
|
+
function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
|
|
3135
3269
|
const maxBytes = options.maxEntrySizeBytes;
|
|
3136
|
-
const
|
|
3270
|
+
const censorMessage = buildMessageCensor(options);
|
|
3271
|
+
const bound = (serializer) => createSizeBoundedSerializer(
|
|
3272
|
+
(input) => redactSerialized(serializer(input)),
|
|
3273
|
+
maxBytes,
|
|
3274
|
+
() => onTruncate("max_entry_size")
|
|
3275
|
+
);
|
|
3137
3276
|
return {
|
|
3138
|
-
err: bound((error) => serializeErrorValue(error, ownFields)),
|
|
3277
|
+
err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
|
|
3139
3278
|
...Object.fromEntries(
|
|
3140
3279
|
Object.entries(options.serializers).map(
|
|
3141
3280
|
([key, serializer]) => [key, bound(serializer)]
|
|
@@ -3143,14 +3282,35 @@ function buildSerializers(options, redactSerialized, ownFields) {
|
|
|
3143
3282
|
)
|
|
3144
3283
|
};
|
|
3145
3284
|
}
|
|
3146
|
-
function
|
|
3285
|
+
function buildMessageCensor(options) {
|
|
3286
|
+
const censor = createTextCensor(buildNameRedactor(options));
|
|
3287
|
+
return (text) => censor("message", text);
|
|
3288
|
+
}
|
|
3289
|
+
function withEntryTextFinisher(logger, options, onTruncate) {
|
|
3147
3290
|
const redact = buildNameRedactor(options);
|
|
3148
|
-
|
|
3291
|
+
const finisher = createEntryTextFinisher(
|
|
3292
|
+
redact,
|
|
3293
|
+
options.maxStringLength,
|
|
3294
|
+
() => onTruncate("max_string_length")
|
|
3295
|
+
);
|
|
3296
|
+
Reflect.set(logger, ENTRY_TEXT_FINISHER, finisher);
|
|
3149
3297
|
return logger;
|
|
3150
3298
|
}
|
|
3299
|
+
function buildTraceMixin(logContext, options) {
|
|
3300
|
+
return createTraceContextMixin(logContext, {
|
|
3301
|
+
...options.otel,
|
|
3302
|
+
censorMessage: buildMessageCensor(options)
|
|
3303
|
+
});
|
|
3304
|
+
}
|
|
3151
3305
|
function buildStreams(options, destinations, health) {
|
|
3306
|
+
const censorMessage = buildMessageCensor(options);
|
|
3152
3307
|
return destinations.map((destination) => {
|
|
3153
|
-
const stream = destinationToStream(
|
|
3308
|
+
const stream = destinationToStream(
|
|
3309
|
+
destination,
|
|
3310
|
+
health,
|
|
3311
|
+
options.destinationQueue.maxBytes,
|
|
3312
|
+
censorMessage
|
|
3313
|
+
);
|
|
3154
3314
|
health.registerStream(destination, stream);
|
|
3155
3315
|
return {
|
|
3156
3316
|
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
@@ -3162,20 +3322,27 @@ function buildStreams(options, destinations, health) {
|
|
|
3162
3322
|
};
|
|
3163
3323
|
});
|
|
3164
3324
|
}
|
|
3165
|
-
function buildRecordFormatter(options, redactRecord) {
|
|
3325
|
+
function buildRecordFormatter(options, redactRecord, onTruncate) {
|
|
3166
3326
|
const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
|
|
3167
3327
|
const maxStringLength = options.maxStringLength;
|
|
3168
3328
|
const wholeRoots = wholeRootKeys(options);
|
|
3329
|
+
const censorMessage = buildMessageCensor(options);
|
|
3169
3330
|
return (record) => {
|
|
3170
3331
|
const redacted = redactRecord(
|
|
3171
3332
|
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
3172
3333
|
true
|
|
3173
3334
|
);
|
|
3174
|
-
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
|
|
3175
|
-
return withSemconvException(
|
|
3335
|
+
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots, () => onTruncate("max_string_length"));
|
|
3336
|
+
return withSemconvException(
|
|
3337
|
+
withEventName(bounded, options.eventNameField),
|
|
3338
|
+
options.errorFormat,
|
|
3339
|
+
options.maxEntrySizeBytes,
|
|
3340
|
+
() => onTruncate("max_entry_size"),
|
|
3341
|
+
censorMessage
|
|
3342
|
+
);
|
|
3176
3343
|
};
|
|
3177
3344
|
}
|
|
3178
|
-
function buildFormatters(options, redactRecord, redactBindings) {
|
|
3345
|
+
function buildFormatters(options, redactRecord, redactBindings, onTruncate) {
|
|
3179
3346
|
return {
|
|
3180
3347
|
// Emit the level as a string label instead of the numeric code — easier
|
|
3181
3348
|
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
@@ -3196,7 +3363,7 @@ function buildFormatters(options, redactRecord, redactBindings) {
|
|
|
3196
3363
|
// `base` and child bindings are NOT visible at this hook — they are
|
|
3197
3364
|
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
3198
3365
|
// sensitive, which `pino-factory.spec.ts` pins.
|
|
3199
|
-
log: buildRecordFormatter(options, redactRecord)
|
|
3366
|
+
log: buildRecordFormatter(options, redactRecord, onTruncate)
|
|
3200
3367
|
};
|
|
3201
3368
|
}
|
|
3202
3369
|
function buildPinoInstance(options, logContext, destinations, health) {
|
|
@@ -3207,6 +3374,7 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3207
3374
|
const redactSerialized = buildNameRedactor(options);
|
|
3208
3375
|
const ownFields = ownFieldPolicyOf(options);
|
|
3209
3376
|
const redactOption = resolveRedactOption(options);
|
|
3377
|
+
const onTruncate = (reason) => health.recordTruncation(reason);
|
|
3210
3378
|
const pinoOptions = {
|
|
3211
3379
|
level: options.level,
|
|
3212
3380
|
...redactOption === void 0 ? {} : { redact: redactOption },
|
|
@@ -3223,13 +3391,13 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3223
3391
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
3224
3392
|
// neither break the line nor add fields to it.
|
|
3225
3393
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
3226
|
-
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
|
|
3227
|
-
serializers: buildSerializers(options, redactSerialized, ownFields),
|
|
3228
|
-
mixin:
|
|
3394
|
+
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options), onTruncate),
|
|
3395
|
+
serializers: buildSerializers(options, redactSerialized, ownFields, onTruncate),
|
|
3396
|
+
mixin: buildTraceMixin(logContext, options),
|
|
3229
3397
|
mixinMergeStrategy: mergeMixinSafely
|
|
3230
3398
|
};
|
|
3231
3399
|
const streams = pino.multistream(buildStreams(options, destinations, health));
|
|
3232
|
-
return withEntryTextFinisher(pino(pinoOptions, streams), options);
|
|
3400
|
+
return withEntryTextFinisher(pino(pinoOptions, streams), options, onTruncate);
|
|
3233
3401
|
}
|
|
3234
3402
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
3235
3403
|
function countInWindow(records, destination, now) {
|
|
@@ -3247,6 +3415,9 @@ function countInWindow(records, destination, now) {
|
|
|
3247
3415
|
}
|
|
3248
3416
|
var DestinationHealth = class {
|
|
3249
3417
|
constructor() {
|
|
3418
|
+
/** How many fields were cut or replaced for the entry-size ceiling, and for the string limit. */
|
|
3419
|
+
this.entrySizeTruncations = 0;
|
|
3420
|
+
this.stringLengthTruncations = 0;
|
|
3250
3421
|
/** Destinations whose `onInit()` rejected. Identity-keyed, not name-keyed. */
|
|
3251
3422
|
this.failed = /* @__PURE__ */ new Set();
|
|
3252
3423
|
/**
|
|
@@ -3345,6 +3516,34 @@ var DestinationHealth = class {
|
|
|
3345
3516
|
this.writeFailed.add(destination);
|
|
3346
3517
|
return countInWindow(this.writeFailures, destination, now);
|
|
3347
3518
|
}
|
|
3519
|
+
/**
|
|
3520
|
+
* Record one field cut or replaced for a size bound.
|
|
3521
|
+
*
|
|
3522
|
+
* @param reason - Which bound: the entry-size ceiling or the string limit.
|
|
3523
|
+
*/
|
|
3524
|
+
recordTruncation(reason) {
|
|
3525
|
+
if (reason === "max_entry_size") this.entrySizeTruncations += 1;
|
|
3526
|
+
else this.stringLengthTruncations += 1;
|
|
3527
|
+
}
|
|
3528
|
+
/** @inheritDoc */
|
|
3529
|
+
truncatedTotal(reason) {
|
|
3530
|
+
return reason === "max_entry_size" ? this.entrySizeTruncations : this.stringLengthTruncations;
|
|
3531
|
+
}
|
|
3532
|
+
/** @inheritDoc */
|
|
3533
|
+
destinationErrorTotal() {
|
|
3534
|
+
let total = 0;
|
|
3535
|
+
for (const count of this.writeFailures.values()) total += count.total;
|
|
3536
|
+
return total;
|
|
3537
|
+
}
|
|
3538
|
+
/** @inheritDoc */
|
|
3539
|
+
deliveryState() {
|
|
3540
|
+
return {
|
|
3541
|
+
destinations: this.healthy.size + this.failed.size,
|
|
3542
|
+
failedInit: this.failed.size,
|
|
3543
|
+
writeFailing: this.writeFailed.size,
|
|
3544
|
+
hasHealthySink: this.healthy.size > 0
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3348
3547
|
/**
|
|
3349
3548
|
* How many writes a destination has refused since startup.
|
|
3350
3549
|
*
|
|
@@ -3546,6 +3745,7 @@ var DestinationRegistry = class {
|
|
|
3546
3745
|
* `onInit` runs and cannot be rebuilt afterwards; see `DestinationHealth`.
|
|
3547
3746
|
*/
|
|
3548
3747
|
this.active = [];
|
|
3748
|
+
this.censorMessage = buildMessageCensor(options);
|
|
3549
3749
|
}
|
|
3550
3750
|
/**
|
|
3551
3751
|
* Initialize every registered destination. A destination whose `onInit`
|
|
@@ -3647,12 +3847,13 @@ var DestinationRegistry = class {
|
|
|
3647
3847
|
* @param cause - The thrown or rejected value.
|
|
3648
3848
|
*/
|
|
3649
3849
|
reportInitFailure(destination, cause) {
|
|
3650
|
-
const name = safeDestinationName(destination);
|
|
3651
3850
|
reportDestinationFailure(
|
|
3652
3851
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
|
|
3653
|
-
|
|
3852
|
+
safeDestinationName(destination),
|
|
3654
3853
|
cause,
|
|
3655
|
-
|
|
3854
|
+
"A log destination failed to initialize and will receive no entries. If no destination initializes, entries fall back to raw NDJSON on stdout.",
|
|
3855
|
+
0,
|
|
3856
|
+
this.censorMessage
|
|
3656
3857
|
);
|
|
3657
3858
|
}
|
|
3658
3859
|
/**
|
|
@@ -3671,12 +3872,13 @@ var DestinationRegistry = class {
|
|
|
3671
3872
|
*/
|
|
3672
3873
|
reportHookFailure(destination, cause) {
|
|
3673
3874
|
const stillActive = !this.health.isFailed(destination);
|
|
3674
|
-
const name = safeDestinationName(destination);
|
|
3675
3875
|
reportDestinationFailure(
|
|
3676
3876
|
RESERVED_LOG_KEYS.LOGGER_DESTINATION_INIT_FAILED,
|
|
3677
|
-
|
|
3877
|
+
safeDestinationName(destination),
|
|
3678
3878
|
cause,
|
|
3679
|
-
|
|
3879
|
+
"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."),
|
|
3880
|
+
0,
|
|
3881
|
+
this.censorMessage
|
|
3680
3882
|
);
|
|
3681
3883
|
}
|
|
3682
3884
|
/**
|
|
@@ -3706,7 +3908,7 @@ var DestinationRegistry = class {
|
|
|
3706
3908
|
}
|
|
3707
3909
|
);
|
|
3708
3910
|
}
|
|
3709
|
-
if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi() === void 0) {
|
|
3911
|
+
if (this.options.otel.shouldAutoInjectTraceContext && detectOtelTraceApi(void 0, this.censorMessage) === void 0) {
|
|
3710
3912
|
this.logger.warnStructured(
|
|
3711
3913
|
RESERVED_LOG_KEYS.LOGGER_BOOTSTRAP_WARNING,
|
|
3712
3914
|
"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 +4028,32 @@ var DestinationRegistry = class {
|
|
|
3826
4028
|
}
|
|
3827
4029
|
}
|
|
3828
4030
|
/**
|
|
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.
|
|
3840
|
-
*
|
|
3841
|
-
* The text is escaped for the same reason every other terminal-bound path is:
|
|
3842
|
-
* a stack is legitimately multi-line, so `escapeControlCharacters` keeps its
|
|
3843
|
-
* newlines and neutralizes everything else that can drive a terminal.
|
|
4031
|
+
* Report a failing `onShutdown` on stderr, as a structured line like the other stages, without
|
|
4032
|
+
* letting the report itself abort the teardown of the destinations still queued behind it.
|
|
3844
4033
|
*
|
|
3845
|
-
* The
|
|
3846
|
-
*
|
|
3847
|
-
*
|
|
3848
|
-
*
|
|
4034
|
+
* The line is written by {@link reportDestinationFailure}, which holds every guard the report
|
|
4035
|
+
* needs: the cause is read inside a guard (a hostile getter or `toPrimitive` degrades the detail
|
|
4036
|
+
* and never the line), the text is escaped for a terminal, and the message of the error passes
|
|
4037
|
+
* the censor of the `message` of an entry. The error is a field (`err`) and never part of `msg`,
|
|
4038
|
+
* which is library text, and its stack is not written: a stack is text a host error carries
|
|
4039
|
+
* whole, and the type and the censored message identify the failure.
|
|
3849
4040
|
*
|
|
3850
|
-
*
|
|
3851
|
-
*
|
|
3852
|
-
*
|
|
4041
|
+
* The DESTINATION is passed rather than its name, so that read happens inside the guard too:
|
|
4042
|
+
* `name` is declared `readonly name: string` but nothing stops a consumer implementing it as a
|
|
4043
|
+
* getter, and reading it at the call site would put it back outside the guard.
|
|
3853
4044
|
*
|
|
3854
4045
|
* @param destination - The destination whose `onShutdown` threw.
|
|
3855
4046
|
* @param cause - The thrown value, of any shape.
|
|
3856
4047
|
*/
|
|
3857
4048
|
reportShutdownFailure(destination, cause) {
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
`);
|
|
4049
|
+
reportDestinationFailure(
|
|
4050
|
+
RESERVED_LOG_KEYS.LOGGER_DESTINATION_SHUTDOWN_FAILED,
|
|
4051
|
+
safeDestinationName(destination),
|
|
4052
|
+
cause,
|
|
4053
|
+
"A log destination failed to shut down; anything it was still holding is lost.",
|
|
4054
|
+
0,
|
|
4055
|
+
this.censorMessage
|
|
4056
|
+
);
|
|
3867
4057
|
}
|
|
3868
4058
|
/**
|
|
3869
4059
|
* The destinations that initialized successfully.
|
|
@@ -3894,6 +4084,8 @@ function buildCommonProviders() {
|
|
|
3894
4084
|
// and by DestinationRegistry (which writes to it during onModuleInit). Both
|
|
3895
4085
|
// depend on this provider and it depends on nothing, so there is no cycle.
|
|
3896
4086
|
DestinationHealth,
|
|
4087
|
+
// The counters and the delivery state of the logger, for the `/observability` subpath.
|
|
4088
|
+
{ provide: LOGGER_OBSERVABILITY_TOKEN, useExisting: DestinationHealth },
|
|
3897
4089
|
{
|
|
3898
4090
|
// The DEFAULT-coverage redactor, shared by the Pino factory's hooks and by
|
|
3899
4091
|
// `PinoLoggerService.child()`. The latter needs it as a provider because
|
|
@@ -3943,6 +4135,7 @@ function augmentLoggerModule(base, providers) {
|
|
|
3943
4135
|
LOGGER_PINO_INSTANCE_TOKEN,
|
|
3944
4136
|
LOGGER_DESTINATIONS_TOKEN,
|
|
3945
4137
|
LOGGER_REDACTOR_TOKEN,
|
|
4138
|
+
LOGGER_OBSERVABILITY_TOKEN,
|
|
3946
4139
|
LOG_CONTEXT_TOKEN,
|
|
3947
4140
|
LogContextService,
|
|
3948
4141
|
PinoLoggerService,
|
|
@@ -4542,7 +4735,9 @@ var PinoUnexpectedErrorSink = class {
|
|
|
4542
4735
|
RESERVED_LOG_KEYS.HTTP_UNEXPECTED_ERROR_DROPPED,
|
|
4543
4736
|
"PinoUnexpectedErrorSink",
|
|
4544
4737
|
cause,
|
|
4545
|
-
"An unexpected-error report could not be logged and was dropped."
|
|
4738
|
+
"An unexpected-error report could not be logged and was dropped.",
|
|
4739
|
+
0,
|
|
4740
|
+
(text) => this.logger.censorMessageText(text)
|
|
4546
4741
|
);
|
|
4547
4742
|
}
|
|
4548
4743
|
}
|
|
@@ -4648,4 +4843,4 @@ function LogPerformance(thresholdMs = DEFAULT_THRESHOLD_MS) {
|
|
|
4648
4843
|
// src/shared/constants/log-keys-convention.constants.ts
|
|
4649
4844
|
var LOG_KEYS_CONVENTION_REGEX = /^[A-Z][A-Z0-9_]+_[A-Z][A-Z0-9_]+(_[A-Z][A-Z0-9_]+)?$/;
|
|
4650
4845
|
|
|
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 };
|
|
4846
|
+
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 };
|