internal/website/docs/observability.md
Observability in Go Micro spans logs, metrics, and traces. The goal is rapid insight into service behavior with minimal configuration.
The default logger can be replaced. Use env vars to adjust level:
MICRO_LOG_LEVEL=debug go run main.go
Recommended fields:
service – service nameversion – release identifiertrace_id – propagated context idspan_id – current operation idPatterns:
Example (pseudo-code):
// Wrap handler to record metrics
func MetricsWrapper(fn micro.HandlerFunc) micro.HandlerFunc {
return func(ctx context.Context, req micro.Request, rsp interface{}) error {
start := time.Now()
err := fn(ctx, req, rsp)
latency := time.Since(start)
metrics.Inc("requests_total", req.Endpoint(), errorLabel(err))
metrics.Observe("request_latency_seconds", latency, req.Endpoint())
return err
}
}
Distributed tracing links calls across services.
Propagation strategy:
Start with only structured logs. Add metrics when operating multiple services. Introduce tracing once debugging multi-hop latency or failures.
| Scale | Suggested Stack |
|---|---|
| Dev | Console logs only |
| Staging | Logs + basic metrics (Prometheus) |
| Prod (basic) | Logs + metrics + sampling traces |
| Prod (complex) | Full tracing + profiling + anomaly detection |
| Symptom | Cause | Fix |
|---|---|---|
| Missing trace IDs in logs | Context not propagated | Ensure wrappers add IDs |
| Metrics server empty | Endpoint not scraped | Verify Prometheus config |
| High cardinality metrics | Dynamic labels | Reduce labeled dimensions |