Skip to content

Practical software architecture · Part 8 of 10

Observability: logs, metrics and traces

Logs tell you what happened, metrics tell you how much, traces tell you where time went. Together they let you debug production without guessing.

· 2 min read

architectureobservability

Monitoring answers questions you thought of in advance. Observability is being able to ask new questions about a running system without shipping new code. It rests on three kinds of data.

Logs

A log is a record of an event: a request failed, a job started. Write structured logs, meaning JSON with fields, rather than free text, so you can filter and aggregate by user, request id or status.

JSON
{"level":"error","msg":"payment failed","request_id":"abc123","user_id":42,"provider":"card","duration_ms":812}

Never log passwords, tokens or full card numbers, and be careful with personal data.

Metrics

Metrics are numbers over time: requests per second, error rate, queue depth, memory. They are cheap to store and perfect for dashboards and alerts. A useful starting set for any service is the RED method: Rate, Errors and Duration of requests.

For duration, look at percentiles instead of the average. An average of 200 ms can hide a slowest one percent of requests that take ten seconds. Track p50, p95 and p99.

Traces

A trace follows one request across services as a tree of spans, each with a start time and duration. When a page is slow, the trace shows whether the time went to the database, a downstream API or your own code. A trace id passed along each call, and included in logs, ties everything together.

How they work together

  1. An alert fires on a metric: error rate is up.
  2. A trace of a failing request shows which dependency is slow.
  3. Logs with the same request id explain the exact error.

Alerting

  • Alert on symptoms users feel, such as errors and latency, not on every internal cause such as CPU.
  • Every alert needs an owner and a documented first step.
  • Remove or tune alerts that fire without action. Noisy alerts teach people to ignore them.

Takeaway

Emit structured logs with a request id, track rate, errors and duration, and add tracing once requests cross several services. Debug with evidence, not guesses.

A knowledge article, drafted with AI assistance and checked with automated tests. It is general background, not a description of my own experience or of any client's work.

Comments

Leave a comment

No account or email needed. Comments appear after review. A one-way hash of your IP address is kept for 30 days to fight spam, then erased.