Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(logger): state why a BigInt digit is charged sixteen characters

Yudhi Armyndharis119f61565003
diff --git a/docs/10-devops-infrastructure.md b/docs/10-devops-infrastructure.md
index b929ded08..7c297eeaa 100644
--- a/docs/10-devops-infrastructure.md
+++ b/docs/10-devops-infrastructure.md
@@ -1111,7 +1111,8 @@ level), and, at any level, an array, Map or Set of more than a million entries.
it is written as: its list of pairs, and each pair an array of two, which below the fifth level is one more of
those 1000. At every level one call copies at most two million entries in all (the keys of its objects plus the
lengths of its arrays, so three to a Map's pair: one of more than 666,666 pairs loses its last pairs) and writes at
-most 2^26 (about 67 million) characters of string values, key names and BigInt text (sixteen to the digit); a
+most 2^26 (about 67 million) characters of string values, key names and BigInt text (sixteen to the digit, as
+a long BigInt's text costs that much more to build, so one of more than 2^22 digits is `[Truncated]` even alone); a
value referenced again is counted again at each use, and what no longer fits is written as `[Truncated]`.
A value that keeps its data outside its own properties is written readably, at any depth: an Error as its
`name`, `message` and `stack` before its own properties, a Date as its ISO text (`Invalid Date` when it holds
diff --git a/src/common/services/logger.service.ts b/src/common/services/logger.service.ts
index 22507ad01..9becc7bf3 100644
--- a/src/common/services/logger.service.ts
+++ b/src/common/services/logger.service.ts
@@ -53,6 +53,9 @@ const REDACT_MAX_ENTRIES = 2_000_000;
// not fit is written as [Truncated]. It is far above any line a caller writes on purpose (a million entries of 64
// characters fit), and below what V8 can build.
const REDACT_MAX_CHARS = 2 ** 26;
+// Building the text of a BigInt costs more per digit the longer it is: about 20 times what writing a character of a
+// string costs at 100,000 digits and 80 times at 4 million. So a BigInt of more than 2**22 digits does not fit even
+// alone, and a line under 2**26 characters that holds one is still cut.
const REDACT_BIGINT_WEIGHT = 16;
export interface RedactOptions {
@@ -167,7 +170,7 @@ export function redactSecrets(value: unknown, options: RedactOptions = {}): unkn
const parents = [...path, node];
const copy = (child: unknown): unknown => {
if (typeof child !== 'bigint') return walk(child, parents);
- // Its text costs far more to build than a string of that length costs to write (ten times or more), and
+ // Its text costs far more to build than a string of that length costs to write (see REDACT_BIGINT_WEIGHT), and
// none is built once the budget is spent.
if (budget.chars < 0) return '[Truncated]';
const text = child.toString();