Add RequestID middleware for tracing and enhance logging with request IDs

This commit is contained in:
2025-04-21 00:03:00 -05:00
parent 9fd027fcda
commit d53afa4903
5 changed files with 59 additions and 2 deletions

View File

@ -26,8 +26,11 @@ func Logging(next http.Handler) http.Handler {
statusCode: http.StatusOK,
}
// Get request ID from header (set by RequestID middleware)
requestID := r.Header.Get(RequestIDHeader)
next.ServeHTTP(wrapped, r)
log.Println(wrapped.statusCode, r.Method, r.URL.Path, time.Since(start))
log.Printf("[%s] %d %s %s %v", requestID, wrapped.statusCode, r.Method, r.URL.Path, time.Since(start))
})
}
}