Prompt
I need traces that link directly to logs and metrics
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
To link traces directly to logs and metrics, you typically want correlated telemetry with a shared identifier such as:
- trace_id
- span_id
- optional service.name, deployment.environment, request_id
What to do
1) Add trace context to logs
Make sure every log line emitted during a request includes:
trace_idspan_id
Example log fields:
{
"timestamp": "2026-10-28T12:34:56Z",
"level": "info",
"message": "payment authorized",
"trace_id": "8f3c2a1b4d...",
"span_id": "4a1c9d..."
}
2) Add trace context to metrics
Metrics usually don’t carry per-event trace IDs directly, but you can correlate them by:
- tagging metrics with
service.name,operation,route,status_code - using exemplars if your backend supports them
- ensuring traces and metrics share the same resource attributes
Example metric labels:
service.name=checkouthttp.route=/payhttp.status_code=200
3) Use OpenTelemetry
OpenTelemetry is the easiest way to propagate context across traces, logs, and metrics.
Recommended setup:
- instrument your app with OTel
- enable context propagation
- configure your logging framework to inject trace context automatically
- export to a backend that supports trace-log-metric correlation
4) Backend support
Choose a backend/UI that can jump from:
- trace → related logs
- trace → related metrics
- log line → trace
- metric point → trace exemplar
Common options:
- Grafana + Tempo + Loki + Prometheus
- Datadog
- New Relic
- Honeycomb
- Elastic Observability
If you want “direct links”
You need your logs and traces to share the same trace context and your observability UI to render those links.
For example:
- from a trace span, show “View logs for this trace”
- from a log line, show “View trace”
- from a metric spike, show linked exemplars or related trace IDs
Minimal implementation checklist
- Instrument app with OpenTelemetry
- Inject
trace_idandspan_idinto logs - Use consistent resource attributes across traces/metrics/logs
- Enable exemplars for metrics if supported
- Verify backend correlation UI
If you want, I can give you:
- a language-specific example (Java, Python, Node, Go, .NET), or
- a Grafana/OTel reference architecture for traces → logs → metrics links.