logging and middleware chaining
Some checks failed
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2025-05-15 12:34:32 -04:00
parent e76386d10a
commit f9a8e9666e
11 changed files with 168 additions and 100 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"log/slog"
"os"
"gitea.michaelthomson.dev/mthomson/habits/internal/middleware"
)
type ContextHandler struct {
@@ -11,8 +13,8 @@ type ContextHandler struct {
}
func (h *ContextHandler) Handle(ctx context.Context, r slog.Record) error {
if requestID, ok := ctx.Value("trace_id").(string); ok {
r.AddAttrs(slog.String("trace_id", requestID))
if requestID, ok := ctx.Value(middleware.TraceIdKey).(string); ok {
r.AddAttrs(slog.String(string(middleware.TraceIdKey), requestID))
}
return h.Handler.Handle(ctx, r)
}