Part 14 · Observability & Production Debugging
14.1 / Logging

Structured events, privacy và audit integrity

Log là event contract cho operators; stack trace strings không thay stable fields, event codes và ownership.

Schema

Timestamp UTC, level, service/version/env, event code/message, trace/span, operation, bounded error/category and relevant safe identifiers. JSON/types enable query; consistent names across services. Log at ownership boundary to avoid duplicate noise.

Errors

Preserve cause/stack once where actionable; expected validation not ERROR. Retry attempts sampled/aggregated with final failure clear. Avoid logging same exception each layer. Include state transition, latency and dependency outcome.

Privacy/security

Never tokens/passwords/keys/full payment/medical/PII. Redaction before serialization/export; access/retention/encryption. Attackers can inject newlines/control fields, so structured encoders. Secret masking cannot prevent encoded exfiltration.

Audit

Audit answers who/what/when/where/outcome, with immutable/tamper-evident retention and restricted access. Separate from debug logs and business source of truth. Clock synchronization and identity provenance matter.

Operations

Sampling/rate limit repetitive logs, but preserve errors/security per policy. Index only useful fields, tier/archive/delete. Detect dropped logs/backpressure; logging must not block critical path indefinitely.

OTel Logs Data Model · OWASP Logging Cheat Sheet
← MetricsTracing →