feat(platform): tag requests, logs and api errors with a request id

A well-formed X-Request-ID from a proxy is kept, otherwise a UUIDv7 is
generated. The ID is echoed in the response header, added to every log
record written with the request context and returned in API error
bodies.

Closes #44

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:20:57 +01:00
1 parent b6843330a8
commit c485d1a96f
6 files changed
+191 -12

No files matched your search

+5 -3
View File
@@ -8,18 +8,20 @@ import (
"time"
"github.com/gin-gonic/gin"
"git.zb-server.de/ZB-Server/uptimesebi/internal/requestid"
)
var quietPaths = map[string]bool{"/healthz": true, "/readyz": true}
// NewRouter returns a gin engine that logs requests and panics through log
// as JSON and writes nothing to stdout itself.
// NewRouter returns a gin engine that assigns request IDs, logs requests and
// panics through log as JSON and writes nothing to stdout itself.
func NewRouter(log *slog.Logger) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard
gin.DefaultErrorWriter = io.Discard
r := gin.New()
r.Use(accessLog(log), recovery(log))
r.Use(requestid.Middleware(), accessLog(log), recovery(log))
return r
}