Skip to content

Commit

Permalink
[CHORE] considering X-Forwarded-For on HTTP Logging
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Takashi <[email protected]>
  • Loading branch information
nicolastakashi committed Apr 24, 2024
1 parent 7c8fe85 commit 04455e4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/logging/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ func (m *HTTPServerMiddleware) preCall(name string, start time.Time, r *http.Req

func (m *HTTPServerMiddleware) postCall(name string, start time.Time, wrapped *httputil.ResponseWriterWithStatus, r *http.Request) {
status := wrapped.Status()

remoteAddr := r.Header.Get("X-Forwarded-For")
if remoteAddr == "" {
remoteAddr = r.RemoteAddr
}

logger := log.With(m.logger,
"http.method", fmt.Sprintf("%s %s", r.Method, r.URL),
"http.request_id", r.Header.Get("X-Request-ID"),
"http.user_agent", r.Header.Get("User-Agent"),
"http.status_code", fmt.Sprintf("%d", status),
"http.time_ms", fmt.Sprintf("%v", durationToMilliseconds(time.Since(start))),
"http.remote_addr", r.RemoteAddr,
"http.remote_addr", remoteAddr,
"thanos.method_name", name)

logger = m.opts.filterLog(logger)
Expand Down

0 comments on commit 04455e4

Please sign in to comment.