F-03: Observability slog + Prometheus (bookshelf-qqz.3) #3

Merged
zombor merged 1 commit from bd-bookshelf-qqz.3 into main 2026-05-20 17:09:48 +00:00
Owner

Summary

Adds internal/observability (F-03 of the Foundation epic bookshelf-qqz):

  • NewLogger(w io.Writer, format, level string) (*slog.Logger, error) — json|text handler, levels debug/info/warn/error (case-insensitive, "warning" alias, empty defaults to info). Errors on unknown values.
  • NewRegistry() *prometheus.Registry — a fresh registry (NOT the default — avoids ginkgo cross-test pollution) with Go runtime + process collectors pre-registered.
  • MetricsHandler(reg) http.Handlerpromhttp.HandlerFor wrapping the registry.
  • NewTraceID() string — 10 bytes from crypto/rand encoded as 16-char base32 (no padding). Panics on RNG failure (unrecoverable).

Takes simple primitives, not config types — main.go wiring lives in a later bead.

Test plan

  • go vet ./internal/observability/... passes
  • go test -race ./internal/observability/... passes
  • 100% statement coverage on internal/observability
  • Ginkgo specs cover logger formats, levels, error paths, registry collectors, /metrics HTTP output, trace ID format/uniqueness/RNG failure

Closes bead bookshelf-qqz.3 on merge.

## Summary Adds `internal/observability` (F-03 of the Foundation epic bookshelf-qqz): - `NewLogger(w io.Writer, format, level string) (*slog.Logger, error)` — json|text handler, levels debug/info/warn/error (case-insensitive, "warning" alias, empty defaults to info). Errors on unknown values. - `NewRegistry() *prometheus.Registry` — a fresh registry (NOT the default — avoids ginkgo cross-test pollution) with Go runtime + process collectors pre-registered. - `MetricsHandler(reg) http.Handler` — `promhttp.HandlerFor` wrapping the registry. - `NewTraceID() string` — 10 bytes from `crypto/rand` encoded as 16-char base32 (no padding). Panics on RNG failure (unrecoverable). Takes simple primitives, not config types — main.go wiring lives in a later bead. ## Test plan - [x] `go vet ./internal/observability/...` passes - [x] `go test -race ./internal/observability/...` passes - [x] 100% statement coverage on `internal/observability` - [x] Ginkgo specs cover logger formats, levels, error paths, registry collectors, /metrics HTTP output, trace ID format/uniqueness/RNG failure Closes bead bookshelf-qqz.3 on merge.
Add internal/observability with:
- NewLogger(w, format, level) returning a configured *slog.Logger
  (json|text handler, levels debug/info/warn/error, case-insensitive)
- NewRegistry returning a fresh *prometheus.Registry pre-loaded with
  Go runtime + process collectors (no global default registry — avoids
  ginkgo cross-test pollution)
- MetricsHandler wrapping the registry with promhttp.HandlerFor
- NewTraceID returning a 16-char base32 opaque ID (10 bytes of
  crypto/rand entropy)

Ginkgo specs achieve 100% coverage on the package.

bd: bookshelf-qqz.3
zombor force-pushed bd-bookshelf-qqz.3 from 16e9d932ef to 4dd228deae 2026-05-20 17:09:43 +00:00 Compare
zombor merged commit 4a4495c597 into main 2026-05-20 17:09:48 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zombor/pergamum!3
No description provided.