Back to Technical Guides
Grafana & Time Series Reading time: 9 min

Correlating Metrics, Logs, and Traces in Grafana with Loki & Tempo

During a critical production incident, bouncing between separate browser tabs and copy-pasting IDs across disconnected tools is the primary reason for prolonged MTTR (Mean Time To Resolution). The architectural strength of the modern observability stack (Prometheus, Grafana Loki, and Grafana Tempo) lies in unifying telemetry into a seamless 1-click investigation flow: from the high-level symptom (Prometheus Metric) to the root cause statement (Loki Log) and the exact microservice bottleneck (Tempo Distributed Trace). Here is how to configure and master this workflow.

1. The Interconnected Observability Triad

Each pillar answers a distinct operational question during an incident:

1. Prometheus (Metrics): What & When?

Detects the anomaly: "HTTP 5xx error rate on service Checkout spiked to 8% at 14:02 UTC".

2. Loki (Logs): Why?

Explains the failure: "Connection timeout to payment database replica-02".

3. Tempo (Traces): Where & How Long?

Pinpoints the bottleneck: "Span db.query SELECT invoices stalled for 4,200 ms inside pod checkout-84df7".

2. Setting Up 1-Click Data Links: Prometheus to Loki

Empower on-call SREs to click directly on a spike within an alerting graph and immediately pivot into matching Loki logs:

# Inside panel settings (Data Links):
Title: View Logs for Service (${__series.name})
URL: /explore?left={"datasource":"Loki","queries":[{"expr":"{service=\"${__field.labels.service}\"} |= \"error\""}],"range":{"from":"${__from}","to":"${__to}"}}

3. Seamless Trace Extraction from Loki to Tempo (Derived Fields)

When microservices emit OpenTelemetry trace IDs inside structured JSON logs, Grafana can automatically transform those strings into direct interactive links to Tempo traces.

In your Loki data source configuration (via YAML provisioning or the Grafana UI):

# provisioning/datasources/loki.yaml
apiVersion: 1
datasources:
  - name: Loki
    type: loki
    url: http://loki:3100
    jsonData:
      derivedFields:
        - datasourceUid: tempo
          matcherRegex: '"trace_id":"([a-f0-9]+)"'
          name: TraceID
          url: '$${__value.raw}'

4. Live Crisis Investigation Workflow

1
Step 1 — Detection on Executive Dashboard:
The service error gauge triggers an alert. The engineer clicks on the error series and chooses the Loki Data Link.
2
Step 2 — Instant Filtering in Loki Explore:
Loki loads with the synchronized time range and level="error" filter. Log lines appear with a blue, clickable TraceID pill.
3
Step 3 — Root-Cause Isolation in Tempo:
Clicking the TraceID opens the distributed trace waterfall (Gantt chart). In seconds, the engineer identifies the failing downstream dependency.

Outcome: MTTR drops from 45 minutes to under 3 minutes without leaving Grafana or opening SSH terminals.

Master These Techniques in Our 2-Day Hands-On Course

This topic is practiced extensively in our Advanced Grafana Training (2-Day Course). Leave with production-ready templates and query optimization workflows tailored to your stack (On-site corporate or Live Virtual Classroom).

More Technical Guides

Kibana & Elasticsearch

ES|QL vs KQL vs Lucene: Which Query Language Should You Choose for Kibana?

Comprehensive architectural comparison between Lucene, KQL, and Elasticsearch's piped vector engine ES|QL: advantages, drawbacks, structural limits, and production recommendations.

Read Guide
Kibana & Elasticsearch

Runtime Fields in Kibana: Calculating Metrics Without Reindexing

Learn how to extract unmapped fields from raw logs or compute custom business indicators at query time using Painless and Kibana Lens without reindexing terabytes of data.

Read Guide
Kibana & Elasticsearch

How to Debug ES|QL LOOKUP JOIN Queries in Kibana

Type mismatch errors, silent empty join results, index mapping pitfalls, and memory limits: a step-by-step troubleshooting guide for LOOKUP JOIN and ENRICH in ES|QL.

Read Guide
Grafana & Time Series

5 Common PromQL Mistakes Slowing Down Your Grafana Dashboards

High cardinality explosions, unanchored regex matchers, misconfigured rate() windows, and heavy subqueries: how to audit and tune PromQL queries before they crash Prometheus.

Read Guide
Grafana & Time Series

Data Transformations in Grafana: The Guide to On-the-Fly Calculations

Join Prometheus time series with PostgreSQL metadata, compute SLA ratios across queries, or reshape data frames: master Grafana's internal transformation pipeline.

Read Guide