It's currently difficult to correlate distributed requests across services using only logs. While the traceparent header (W3C Trace Context) provides the necessary context, directly logging the trace_id component would be the most effective way to enable log-based trace correlation.
When an incoming HTTP request contains the traceparent header:
- Parse the header value according to the W3C Trace Context specification.
- Extract the
trace_id portion.
- Include this extracted
trace_id value in the corresponding request log entry.
For example, if the header is traceparent="00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01", the log entry should include a field like trace_id="0af7651916cd43dd8448eb211c80319c".
Logging the full traceparent string is an alternative, but logging just the trace_id is often sufficient for correlation and can result in slightly cleaner/more focused log entries.
This allows direct filtering and searching of logs using the trace_id in log aggregation systems, significantly improving debugging capabilities and observability for distributed traces.
c.f.
Some cloud providers support their own log format for trace id:
Google Cloud "trace" or "logging.googleapis.com/trace" Structured logging
AWS aws.cloudwatch_logs.log_group AWS resource data
It's currently difficult to correlate distributed requests across services using only logs. While the
traceparentheader (W3C Trace Context) provides the necessary context, directly logging thetrace_idcomponent would be the most effective way to enable log-based trace correlation.When an incoming HTTP request contains the
traceparentheader:trace_idportion.trace_idvalue in the corresponding request log entry.For example, if the header is
traceparent="00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01", the log entry should include a field liketrace_id="0af7651916cd43dd8448eb211c80319c".Logging the full
traceparentstring is an alternative, but logging just thetrace_idis often sufficient for correlation and can result in slightly cleaner/more focused log entries.This allows direct filtering and searching of logs using the
trace_idin log aggregation systems, significantly improving debugging capabilities and observability for distributed traces.c.f.
Some cloud providers support their own log format for trace id:
Google Cloud "trace" or "logging.googleapis.com/trace" Structured logging
AWS aws.cloudwatch_logs.log_group AWS resource data