Course contentsShow
← Software Engineering
Lesson 1136 of 1,93334. Logging and ObservabilityFree lesson

Metrics vs Logs vs Traces

Understanding the three pillars of observability and when to use each for system insights.

Metrics vs Logs vs Traces

What you'll learn: How the three pillars of observability—metrics, logs, and traces—differ and when to use each for understanding system behavior.

The Three Pillars of Observability

When monitoring distributed systems, you need different lenses to see what's happening. Think of observability like understanding traffic in a city: metrics are the speed limit signs showing aggregate data, logs are individual incident reports with details, and traces are GPS recordings following one car's complete journey.

Metrics are numerical measurements aggregated over time. They answer "how much" and "how often"—request count, error rate, CPU usage, response time percentiles. Metrics are cheap to store and excellent for dashboards, alerts, and spotting trends. Use metrics when you need high-level health indicators and real-time monitoring.

Logs are discrete event records with detailed context. They answer "what happened" and "why"—as you've learned through structured logging with key-value pairs and JSON formats. Logs provide rich detail for debugging specific failures but can be expensive at scale. Use logs when you need to investigate individual errors or audit specific events.

Traces track a single request's journey across multiple services. They answer "where did time go" and "what path did this take"—showing how a user request flows through microservices, databases, and external APIs. Traces connect related operations with correlation IDs. Use traces when debugging latency issues or understanding cross-service dependencies.

When to Use Each

  • Alert on metrics (error rate exceeds 5%)
  • Debug with logs (what caused request ID xyz to fail)
  • Diagnose with traces (why checkout takes 3 seconds)

These three pillars work together: metrics tell you something is wrong, logs tell you what went wrong, and traces tell you where it went wrong.

Key Takeaway: Metrics provide aggregate trends, logs give detailed event context, and traces map request flows—use all three together for complete system visibility.