feat(observability): structured logging foundation and error taxonomy - #30
Open
kiro-agent[bot] wants to merge 1 commit into
Open
feat(observability): structured logging foundation and error taxonomy#30kiro-agent[bot] wants to merge 1 commit into
kiro-agent[bot] wants to merge 1 commit into
Conversation
…nomy - drop GCP Cloud Logging severity/message renaming; keep slog defaults (level/msg/time) so Grafana/Loki level detection works - decouple log format (LOG_FORMAT) from APP_ENV so the JSON pipeline can be exercised locally - add ContextHandler that enriches every log line with trace_id/request_id from the request context - add RequestID middleware (outermost) that reads W3C traceparent or generates a request id and echoes X-Request-Id - logging middleware: numeric duration_ms, low-cardinality route vs raw path, response bytes, skip SSE, context-aware - error taxonomy: severity by status class (5xx error / 429 info / 4xx warn) and a stable error_kind fingerprint for log-based error grouping - add optional Code field to HTTPError for machine-readable error kinds - config: add observability env vars with safe defaults (no new required) Co-authored-by: Ami <github@ccrsxx.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was created by @kiro-agent on behalf of @ccrsxx 👻
Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro Web
Summary
First PR in the observability roadmap (Phase 0/1 prerequisite). Makes the API's logs immediately useful in Loki/Grafana and lays the correlation groundwork for tracing. Additive, no new dependencies, no behavior change for clients.
Logging
severity/messagerenaming (leftover from Cloud Run). Keeps slog defaults (level/msg/time) so Grafana level detection and Logs Drilldown work.LOG_FORMAT(json|text) so the JSON pipeline can be tested locally instead of only in prod.ContextHandlerslog middleware enriches every log line withtrace_id/span_id/request_id/routepulled from the request context — existingslog.*Contextcalls across all feature packages become correlated for free.service_name+deployment_environmenton every line (label convention).Request correlation
RequestIDmiddleware (registered outermost): reads a W3Ctraceparent, an inboundX-Request-Id, or generates a UUID; echoesX-Request-Idback so users can quote it when reporting issues.Request logging middleware
duration_msis now a number (was the string"1.5ms", unqueryable).r.Pattern) alongside the rawpath, plus responsebytes./sseso long-lived streams don't corrupt latency aggregations.Error taxonomy (Loki-based error reporting foundation)
error, 429 →info(expected/high-volume), other 4xx →warn. Solevel="error"finally means "my fault".error_kindfingerprint for grouping:HTTPError.Code→http_<status>→ Go type name for unhandled → first application stack frame for panics.Codefield added toHTTPError(backwards compatible; all call sites use named literals).Testing
go build ./...✅go test ./...✅ all packages passgo vet✅ /gofmt✅ cleangolangci-lintcould not run in the sandbox (its binary was built with Go 1.24, below this repo's 1.26 target). Please confirm CI lint locally.Follow-ups (separate PRs)
otelpgx+ client transports (adds deps)/metrics+/healthzon an internal-only port, Go runtime + custom SSE/cache/upstream metricshomelabrepo: LGTM stack (docker/observability+docker/observability-agent)