Linking Tempo traces to Loki logs in Grafana adds a navigation path from a span to log lines from the same request or service. It is useful when a trace shows where latency or an error happened and the matching logs contain the application detail.
Trace-to-log linking is configured on the Tempo data source, while log-to-trace linking is configured on the Loki data source. Both sides need to agree on the data source UIDs and on the fields that connect records, such as service.name and a trace ID in the log body.
Do not use trace IDs as Loki labels. Use low-cardinality labels such as service, namespace, or cluster for stream selection, then match trace IDs from structured metadata or message content.
$ curl --silent --user admin:admin http://127.0.0.1:3000/api/datasources
[
{"uid":"tempo","name":"Tempo","type":"tempo"},
{"uid":"loki","name":"Loki","type":"loki"}
]
Widen the window when log writes happen noticeably before or after span timestamps.
The Loki label must match the actual stream label. A mismatch returns no logs without proving that the trace has no matching log lines.
name: TraceID
matcherRegex: trace_id=([0-9a-fA-F]{32})
datasourceUid: tempo
url: ${__value.raw}
{service_name="checkout-api"} |= "5b8efff798038103d269b633813fc700"
If one direction works but the other does not, review the data source UID and regular expression on the failing side.