161 Structured Logging and Correlation

161 Structured Logging and Correlation

Structured logs are event records, not formatted print statements.

Correlation Model

request_id/trace_id
   -> log fields
   -> metric labels (careful cardinality)
   -> trace attributes

A single correlation key allows fast cross-signal debugging.

Schema Discipline

Keep a stable field set across services:

  • service
  • env
  • request_id
  • trace_id
  • error_class

Inconsistent schemas make incident search expensive and error-prone.

Security Consideration

Logs are data exfiltration risk. Always design for redaction and sensitive-field filtering.