fix(logging): never redact trace/span correlation keys#156
Merged
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Response to the observability master document (logs finding L1).
Problem
Redaction ran over each log record after
_add_trace_idsinjected the correlation keys. A 32-chartrace_idhex 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 mutilatetrace_id/span_idand silently break log↔trace correlation.Fix
NEVER_REDACT = {trace_id, span_id, trace_flags, correlationId}allowlist in the structlog redactor, checked first so it wins even over an explicitdeny_fieldsentry.Tests
New regression case reproduces the PHONE corruption (sanity-asserts the id would be mutilated unguarded) and asserts
trace_id/span_idsurvive verbatim while a genuine phone in the message is still redacted. Full logging suite green (51 passed).Out of scope
The
StdlibLoggingAdaptertrace-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.