Skip to content

Commit

Permalink
[chore] include attemptno in httpclient logs (#2887)
Browse files Browse the repository at this point in the history
* include request attempt number in httpclient logs

* slightly nicer attempt number formatting
  • Loading branch information
NyaaaWhatsUpDoc committed Apr 30, 2024
1 parent 39b3a27 commit ec334ec
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/httpclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ type Request struct {
func WrapRequest(r *http.Request) Request {
var rr Request
rr.Request = r
rr.Entry = log.WithContext(r.Context()).
WithField("method", r.Method).
WithField("url", r.URL.String()).
WithField("contentType", r.Header.Get("Content-Type"))
entry := log.WithContext(r.Context())
entry = entry.WithField("method", r.Method)
entry = entry.WithField("url", r.URL.String())
if r.Body != nil {
// Only add content-type header if a request body exists.
entry = entry.WithField("contentType", r.Header.Get("Content-Type"))
}
// note our formatting library follows ptr values
entry = entry.WithField("attempt", &rr.attempts)
rr.Entry = entry
return rr
}

Expand Down

0 comments on commit ec334ec

Please sign in to comment.