Skip to content

Commit

Permalink
add request id to all responses
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Jul 4, 2023
1 parent bd9eb89 commit 6986cc4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion services/proxy/pkg/middleware/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
requestID := middleware.GetReqID(r.Context())
// add Request Id to all responses
w.Header().Set(middleware.RequestIDHeader, requestID)
wrap := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
next.ServeHTTP(wrap, r)

logger.Info().
Str("proto", r.Proto).
Str(log.RequestIDString, middleware.GetReqID(r.Context())).
Str(log.RequestIDString, requestID).
Str("remote-addr", r.RemoteAddr).
Str("method", r.Method).
Int("status", wrap.Status()).
Expand Down

0 comments on commit 6986cc4

Please sign in to comment.