0004: Redact before anything leaves the process¶
Status: accepted ยท Reviewed: 2026-10-31
Ownership narrowed by 0015: applications can retain their own sanitized logging pipeline explicitly.
Context¶
Log records carry request data. Passwords, tokens, cookies and API keys end up in extra fields and headers. Once a value has been written to a file or exported to a backend, it can't be taken back.
Decision¶
- Redaction runs in fastapi-observer's own output path, before anything is written or exported:
- the JSON formatter covers stdout, files and sinks;
- a sanitizing wrapper covers the OTLP log handler (
otel/logs.py:26).
- Presets choose what is masked:
strict,pciandgdpr. - Containers nested deeper than the depth limit are masked, not passed through (
redaction.py:41). - No handler other than fastapi-observer's queue handler goes on the root logger. Anything else there receives records before redaction.
Evidence¶
- The leak this rule prevents. From March to October 2026, an OpenTelemetry handler on the root logger exported every record a second time without redaction. It was fixed in 1.5.0.
- The guard test.
test_otlp_logs_are_redacted_without_deprecated_or_root_handlerfails if another handler sits on the root logger after setup, and checks that an exportedpasswordcomes out as***.
What it cost¶
- Other root-logger handlers aren't covered. Redaction belongs to fastapi-observer's handlers, not to the records themselves. A handler someone else adds to the root logger, such as Sentry's logging integration, still sees unredacted data. The Sentry notes document this. It isn't solved.
- Matching is by field name. A secret stored under a key that isn't on the list isn't masked.
- CPU on every record. Nested data is walked. Since 1.5.0, the key sets are built once per policy instead of once per record.