Prompt
How do I correlate traces with logs when debugging an incident?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
A good way to correlate traces with logs during an incident is to make them share the same identifiers and then use those identifiers consistently in both systems.
What to look for
The most useful join keys are:
- Trace ID: ties together all spans for one request or transaction
- Span ID: identifies a specific operation within a trace
- Correlation / request ID: a custom ID often propagated across services
- Service name, host, pod, container, region: useful for narrowing down where the issue happened
- Timestamp: helps align events when IDs are missing
Best practice: inject trace context into logs
If your tracing system uses OpenTelemetry or similar, add trace context fields to every log line:
trace_idspan_idservice_nameenvironmentrequest_idif available
Then you can:
- Find an error log
- Copy its
trace_id - Open the trace in your tracing tool
- Inspect spans around the failure
- Search for other logs with the same
trace_id
During an incident: practical workflow
-
Start from the symptom
- Error spike, latency increase, failed job, etc.
-
Find a representative log
- Look for an exception, timeout, or warning around the incident time
-
Extract the trace ID
- If the log includes it, use it directly
-
Open the trace
- Check the full request path, downstream calls, and span durations
-
Pivot back to logs
- Search logs for the same
trace_idacross all services - Compare logs before, during, and after the problematic span
- Search logs for the same
-
Use timestamps if trace IDs are missing
- Filter logs by the same time window and service
- Narrow further using request path, user/session ID, or host
If you don’t already have trace IDs in logs
You’ll need instrumentation changes:
- Use distributed tracing libraries or OpenTelemetry SDKs
- Configure your logger to include active trace context automatically
- Propagate context across HTTP, gRPC, message queues, and background jobs
Example
A log line might look like:
{
"timestamp": "2026-10-19T10:15:22Z",
"level": "error",
"service": "checkout",
"trace_id": "4f3c2a1b9d...",
"span_id": "7e8d1f...",
"message": "Payment service timeout"
}
You can then:
- search traces for
trace_id=4f3c2a1b9d... - inspect spans from
checkouttopayment - search logs in
paymentfor the same trace ID
Common pitfalls
- Logging without trace context
- Losing context across async jobs or queues
- Sampling traces so the “bad” request isn’t captured
- Clock skew between services
- Inconsistent field names across teams
Bottom line
To correlate traces and logs effectively:
- propagate a shared request/trace ID
- include trace context in every log
- use timestamps and service metadata as backup
- pivot between logs and traces from the same incident window
If you want, I can also show:
- a concrete OpenTelemetry setup,
- how to do this in Kubernetes,
- or how to query traces and logs in tools like Datadog, Grafana, or Elastic.