LLM Root Cause Analysis: Correlate Logs, Metrics, Traces

LLM Root Cause Analysis: Correlate Logs, Metrics, Traces

LLM root cause analysis works when the model never has to guess. Feed it the deploy history, one good PromQL result, filtered logs and a single trace, and it ranks likely causes with evidence instead of vibes. This post gives you the exact queries, a prompt template that forces cited hypotheses, and the guardrails that keep the model honest during an incident.

How LLM root cause analysis works

An LLM cannot see your cluster. It only knows what you paste into the prompt, so the quality of the answer is decided before the model runs, by the evidence you collect. The diagram below shows the pipeline: you gather a small, high-signal context pack, the model correlates it and ranks hypotheses, and a human confirms the cause before any fix.

Architecture: git and deploy history, Prometheus metrics, Loki logs and Tempo traces feed a small context pack; an LLM ranks hypotheses with citations; an SRE verifies and fixes through the change process
Read-only evidence in, ranked hypotheses out; the human decides.

Notice what is not in the diagram: the model never queries production directly, and it never applies a fix. You need kubectl and git, a Prometheus-compatible query API, Loki's LogCLI for logs, and Tempo or Jaeger for traces. Any CLI assistant that reads standard input can play the LLM role.

Step 1: start from the change

Most incidents follow a change: a deploy, a config edit, a flag flip, a certificate renewal. So the first correlation is always time. Did something change shortly before the symptoms started? The flowchart below shows the full investigation loop. The yes branch is the fast path, and it is why we check changes before opening a single dashboard.

Flowchart: alert fires, gather the last two hours of changes, decide whether a change lines up with the symptoms; if yes correlate the change with traces and logs, if no mine metrics and logs for anomalies; then the LLM ranks hypotheses and the SRE confirms
Change-first: the yes branch resolves most incidents fastest.

Start with the application's own repository and the rollout history of the affected service. Both are read-only and fast:

# What shipped in the last two hours, with the files each commit touched
git log --since="2 hours ago" --oneline --stat

# Which revision of the service is live, and when it rolled out
kubectl rollout history deployment/checkout -n shop

--since bounds the search to the incident window, and --stat shows the blast radius of each commit without opening the full diff. If revision 142 rolled out at 09:12 and the 5xx rate jumped at 09:14, you have a first hypothesis and a suspect commit in under a minute. If nothing changed, the flowchart's no branch widens the search to metric and log anomalies instead of staring at dashboards at random.

Step 2: collect metrics, logs and traces

Now build the evidence pack. The rule is small, filtered and tied to the suspect service: you are writing a prompt, not a data lake. Every query below already has the incident window and the service name baked in. I ran a 30M+ active-series open-source observability stack, and Grafana Tempo tracing helped cut MTTR by up to 80%; the trace is what turns a guess into a call graph.

# 1. Error rate for the suspect service (Prometheus HTTP API)
curl -s 'http://prometheus:9090/api/v1/query' \
  --data-urlencode 'query=sum(rate(http_requests_total{service="checkout",status=~"5.."}[5m]))'

# 2. Recent ERROR logs, trace IDs included (Loki's LogCLI)
logcli query '{app="checkout"} |= "ERROR"' --since=2h --limit=100

# 3. The full trace behind one failing request (Tempo API)
curl -s 'http://tempo:3200/api/traces/4bf92f3577b34da6a3ce929d0e0e4736'

The PromQL rate(...[5m]) smooths the error counter into a per-second rate you can quote in the prompt. logcli --since=2h --limit=100 keeps the log flood out of the context window; pipe through grep -oE 'trace_id=[a-f0-9]{32}' to pull candidate trace IDs straight from the log lines. The Tempo API returns the trace as JSON, one span per hop, so the model can see exactly which service in the chain got slow or started failing. If sampling drops your failing traces, the fix is usually tail-based sampling, covered in my trace sampling guide.

Step 3: the prompt that forces ranked hypotheses

A vague prompt gets a vague answer: "it could be the database". The fix is structure. Ask for exactly three hypotheses, each with evidence for, evidence against, and one check that would confirm or kill it. The "evidence against" line matters most, because it breaks the model's habit of agreeing with your leading theory.

You are an SRE assistant. Correlate the incident context below.

Rules:
- Output exactly 3 ranked hypotheses, most likely first.
- For each: evidence FOR (cite the input), evidence AGAINST,
  and one command to confirm or rule it out.
- Do not invent log lines, metrics or commits. If evidence is
  missing, say "no evidence" and name what to collect next.
- End with: recommended first action (rollback, config revert
  or none) and why.

CONTEXT
Alert: {name, started-at, SLO impact}
Changes: {git log and rollout history from step 1}
Metrics: {PromQL results from step 2}
Logs: {filtered logcli output}
Trace: {slow or failing spans from the Tempo trace}

Paste the outputs from steps 1 and 2 into the placeholders. Version this template in Git like any other code, because a prompt change is a behaviour change, and review each answer the way you would review a junior engineer's write-up. Good output looks like this:

H1 (likely): deploy v142 — 5xx began 2 min after rollout; the
    trace shows the checkout→payments span failing with 502.
    Confirm: roll back v142, watch the error rate 5 minutes.
H2 (possible): payments connection-pool exhaustion — "too many
    connections" logs began 08:50, before the deploy.
H3 (unlikely): node pressure — no evidence in events or metrics.
First action: roll back v142; H2 survives the rollback if real.

Notice that H2 carries evidence against the deploy theory, which is exactly what you want surfaced before you roll anything back. I automated this same flow end to end: a Slack bot that investigates incidents using documentation search, metric plugins and log APIs, then posts the ranked summary to the incident channel. The wider first-ten-minutes version is in AI incident triage: a co-pilot for the first 10 minutes.

Failure modes and guardrails

Three failure modes show up in every team that tries this. The diagram below maps each one to the guardrail that contains it.

Three failure modes mapped to guardrails: anchoring is countered by forcing three or more hypotheses with evidence against, hallucinated causes by requiring citations that get verified, context overload by a token budget with filtering at the source
Every failure mode has a cheap, mechanical guardrail.

Anchoring. If your prompt says "the deploy looks suspicious", the model will agree with you. Guardrail: never state your theory in the prompt, and always demand three hypotheses with evidence against. The model is a strong pattern-matcher, so make it match competing explanations instead of one.

Hallucinated causes. With thin context, models invent plausible log lines and config keys. Guardrail: require citations from the pasted inputs, and spot-check one before acting. If the model says "no evidence", believe it and collect more data; a confident "unknown" is a good answer.

Context overload. Pasting a megabyte of logs raises cost and latency while burying the signal. Guardrail: filter at the source and keep the pack under roughly 8k tokens. Track cost per investigation and answer latency like any other SLO; an RCA helper that takes five minutes is a dashboard with extra steps.

Common pitfalls

  • Letting the model declare the root cause. It proposes; the SRE disposes. Declaring a cause drives remediation, so a human confirms it.
  • Pasting secrets into prompts. Logs contain tokens and customer data. Redact before the prompt leaves your network.
  • Skipping the change check. Jumping straight to log diving wastes the strongest correlation signal you have.
  • Reusing stale evidence. Re-fetch context for every incident. Last week's root cause is not this week's.
  • No feedback loop. Record which hypothesis won; those labels become the eval set for prompt and model upgrades.

The last point is the LLMOps angle most teams miss: incidents are your evaluation data. Version the prompt, score each ranked output against the confirmed cause in the post-mortem, and the system measurably improves instead of drifting.

Key takeaways

  • Check changes first: most incidents follow one, and it is the fastest correlation.
  • Build a small evidence pack: one PromQL result, filtered logs, one trace.
  • Force three ranked hypotheses with evidence for and against, plus citations.
  • Guard against anchoring, hallucination and context overload with prompt structure and token budgets.
  • The LLM proposes; a human confirms the root cause and approves every production action.

Wiring this into Slack or your incident platform, with metric plugins and log APIs behind it, is the core of an AI SRE practice. See my AI and automation consulting if you want help building it.

Related articles