Metrics and Logging
Responsibility
internal/observability/metrics.go defines the Prometheus metrics;
internal/http/middleware/middleware.go (Logging, Metrics) emits access logs
and records them. Both backend and frontend use the same patterns.
Metrics
observability.Metrics holds:
- flaggo_http_requests_total (CounterVec) — labels method, path, status.
- flaggo_http_request_duration_seconds (HistogramVec) — labels method, path.
Registered on the default registerer in production (NewDefaultMetrics);
tests can use a fresh registerer. Scrape endpoint: GET /metrics
(promhttp.Handler()).
Logging
- Backend and frontend use
slog.NewJSONHandlerto stdout, level fromLOG_LEVEL(debug/info/warn/error). - Each request produces one
slog.Info("request", ...)line: method, path, status, duration_ms, request_id, remote. - Panics are logged via
Recoverywith panic value, path, request id.
Correlation
X-Request-ID is generated at the outermost middleware and echoed on the
response. The frontend propagates it to the backend, so one id spans gateway
access log, backend access log, and any error logs.
Related
openwiki/api/middleware.mdopenwiki/architecture/request-flow.md