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.

  1. Use the OTel logging bridge or a log appender (Logback/Log4j MDC, Python LoggingInstrumentor, otelslog in Go) so the IDs are added automatically.
  2. Log in JSON:
    {"level":"error","msg":"charge failed","trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","span_id":"00f067aa0ba902b7"}
    
  3. 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.

All Monitoring & Observability questions Roadmap: Logging & tracing

More on Tracing & OpenTelemetry