Design Distributed Tracing and Safe Production Logs Together
Correlate requests across services while controlling log volume, masking sensitive fields, limiting access, and retaining only useful operational data.
Source and AI note: This article is based on Gemini’s Devpractice on YouTube. It was generated and edited with the
gpt-5.6-solmodel.
Production logs are useful only when operators can connect the right events without exposing data the system should not retain. In a distributed request path, prioritize end-to-end correlation with a shared trace identifier, then log the minimum information needed to diagnose the flow. Volume, access, retention, and sensitive fields belong in the same design.
A rigid rule such as “write an error before throwing upward” does not guarantee useful evidence. Consistency matters, but the operational question comes first: can the team reconstruct one failed request across the services that handled it?
Follow one request across service boundaries
If service A calls B and B calls C, three isolated log streams do not reveal which entries belong together. A user may have made several similar requests. Timestamps and user IDs alone can leave operators guessing which payment call followed which order attempt.
Propagate one trace identifier through the entire path. Each local operation can have its own span identifier while sharing the trace. A centralized log search can then retrieve the sequence as one incident narrative rather than three unrelated fragments.
The specific tracing library is an implementation choice and can change. The durable requirement is correlation across the actual transport boundaries used by the system. Common HTTP or RPC instrumentation may justify a small shared component because inconsistency here directly damages operability.
Do not let convenient serialization leak secrets
Request and response logging is dangerous when generic string conversion prints every field. Passwords, phone numbers, or other sensitive values can enter centralized storage simply because a data class generated a convenient representation.
Safer logging selects fields deliberately. Sensitive types can control their representation, and shared logging code can mask or omit marked values. The mechanism matters less than the invariant: a new field must not become public to operators merely because an object was logged whole.
Logging nothing is not the answer. Without request correlation and meaningful state, operating the service becomes guesswork. Preserve identifiers and events that explain the path while excluding payload detail that is not needed to resolve an incident.
Separate exceptional audit needs from general logs
Full SQL logging in production can create large volumes and expose parameters without providing proportionate operational value. That is a default caution, not a ban that fits every system. Some audit or support case may require detailed evidence.
When detail is genuinely required, isolate it rather than turning every application log into a sensitive archive. Limit access to authorized roles, retain it only for the necessary period, and involve security or legal specialists in the applicable requirements. Masked data that cannot answer the operational question is not automatically useful; unmasked data without strict control is not acceptable either.
A sound logging policy answers four things together: how one request is traced, what fields are recorded, who may inspect them, and how long they remain. Optimizing only one creates another failure. Traceability without privacy leaks data; aggressive masking without useful correlation leaves the service impossible to operate.