@logbrew/sdk 0.1.5 → 0.1.6
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/README.md +1 -1
- package/core.cjs +61 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -585,7 +585,7 @@ logger.error(new Error("payment failed"), "checkout failed");
|
|
|
585
585
|
await destination.flush();
|
|
586
586
|
```
|
|
587
587
|
|
|
588
|
-
The Pino adapter reads JSON log lines, maps Pino `trace`/`debug` to LogBrew `info`, `warn` to `warning`, `error` to `error`, and `fatal` to `critical`, captures primitive Pino fields as `context.*`, captures serialized error name/message, skips noisy runtime defaults, and omits stack text unless `includeErrorStack: true` is set. It does not patch Pino or replace application logger ownership.
|
|
588
|
+
The Pino adapter reads JSON log lines, maps Pino `trace`/`debug` to LogBrew `info`, `warn` to `warning`, `error` to `error`, and `fatal` to `critical`, captures safe primitive Pino fields as `context.*`, captures serialized error name/message, skips noisy runtime defaults, and omits stack text unless `includeErrorStack: true` is set. Credential, authorization, cookie, body, payload, query, raw-URL, propagation-header, local-path, and stack fields are excluded even when they are primitive. It does not patch Pino or replace application logger ownership. The log message itself is telemetry, so retain normal Pino redaction and keep secrets or user-entered text out of messages.
|
|
589
589
|
|
|
590
590
|
When the app also uses a LogBrew Node or framework request helper, pass `traceProvider: getActiveLogBrewTrace` from `@logbrew/node` to add the current active `traceId`, `spanId`, optional `parentSpanId`, and `sampled` flag to each captured log. The provider is called per record, invalid or missing contexts are ignored, and no raw propagation headers, request data, payloads, or stack traces are captured.
|
|
591
591
|
|
package/core.cjs
CHANGED
|
@@ -28,6 +28,44 @@ const CONSOLE_METHODS = new Set(["debug", "info", "log", "warn", "error"]);
|
|
|
28
28
|
const DEFAULT_CONSOLE_LEVELS = ["debug", "info", "log", "warn", "error"];
|
|
29
29
|
const PINO_HOST_FIELD = ["host", "name"].join("");
|
|
30
30
|
const PINO_RESERVED_FIELDS = new Set(["level", "time", "timestamp", "msg", "message", "err", "error", "pid", PINO_HOST_FIELD, "v"]);
|
|
31
|
+
const PINO_SENSITIVE_CONTEXT_FIELDS = new Set([
|
|
32
|
+
"apikey",
|
|
33
|
+
"authorization",
|
|
34
|
+
"baggage",
|
|
35
|
+
"body",
|
|
36
|
+
"cookie",
|
|
37
|
+
"credentials",
|
|
38
|
+
"cwd",
|
|
39
|
+
"directory",
|
|
40
|
+
"dirname",
|
|
41
|
+
"errorstack",
|
|
42
|
+
"file",
|
|
43
|
+
"filename",
|
|
44
|
+
"filepath",
|
|
45
|
+
"headers",
|
|
46
|
+
"href",
|
|
47
|
+
"key",
|
|
48
|
+
"password",
|
|
49
|
+
"payload",
|
|
50
|
+
"proxyauthorization",
|
|
51
|
+
"query",
|
|
52
|
+
"querystring",
|
|
53
|
+
"requestbody",
|
|
54
|
+
"requestheaders",
|
|
55
|
+
"requesturl",
|
|
56
|
+
"responsebody",
|
|
57
|
+
"responseheaders",
|
|
58
|
+
"responseurl",
|
|
59
|
+
"search",
|
|
60
|
+
"secret",
|
|
61
|
+
"setcookie",
|
|
62
|
+
"stack",
|
|
63
|
+
"token",
|
|
64
|
+
"traceparent",
|
|
65
|
+
"tracestate",
|
|
66
|
+
"uri",
|
|
67
|
+
"url"
|
|
68
|
+
]);
|
|
31
69
|
const TRACEPARENT_PATTERN = /^([0-9a-fA-F]{2})-([0-9a-fA-F]{32})-([0-9a-fA-F]{16})-([0-9a-fA-F]{2})$/u;
|
|
32
70
|
const ZERO_TRACE_ID = "00000000000000000000000000000000";
|
|
33
71
|
const ZERO_SPAN_ID = "0000000000000000";
|
|
@@ -1798,13 +1836,35 @@ function pinoMessage(record) {
|
|
|
1798
1836
|
function pinoContextMetadata(record) {
|
|
1799
1837
|
const metadata = {};
|
|
1800
1838
|
for (const [key, value] of Object.entries(record)) {
|
|
1801
|
-
if (!PINO_RESERVED_FIELDS.has(key) && isMetadataValue(value)) {
|
|
1839
|
+
if (!PINO_RESERVED_FIELDS.has(key) && !isSensitivePinoContextField(key) && isMetadataValue(value)) {
|
|
1802
1840
|
metadata[`context.${key}`] = value;
|
|
1803
1841
|
}
|
|
1804
1842
|
}
|
|
1805
1843
|
return metadata;
|
|
1806
1844
|
}
|
|
1807
1845
|
|
|
1846
|
+
function isSensitivePinoContextField(key) {
|
|
1847
|
+
const normalized = key.toLowerCase().replace(/[^a-z0-9]+/gu, "");
|
|
1848
|
+
return (
|
|
1849
|
+
PINO_SENSITIVE_CONTEXT_FIELDS.has(normalized)
|
|
1850
|
+
|| normalized.endsWith("accesskey")
|
|
1851
|
+
|| normalized.endsWith("apikey")
|
|
1852
|
+
|| normalized.endsWith("authorization")
|
|
1853
|
+
|| normalized.endsWith("body")
|
|
1854
|
+
|| normalized.endsWith("cookie")
|
|
1855
|
+
|| normalized.endsWith("credentials")
|
|
1856
|
+
|| normalized.endsWith("headers")
|
|
1857
|
+
|| normalized.endsWith("password")
|
|
1858
|
+
|| normalized.endsWith("payload")
|
|
1859
|
+
|| normalized.endsWith("privatekey")
|
|
1860
|
+
|| normalized.endsWith("query")
|
|
1861
|
+
|| normalized.endsWith("secret")
|
|
1862
|
+
|| normalized.endsWith("stack")
|
|
1863
|
+
|| normalized.endsWith("token")
|
|
1864
|
+
|| normalized.endsWith("url")
|
|
1865
|
+
);
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1808
1868
|
function addPinoErrorMetadata(metadata, error, includeErrorStack) {
|
|
1809
1869
|
if (!error) {
|
|
1810
1870
|
return;
|