Portal Community

Log-to-Trace (Loki → Tempo)

Configure Derived Fields in the Loki data source to make TraceIds in log lines clickable:

# grafana-provisioning/datasources/bizfirst-observe.yaml
datasources:
  - name: Loki
    type: loki
    url: http://loki:3100
    jsonData:
      derivedFields:
        - name: TraceID
          matcherRegex: '"traceId":"(\w+)"'   # Matches JSON log format
          url: '$${__value.raw}'
          datasourceName: Tempo               # Opens in Tempo data source
          urlDisplayLabel: "Open in Tempo"

After this configuration:

Trace-to-Log (Tempo → Loki)

Configure the Tempo data source to enable "Logs" links from trace spans:

# grafana-provisioning/datasources/bizfirst-observe.yaml
datasources:
  - name: Tempo
    type: tempo
    url: http://tempo:3200
    uid: tempo-uid
    jsonData:
      tracesToLogs:
        datasourceName: Loki             # Target data source
        tags: ['service.name', 'job']    # Labels to filter Loki stream
        spanStartTimeShift: -5m          # Start time shift for log query
        spanEndTimeShift: 5m             # End time shift for log query
        filterByTraceID: true            # Filter logs by traceId field
        filterBySpanID: false            # Don't filter by spanId (too specific)

      # Also enable node graph (service map)
      nodeGraph:
        enabled: true

After this configuration, from any trace in Grafana:

The Auto-Generated LogQL Query

# Auto-generated by Grafana when clicking "Logs" from a trace span:
{
  service_name="processengine",
  environment="production"
} |= "4bf92f3577b34da6a3ce929d0e0e4736"

# Time range: [span_start - 5m] to [span_end + 5m]
# This finds all logs from the processengine service that reference this TraceId
The Debugging Loop

With bi-directional correlation configured: 1) See alert in Slack, 2) Click link → Grafana dashboard, 3) Find error log in Loki Explore, 4) Click TraceId → Tempo trace detail, 5) Identify slow/failed span, 6) Click Logs → Loki scoped to that span's time and service, 7) Read the detailed error message and stack trace. Total time: under 3 minutes without leaving Grafana.