Skip to content

fix(logging): never redact trace/span correlation keys#156

Merged
casc84ab merged 2 commits into
mainfrom
fix/never-redact-correlation-keys
Jul 16, 2026
Merged

fix(logging): never redact trace/span correlation keys#156
casc84ab merged 2 commits into
mainfrom
fix/never-redact-correlation-keys

Conversation

@casc84ab

Copy link
Copy Markdown
Contributor

Response to the observability master document (logs finding L1).

Problem

Redaction ran over each log record after _add_trace_ids injected the correlation keys. A 32-char trace_id hex can contain a 7-digit island bounded by hex letters, which matches the built-in PHONE pattern ((?<!\d)…\d{3}[ .-]?\d{4}(?!\d)). The redactor could therefore mutilate trace_id/span_id and silently break log↔trace correlation.

Fix

  • Hardcoded NEVER_REDACT = {trace_id, span_id, trace_flags, correlationId} allowlist in the structlog redactor, checked first so it wins even over an explicit deny_fields entry.
  • Reordered the structlog pre-chain so redaction runs before trace-id injection (defense in depth — the redactor never even sees the keys).

Tests

New regression case reproduces the PHONE corruption (sanity-asserts the id would be mutilated unguarded) and asserts trace_id/span_id survive verbatim while a genuine phone in the message is still redacted. Full logging suite green (51 passed).

Out of scope

The StdlibLoggingAdapter trace-id injection asymmetry (it doesn't inject correlation keys at all) is a separate, larger change (new filter + JSON contract change) and is not included here.

casc84ab added 2 commits July 16, 2026 12:03
Presidio-style redaction ran over log records after the trace ids were injected,
and a 32-char trace_id hex can contain a 7-digit island that matches the PHONE
pattern, so the redactor could mutilate trace_id/span_id and silently break
log↔trace correlation.

Add a hardcoded NEVER_REDACT allowlist {trace_id, span_id, trace_flags,
correlationId} in the structlog redactor that wins even over an explicit deny,
and reorder the structlog pre-chain so redaction runs BEFORE trace-id injection
(defense in depth). Adds a regression test that reproduces the PHONE corruption
and asserts the keys survive while a genuine phone in the message is still redacted.
@casc84ab
casc84ab merged commit 8cd79af into main Jul 16, 2026
7 checks passed
@casc84ab
casc84ab deleted the fix/never-redact-correlation-keys branch July 16, 2026 10:20
casc84ab added a commit that referenced this pull request Jul 16, 2026
Never-redact fix for trace/span correlation keys (#156). First release of July,
patch reset to 01.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant