Lesson 11 / 25

Logs and Trace Correlation

Connect log lines to traces.

Bridge existing logging

OpenTelemetry does not ask you to replace your logging library. Instead, log bridges and appenders connect existing frameworks (Python logging, Log4j, Logback, .NET ILogger) to the SDK, which adds the active trace ID and span ID to each record and exports logs over OTLP. Alternatively, keep writing structured logs to files or stdout with trace IDs included and let the Collector's filelog receiver collect them. Either way, log lines can be joined to traces.

A structured log line with trace context

What correlated logs look like (illustrative).

{
  "timestamp": "2026-10-02T07:01:12.481Z",
  "severity": "ERROR",
  "body": "gateway timeout after 700 ms",
  "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
  "span_id": "a3ce929d0e0e4736",
  "attributes": {"app.payment.provider": "acme-pay"},
  "resource": {"service.name": "payment-service", "service.version": "2.8.1"}
}

Log in structured form

JSON or key-value logs with consistent fields are far easier to search and correlate than free text.

Quick check: What does correlation add to a log record?

  • A random UUID unrelated to traces
  • A screenshot
  • The full source code
  • The trace ID and span ID of the active span
Answer

The trace ID and span ID of the active span — Jump from logs to traces.