Summary
Standardise structured JSON logging across the Go API with consistent fields and level-based sampling.
Background & current behaviour
Handlers use slog unevenly (some slog.Error, some slog.ErrorContext), with inconsistent fields. There is no single logger config, no guaranteed request-id/key-id fields, and no sampling for hot paths.
Why this matters for MVP
Consistent, queryable logs are essential for operating the service. Ad-hoc logging makes incident response slow and risks leaking secrets.
Proposed implementation
- Configure a single JSON
slog handler at startup; inject common fields (service, level, request_id, api_key_id, route, status, latency_ms) via context/middleware.
- Guarantee raw API keys / secrets are never logged (redaction + a test).
- Add level-based sampling for high-volume debug logs.
- Document the log schema.
Acceptance criteria
Affected files / components
services/api/main.go (logger setup)
services/api/middleware/ (field injection)
Testing & verification
A test capturing log output and asserting fields + absence of secrets; sampling unit test.
Related / dependencies
Feeds log/trace correlation (#294) and request-id (#226).
Out of scope
Log shipping/aggregation infrastructure.
Target branch
All work for this issue MUST target the dev branch. Cut your feature branch from dev and open the pull request against dev, never against main. Any PR opened against main for this issue will be closed and asked to re-target dev.
Summary
Standardise structured JSON logging across the Go API with consistent fields and level-based sampling.
Background & current behaviour
Handlers use
slogunevenly (someslog.Error, someslog.ErrorContext), with inconsistent fields. There is no single logger config, no guaranteed request-id/key-id fields, and no sampling for hot paths.Why this matters for MVP
Consistent, queryable logs are essential for operating the service. Ad-hoc logging makes incident response slow and risks leaking secrets.
Proposed implementation
sloghandler at startup; inject common fields (service, level, request_id, api_key_id, route, status, latency_ms) via context/middleware.Acceptance criteria
Affected files / components
services/api/main.go(logger setup)services/api/middleware/(field injection)Testing & verification
A test capturing log output and asserting fields + absence of secrets; sampling unit test.
Related / dependencies
Feeds log/trace correlation (#294) and request-id (#226).
Out of scope
Log shipping/aggregation infrastructure.
Target branch
All work for this issue MUST target the
devbranch. Cut your feature branch fromdevand open the pull request againstdev, never againstmain. Any PR opened againstmainfor this issue will be closed and asked to re-targetdev.