Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request id to all responses #6715

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/add-request-id-response.md
Original file line number Diff line number Diff line change
@@ -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
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