Prompt
How do I correlate logs with metrics and traces during an incident?
Latest observation
A practical way to correlate logs, metrics, and traces during an incident is to move from “what is broken?” to “which requests, services, and dependencies caused it?” using shared identifiers and timestamps.
1) Start with the symptom in metrics
Metrics usually tell you where and when the problem started.
Look for:
- Latency spikes
- Error-rate increases
- Saturation issues
- Traffic drops or retries
- Dependency failures
Useful dimensions:
- service / pod / host
- endpoint / route
- region / AZ
- version / deployment
- customer segment, if relevant
This narrows the blast radius and gives you a time window.
2) Use traces to find the failing path
Once you know the affected service and time window, inspect traces to find:
- slow spans
- erroring spans
- the specific downstream dependency causing the issue
- whether the issue is in your code, a DB, cache, queue, or external API
Traces are the bridge between high-level metrics and low-level logs because they give you:
- trace_id
- span_id
- service call chain
- timing across components
3) Pivot from traces to logs using IDs
The most important correlation key is usually:
- trace_id
- sometimes also span_id
- request_id / correlation_id
If your logs include these fields, you can:
- take a failing trace
- copy the
trace_id - query logs for that ID
- inspect all logs for that exact request path
Example log query:
trace_id:"abc123"
If you don’t have trace IDs in logs, use:
- request ID
- user/session ID
- timestamp + service + instance/pod
- endpoint name
- error signature
But trace ID is by far the most reliable.
4) Use timestamps to align everything
Even with IDs, time matters.
When correlating:
- use the same time zone and clock source
- check for clock skew between hosts
- zoom into the incident window
- compare before/during/after the event
A good pattern is:
- metrics show spike at 14:03
- traces from 14:02–14:06 show failing requests
- logs from the same window reveal the exception or timeout
5) Correlate by service and deployment metadata
Add environment and release context to all three signal types.
Include labels/tags like:
- service name
- environment
- version/build SHA
- pod/container/host
- region/AZ
- tenant/customer
- endpoint
This helps answer:
- Did it start after a deploy?
- Is it isolated to one region?
- Is one pod or node unhealthy?
- Is it only affecting a subset of users?
6) A good incident workflow
A simple workflow:
- Alert fires from metrics
- Identify the impacted service and time window
- Open traces for the failing endpoint/request
- Extract trace_id from a bad trace
- Search logs for that trace_id
- Look for exceptions, retries, timeouts, and downstream failures
- Confirm with metric trends
- Check deployment and infrastructure changes
- Document the root cause and timeline
7) What “good correlation” looks like
Ideally, for every request you can connect:
- metrics: “error rate rose on checkout service”
- trace: “checkout → payment → inventory timed out”
- logs: “payment client returned 504 for trace_id=…”
- deployment: “new version rolled out 5 minutes earlier”
That lets you move from symptom to root cause quickly.
8) Best practices to make this easy next time
Instrument your systems so correlation is built in:
- propagate trace context across services
- include
trace_idandspan_idin logs automatically - use structured logging
- standardize labels across metrics/traces/logs
- sample traces intelligently, but keep error traces
- ensure NTP/clock synchronization
- tag logs with deployment version and instance metadata
9) Common failure modes
Correlation becomes hard when:
- logs are unstructured text
- trace context is not propagated
- different systems use different timestamps/time zones
- metrics lack service/version dimensions
- logs are sampled or discarded during load
- IDs are not consistent across services
10) Quick rule of thumb
- Metrics tell you where
- Traces tell you which request path
- Logs tell you why
If you want, I can also give you:
- a step-by-step incident triage checklist,
- a sample correlation query workflow for Datadog / Grafana / Splunk / Elasticsearch, or
- a reference architecture for instrumenting apps with OpenTelemetry.