From f5bcc0a41bc4bd4570b726f5c392ce5567cb7b06 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Tue, 4 Jul 2023 17:08:29 +0200 Subject: [PATCH] add request id to all responses Signed-off-by: Michael Barz --- changelog/unreleased/add-request-id-response.md | 5 +++++ services/proxy/pkg/middleware/accesslog.go | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/add-request-id-response.md diff --git a/changelog/unreleased/add-request-id-response.md b/changelog/unreleased/add-request-id-response.md new file mode 100644 index 00000000000..b75f0cd0c4b --- /dev/null +++ b/changelog/unreleased/add-request-id-response.md @@ -0,0 +1,5 @@ +Enhancement: Add X-Request-Id to all responses + +We added the X-Request-Id to all responses to increase the debuggability of the platform. + +https://github.com/owncloud/ocis/pull/6715 diff --git a/services/proxy/pkg/middleware/accesslog.go b/services/proxy/pkg/middleware/accesslog.go index ff41eaf6b86..00afc71c436 100644 --- a/services/proxy/pkg/middleware/accesslog.go +++ b/services/proxy/pkg/middleware/accesslog.go @@ -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()).