During an incident, many things change at once, and correlation tools will happily rank all of them. Correlation says two signals moved together; causation says one made the other happen, and only causes are worth acting on. Moving from one to the other takes a short, repeatable discipline: check that the candidate sits upstream of the symptom in the dependency graph, that it changed before the symptom, that no common cause explains both, and then intervene (roll back, disable a flag, compare a canary) and watch whether the symptom follows. This lesson follows one checkout latency incident and shows the two classic mistakes: acting on the top correlated change, and missing the common cause behind several correlated signals.
Difficulty: Advanced · Know this first: Lesson 280, Lesson 336
By the end of this lesson you can work at four levels:
This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.
This bar adds up minutes from the alert to proven cause and restored latency. It is a worked example, not a measurement. The candidates and confounders hops decide how much time goes to the wrong fixes.
Pick the team's method, and whether a common cause such as a traffic surge is behind the symptom.
Three questions. No score is saved anywhere — this is just you against the material.
Causal analysis in operations grows in four levels: reading signals honestly, testing candidates, proving causes safely, and measuring the tools that suggest them.
At the basic level you know what correlation can and cannot tell you.
Where it breaks: treating a dashboard where many lines rose together as proof of anything.
Try it: Basic
Retries rose one minute after latency did. Cause or effect?
Now do it: Mark causes and effects on the timeline of a past incident.
At the intermediate level you can test each candidate quickly.
Try it: Intermediate
A change to a service that checkout never calls correlates at 0.9 with checkout latency. What do you conclude?
Now do it: Check one past incident's top suspect against traces.
At the advanced level you prove causes with interventions that are safe to make.
Try it: Advanced
Why change one thing at a time during mitigation?
Now do it: Write a rule into your incident runbook: one change, then watch.
At the master level correlation tools are measured against proven causes.
Trade-off: testing candidates takes minutes; acting on a score is faster until it is wrong, and every wrong action is another change in the middle of an incident.
Try it: Master
How do you know whether an AIOps tool's top suggestion can be trusted?
Now do it: Label the proven cause of your last ten incidents.
A quick check for a common cause: compare per-request latency at matching traffic levels, or compute a partial correlation that removes the effect of traffic (a sketch with pandas; columns are per-minute series):
import pandas as pd
df = pd.read_csv("minutes.csv") # columns: rps, gc_ms, latency_ms, deploy (0/1)
print(df[["gc_ms", "latency_ms"]].corr()) # high: they move together
# residuals after removing what traffic explains
for col in ("gc_ms", "latency_ms"):
slope = df[col].cov(df["rps"]) / df["rps"].var()
df[col + "_resid"] = df[col] - slope * df["rps"]
print(df[["gc_ms_resid", "latency_ms_resid"]].corr()) # near zero: traffic explained both
Tools that help: distributed traces (which span grew), change-event feeds joined to metrics (Kubernetes events, deploy and flag audit logs), change-point detection on per-request metrics, and canary analysis (Argo Rollouts, Flagger, Kayenta) that compares old and new versions under the same traffic, which is a controlled experiment by design.
Causal reasoning in practice is a checklist, not a statistics degree: in the path, before the symptom, not explained by a common cause, moved by an intervention, explained by a mechanism. Record which of the five a conclusion meets; "likely cause" and "proven cause" are different claims.
This is a composite of a failure pattern that keeps repeating; the details are illustrative. The deploy that took the blame for a marketing email.
Marketing sends are published to the change timeline, incident dashboards show per-request latency next to traffic, the runbook asks the common-cause question before any rollback, and the incident is labelled in the correlation tool's evaluation set.
Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.
Before you start: Linux with the standard text tools (sort, awk, uniq) and Python 3.10 or newer.
Type each one, read what it prints, and compare it with the note above it.
Put changes and alerts from two sources on one UTC timeline.
mkdir -p ~/labs/causal && cd ~/labs/causal printf '%s\n' '2026-11-27T09:01:10Z change deploy search v212' '2026-11-27T09:00:00Z change marketing email to 2,000,000 customers' > changes.log printf '%s\n' '2026-11-27T09:01:40Z alert checkout p99 2.1s' '2026-11-27T09:02:05Z alert gc-pause high' '2026-11-27T09:02:30Z alert autoscaler 12 to 30 pods' > alerts.log sort changes.log alerts.log
Count requests per minute from an access log, to check for a common cause.
awk 'BEGIN { for (m = 0; m < 6; m++) { n = (m < 1) ? 1000 : 3000; for (i = 0; i < n; i++) printf "2026-11-27T09:%02d:00Z GET /checkout\n", m } }' > access.log
cut -c1-16 access.log | uniq -cTopology check: keep only changes and alerts for services in checkout's request path.
printf '%s\n' checkout payments search postgres > checkout-path.txt sort changes.log alerts.log | grep -F -w -f checkout-path.txt
causation.pyThis program builds half an hour of per-minute metrics in which a traffic surge and an unrelated deploy start in the same minute. It shows that GC pauses and the deploy both correlate strongly with latency, that the GC correlation disappears once traffic is accounted for, that retries rose after latency (an effect, not a cause), and that only interventions separate the deploy from the surge. Save it as causation.py, then run it.
# causation.py
from statistics import mean
MIN = range(30)
rps = [1000 if m < 10 else 3000 for m in MIN] # a marketing email lands at minute 10
deploy = [0 if m < 10 else 1 for m in MIN] # an unrelated deploy, the same minute
capacity = [1 if m < 25 else 2 for m in MIN] # capacity doubled at minute 25
n1 = [((m * 7) % 5) - 2 for m in MIN] # small fixed wobbles, different per signal
n2 = [((m * 3) % 4) - 1.5 for m in MIN]
gc = [4 + rps[m] / 250 + n2[m] for m in MIN]
lat = [200 + 0.25 * rps[m] / capacity[m] + n1[m] * 6 for m in MIN]
retries = [0] + [max(0, int((lat[m - 1] - 500) / 20)) for m in MIN if m > 0]
def corr(x, y):
mx, my = mean(x), mean(y)
sxy = sum((a - mx) * (b - my) for a, b in zip(x, y))
return sxy / (sum((a - mx) ** 2 for a in x) * sum((b - my) ** 2 for b in y)) ** 0.5
def without(y, x): # what is left of y after removing what x explains
mx, my = mean(x), mean(y)
slope = sum((a - mx) * (b - my) for a, b in zip(x, y)) / sum((a - mx) ** 2 for a in x)
return [b - slope * a for a, b in zip(x, y)]
w = range(20) # before any intervention
pick = lambda s: [s[m] for m in w]
print(f"correlation with latency: GC {corr(pick(gc), pick(lat)):.2f}, deploy {corr(pick(deploy), pick(lat)):.2f}")
print(f"after removing traffic: GC {corr(without(pick(gc), pick(rps)), without(pick(lat), pick(rps))):.2f} -> traffic explained both")
print(f"deploy versus traffic: {corr(pick(deploy), pick(rps)):.2f} -> the data alone cannot separate them")
print()
first = lambda s, limit: next(m for m in MIN if s[m] > limit)
print(f"latency over 600 ms from minute {first(lat, 600)}, retries from minute {first(retries, 0)} -> retries are an effect")
print()
for label, lo, hi in (("surge, deploy live", 15, 20), ("surge, deploy rolled back", 20, 25), ("surge, capacity doubled", 25, 30)):
print(f" {label:<27} mean latency {mean(lat[lo:hi]):5.0f} ms")
print("the rollback changed nothing; adding capacity did: traffic was the cause")
Run it, and you should see this output:
$ python3 causation.py correlation with latency: GC 0.96, deploy 1.00 after removing traffic: GC 0.00 -> traffic explained both deploy versus traffic: 1.00 -> the data alone cannot separate them latency over 600 ms from minute 10, retries from minute 11 -> retries are an effect surge, deploy live mean latency 950 ms surge, deploy rolled back mean latency 950 ms surge, capacity doubled mean latency 575 ms the rollback changed nothing; adding capacity did: traffic was the cause
The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/correlation-versus-causation-in-incident-analysis && cd ~/labs/correlation-versus-causation-in-incident-analysis) and save this as lab.sh.
#!/usr/bin/env bash
# The Linux steps of "Correlation Versus Causation in Incident Analysis: From "Changed at the Same Time" to Proven Cause", as one script (save it as lab.sh).
#
# ./lab.sh run every step, in order
# ./lab.sh 2 4 run only steps 2 and 4
# ./lab.sh --list list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.
STEPS=(
'Put changes and alerts from two sources on one UTC timeline.'
'Count requests per minute from an access log, to check for a common cause.'
'Topology check: keep only changes and alerts for services in checkout'\''s request path.'
)
step_1() {
mkdir -p ~/labs/causal && cd ~/labs/causal
printf '%s\n' '2026-11-27T09:01:10Z change deploy search v212' '2026-11-27T09:00:00Z change marketing email to 2,000,000 customers' > changes.log
printf '%s\n' '2026-11-27T09:01:40Z alert checkout p99 2.1s' '2026-11-27T09:02:05Z alert gc-pause high' '2026-11-27T09:02:30Z alert autoscaler 12 to 30 pods' > alerts.log
sort changes.log alerts.log
}
step_2() {
awk 'BEGIN { for (m = 0; m < 6; m++) { n = (m < 1) ? 1000 : 3000; for (i = 0; i < n; i++) printf "2026-11-27T09:%02d:00Z GET /checkout\n", m } }' > access.log
cut -c1-16 access.log | uniq -c
}
step_3() {
printf '%s\n' checkout payments search postgres > checkout-path.txt
sort changes.log alerts.log | grep -F -w -f checkout-path.txt
}
# print a step that has to be run by hand, instead of running it
by_hand() {
echo " (run this one yourself: $1)"
sed 's/^/ /'
}
RESULTS=()
run_step() {
local n=$1 start=$SECONDS code
printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
"step_$n"
code=$?
RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}
summary() {
echo
echo "== summary"
local r
for r in "${RESULTS[@]}"; do echo " $r"; done
}
case "${1:-}" in
-h|--help) sed -n '2,6p' "$0"; exit 0 ;;
--list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac
[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
echo "there is no step '$n'; try --list" >&2
exit 2
fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done
Then make it executable and run it:
chmod +x lab.sh ./lab.sh --list # the steps ./lab.sh # every step, then a summary of exit codes and times ./lab.sh 2 3 # only steps 2 and 3
New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.
grep, awk, cut, sort, uniq, mkdir, cd, Pipes, Redirection, If...Else.Your AIOps tool suggests a probable cause for every incident, and on-call engineers act on it about half the time. Design the analysis practice and the measurement of the tool.
Which steps must an engineer take before acting on a suggestion? Which data must the incident view show (traces, change feed, traffic, per-request metrics)? Which interventions are preferred, in which order? How are conclusions recorded? How is the tool's precision measured and reported?
Say 300 incidents a year, a change feed of 2,000 changes a week, and a tool that ranks five candidates per incident.
A five-question check (path, order, common cause, intervention, mechanism) in the incident template; an incident view joining traces, the change feed, business events, and per-request metrics; interventions ordered from flag off to traffic shift to rollback, one at a time; a postmortem evidence table with confidence; labelled causes feeding a monthly report of top-1 and top-3 precision for the tool.
The checks take a few minutes per incident and save the much larger cost of wrong actions; labelling causes takes postmortem effort and is the only way to know whether the tool helps.
Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.
| Scenario | Where | Effect | What goes wrong |
|---|---|---|---|
| Act on top correlation | Hop 3: Candidates | Breaks | The team acts in score order. It rolls back the CDN rule (no change), shrinks the cache TTL (no change), restarts the checkout pods (worse for a few minutes). 95 minutes pass. |
| Miss the common cause | Hop 6: Confounders | Breaks | The search deploy landed in the same minute as the marketing email, so the team rolls it back. Latency does not improve. |
The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.
Last updated . Next review due by November 2027. Found something out of date? Tell me.