Skip to content
Snippets Groups Projects
Commit 9cc3d6d1 authored by Matthias Kaeppler's avatar Matthias Kaeppler
Browse files

Add request path to the current request Context

This allows us to include it in every log line
we emit in Workhorse.
parent 05ceec73
No related merge requests found
package requests
import (
"context"
"net/http"
)
type PathKey string
func WithRequestPathMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), PathKey("path"), r.URL.Path)))
})
}
......@@ -17,6 +17,7 @@ import (
"gitlab.com/gitlab-org/labkit/log"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/requests"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/secret"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/upload/destination/filestore"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/upload/destination/objectstore"
......@@ -194,6 +195,7 @@ func Upload(ctx context.Context, reader io.Reader, size int64, opts *UploadOpts)
}
logger := log.WithContextFields(ctx, log.Fields{
"path": ctx.Value(requests.PathKey("path")),
"copied_bytes": fh.Size,
"is_local": opts.IsLocal(),
"is_multipart": opts.IsMultipart(),
......
......@@ -23,6 +23,7 @@ import (
proxypkg "gitlab.com/gitlab-org/gitlab/workhorse/internal/proxy"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/queueing"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/redis"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/requests"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/secret"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/senddata"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/sendfile"
......@@ -136,6 +137,7 @@ func (u *upstream) route(method, regexpStr string, handler http.Handler, opts ..
// Add distributed tracing
handler = tracing.Handler(handler, tracing.WithRouteIdentifier(regexpStr))
}
handler = requests.WithRequestPathMiddleware(handler)
return routeEntry{
method: method,
......
//+build tools
//go:build tools
// +build tools
package main
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment