How do you correlate logs with traces?
BeginnerConceptTracing & OpenTelemetry
Answer
Put the active trace_id and span_id into every log line, then configure the UI to link them.
- Use the OTel logging bridge or a log appender (Logback/Log4j MDC, Python
LoggingInstrumentor,otelslogin Go) so the IDs are added automatically. - Log in JSON:
{"level":"error","msg":"charge failed","trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","span_id":"00f067aa0ba902b7"} - In Grafana, configure derived fields on the Loki datasource (regex on
trace_id) to link to Tempo, and trace to logs on the Tempo datasource to query Loki by trace ID.
Now an engineer goes from an error log to the full request waterfall in one click, and from a slow span to its logs.
More on Tracing & OpenTelemetry
What is distributed tracing, and what are a trace, a span and a span context?BeginnerWhat fields does an OpenTelemetry span carry?BeginnerWhat are span kinds and why do they matter?IntermediateWhat does the W3C `traceparent` header look like?IntermediateWhat is baggage, and how is it different from span attributes?IntermediateWhat is OpenTelemetry and what are its main parts?Beginner