Integrating Traces with Logs and Metrics
You'll learn how to unify observability by correlating trace IDs with logs and metrics for complete system visibility.
The Core Idea
The three pillars of observability—traces, logs, and metrics—are most powerful when connected. Integration means embedding trace IDs (and sometimes span IDs) into your logs and metric tags, creating bidirectional links that let you jump between systems seamlessly.
Think of it like detective work: metrics alert you to a problem (high latency), traces show you the suspicious transaction path, and logs reveal the exact error message—all connected by the same trace ID thread.
How Integration Works
Traces → Logs: When instrumenting your application, inject the current trace ID and span ID into your logging context. Every log statement automatically includes these identifiers.
Traces → Metrics: Add trace ID or service-level identifiers as metric labels (carefully, to avoid cardinality explosion). More commonly, use exemplars—sample trace IDs attached to metric data points.
Bidirectional Navigation: Your observability UI should let you:
- Click a metric spike and see example traces from that time
- View a trace span and jump to related logs filtered by trace ID
- Start from an error log and visualize the full request trace
The Unified Experience
When investigating an incident, you might:
- Notice elevated error rate in metrics
- Find a failing trace showing which service timed out
- Query logs using the trace ID to see the exact SQL query that deadlocked
Key Takeaway: Integrate the three pillars by embedding trace IDs in logs and using exemplars in metrics, creating a unified observability experience where you can pivot seamlessly between traces, logs, and metrics during investigations.