Logs, Metrics, and Traces

1 min read
#go #observability #web
>> Series Navigation

Building Production Go Web Servers

  1. 1. ServeMux Foundations
  2. 2. Middleware Without Magic
  3. 3. Timeouts and Graceful Shutdown
  4. > 4. Logs, Metrics, and Traces

Observability starts with asking what you need to know during an incident.

Structured Logs

Log fields, not prose. A request log should include method, path, status, duration, and request ID.

slog.Info("request completed",
    "method", r.Method,
    "path", r.URL.Path,
    "status", status,
    "duration_ms", elapsed.Milliseconds(),
)

Metrics

Track request rate, latency, error rate, and dependency health. These four signals answer most first-response questions.

Traces

Distributed tracing is most valuable when a request crosses service boundaries. Keep span names stable and tags low-cardinality.