Observability Best Practices
Production Go services stay debuggable when logs, metrics, traces, probes, and shutdown behavior follow shared rules that protect on-call engineers and observability budgets.
Search across all documentation pages
Production Go services stay debuggable when logs, metrics, traces, probes, and shutdown behavior follow shared rules that protect on-call engineers and observability budgets.
request_id and trace_id on every request-scoped log line. On-call can jump from log line to trace without grep gymnastics.err, http.route, user_id). Consistent schemas make cross-service queries possible./users/{id} prevents unbounded series from IDs.main, not per request. Duplicate registration panics and duplicates series./metrics on an admin listener or restricted network. Public scrape leaks internal operational detail.probe=true. Probe QPS skews rate and duration aggregates.context.Context through HTTP handlers, gRPC, and database calls. Broken context breaks trace trees.span.RecordError. Failed traces must remain visible under sampling.TracerProvider.Shutdown on exit. Buffered spans drop on SIGKILL without flush.service.name and deployment environment resource attributes. Backends group traces per team and stage./healthz and /readyz in auth middleware. Kubelet probes do not send bearer tokens.http.Server.Shutdown with a bounded context. Rolling deploys drain in-flight work.terminationGracePeriodSeconds. Avoid SIGKILL mid-request.os.Getenv in handlers. Tests and clarity suffer from hidden env access.go test with slog test handlers for critical middleware. Regressions in request logging are caught in CI.Route template labels, readiness vs liveness separation, secret redaction, and SIGTERM shutdown are non-negotiable for HTTP services.
Yes for logs, metrics, tracing, and shutdown.
Replace probe rules with queue lag metrics and consumer health checks.
Code review plus lint rules that ban WithLabelValues using dynamic path segments or user identifiers.
Briefly during targeted incidents with explicit toggles and time-bounded feature flags, never as a default.
The explainer teaches why the pillars exist.
This list is the enforceable checklist for teams shipping services.
Prefer slog for new code unless profiling proves zap is required on your hot path.
Request total counter, duration histogram, and process Go collector metrics cover most API SLO dashboards.
After doubling traffic, adding a dependency, or any observability-related incident.
Yes.
Framework choice does not change probe, shutdown, or cardinality discipline.
Copy a service template with middleware, metrics registration, probes, and shutdown already wired.
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026