Prompt
I'm building an observability stack and need logs correlated with metrics and traces
Latest observation
To correlate logs, metrics, and traces, you want to standardize on a shared set of identifiers and propagate them end-to-end.
Core approach
Use these common fields across all signals:
- trace_id
- span_id
- service.name
- service.version
- environment / deployment.environment
- request_id / correlation_id if you have one
- host.name, container.id, k8s.pod.name if relevant
Best practice: OpenTelemetry
The simplest path is to use OpenTelemetry (OTel) for instrumentation and export:
- Traces: OTel SDK/auto-instrumentation
- Metrics: OTel metrics API/exporter
- Logs: OTel logging integration or log enrichment via app/framework/logger config
OpenTelemetry helps because it:
- propagates trace context through services
- makes it easy to attach trace/span IDs to logs
- standardizes resource attributes across signals
How to correlate them
1) Propagate trace context
Ensure incoming requests carry W3C trace context headers:
traceparenttracestate
Your services should extract and continue that context.
2) Enrich logs with trace context
Configure your logger to automatically include:
- current
trace_id - current
span_id
So when a log entry is emitted during a request, it’s tied to the active trace.
3) Attach the same resource labels to metrics
Metrics should include the same service/resource tags:
service.nameservice.versionenvironment
If you use exemplars, you can also link specific metric datapoints to trace IDs.
4) Correlate in your backend UI
Choose a backend that can pivot between signals:
- Grafana + Tempo + Loki + Prometheus
- Datadog
- Elastic Observability
- New Relic
- Splunk Observability
In a good setup, you can click:
- from a log line → trace
- from a trace → related metrics
- from a metric spike → exemplar trace or related logs
Recommended architecture
A common stack:
- Instrumentation: OpenTelemetry SDK/auto-instrumentation
- Collector: OpenTelemetry Collector
- Metrics backend: Prometheus / Mimir / Cortex
- Traces backend: Tempo / Jaeger / vendor APM
- Logs backend: Loki / Elasticsearch / vendor log platform
Practical implementation tips
- Use structured logs, not plain text
- Put correlation fields at the top level of the log event
- Keep naming consistent across services
- Standardize time sync across hosts
- Include consistent service metadata in all exporters
- Sample traces carefully so logs still contain IDs for sampled and unsampled requests if needed
Minimal example of a correlated log record
{
"timestamp": "2026-10-21T12:34:56.789Z",
"level": "info",
"message": "payment processed",
"service.name": "checkout-api",
"environment": "prod",
"trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
"span_id": "00f067aa0ba902b7",
"request_id": "req-12345",
"user_id": "u-987"
}
If you want the fastest path
- Add OpenTelemetry to your services
- Emit structured logs with trace/span IDs
- Export metrics/traces/logs to one observability platform
- Ensure dashboards and trace-to-log linking are enabled
If you want, I can also give you:
- a reference architecture
- a Kubernetes setup
- or code examples for Java, Go, Python, Node.js, or .NET