logging and middleware chaining
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user