Prompt
How do I correlate logs metrics and traces for one incident
Latest observation
To correlate logs, metrics, and traces for one incident, the goal is to use a shared set of identifiers and timestamps so you can move from “something is wrong” to “this exact request, service, and code path caused it.”
Core idea
For each event in your system, try to include:
- Trace ID — links logs and traces for a single request or workflow
- Span ID — identifies the specific operation inside a trace
- Service / instance / pod / host identifiers
- Timestamp in a consistent time zone, ideally UTC
- Request / correlation ID if you have one at the edge
- Deployment version / build number
- User / tenant / account ID if relevant and safe to store
Practical workflow for one incident
1) Start from the symptom in metrics
Use metrics to detect the incident:
- latency spike
- error rate increase
- saturation / CPU / memory issue
- throughput drop
Narrow it to:
- the time window
- the service
- the specific dimension if available:
- endpoint
- pod
- zone
- tenant
- version
Example:
checkout-api500s started at10:42–10:55 UTC- p95 latency doubled on
/payments/authorize
2) Jump from metric anomaly to traces
Use traces to find:
- the slowest or failing requests
- the common span where time is spent
- whether failure is in your service, downstream dependency, or network
Look for:
- traces in the same time window
- same endpoint / operation
- same version / instance
- high latency or errors
From a trace you should identify:
- trace ID
- failing span
- downstream call causing delay/failure
3) Use trace IDs to pull logs
Once you have a trace ID, search logs for that ID.
If logs are structured, this becomes easy:
{
"timestamp": "2026-10-28T10:43:12.123Z",
"service": "checkout-api",
"level": "error",
"trace_id": "3f2c9a...",
"span_id": "a91b4...",
"message": "payment authorization failed",
"order_id": "12345"
}
Search by:
trace_idspan_idrequest_idorder_idoruser_idif needed
This gives you:
- application error messages
- stack traces
- input/output details
- retry behavior
- timeout reasons
Best practices to make correlation work
A. Use distributed tracing everywhere
Instrument services with OpenTelemetry or your APM tool so traces are propagated across:
- API gateway
- backend services
- async jobs
- queues
- databases
- external APIs
Make sure trace context propagates between services.
B. Put trace IDs into logs automatically
Every log line should include:
trace_idspan_idservice_nameenvversion
That way, even if you start from logs, you can jump back to the trace.
C. Use consistent timestamps
- Prefer UTC everywhere
- Ensure NTP/time sync on hosts
- Store milliseconds or nanoseconds if possible
Bad time sync can make incident correlation very hard.
D. Tag metrics with the right dimensions
Metrics should include labels like:
- service
- endpoint
- status code
- region
- version
- instance
Be careful not to add high-cardinality labels like:
- request_id
- user_id
- trace_id
Those belong in logs/traces, not metrics.
E. Add deployment/version markers
Incidents often line up with a deployment. Track:
- build version
- git SHA
- rollout time
- feature flag state
This helps answer:
- “Did the issue start after deploy X?”
- “Is it only affecting one version?”
Recommended incident correlation path
A good sequence is:
- Metrics alert fires
- Identify service + time + endpoint
- Find sample traces in that window
- Pick a slow/error trace
- Use the trace ID to fetch logs
- Inspect logs around the failing span
- Compare with metrics for saturation, dependency failures, or retries
- Check deployment/version and recent config changes
Example
Incident:
- checkout latency increases
- error rate rises on payment authorization
Correlation:
- Metrics show p95 latency spike at
10:42 UTC - Trace shows slow span in
payment-service -> external-gateway - Trace ID is
abc123 - Search logs with
trace_id=abc123 - Logs show timeout calling gateway:
upstream timeout after 5s
- Metrics show gateway dependency latency also spiking
- Deployment marker shows new release at
10:40 UTC - Root cause: new release caused retry storm or bad timeout config
If you want a simple implementation checklist
- Add distributed tracing
- Inject trace/span IDs into every log line
- Standardize timestamps in UTC
- Add service/version/env labels to metrics
- Propagate context through async boundaries
- Use a dashboard linking metrics → traces → logs
- Capture deployment markers and feature flag changes
Short version
To correlate logs, metrics, and traces for one incident:
- use metrics to find when/where it happened,
- use traces to find the exact failing request path,
- use logs with the same trace ID/span ID to see details,
- and include service, version, timestamp, and request context in all three.
If you want, I can also give you:
- a step-by-step incident runbook,
- a sample OpenTelemetry setup, or
- an example in Datadog / Grafana / Elastic / New Relic.