expose the embedded log fields in httpclient.Request{}

This commit is contained in:
kim 2024-04-05 22:35:16 +01:00
parent f17ef91fb9
commit 4811ded078
3 changed files with 8 additions and 6 deletions

View file

@ -264,12 +264,12 @@ func (c *Client) DoOnce(r *Request) (rsp *http.Response, retry bool, err error)
if rsp != nil {
// Log successful rsp.
r.log.Info(rsp.Status)
r.Entry.Info(rsp.Status)
return
}
// Log any errors.
r.log.Error(err)
r.Entry.Error(err)
switch {
case !retry:

View file

@ -32,9 +32,6 @@ const (
// Request wraps an HTTP request
// to add our own retry / backoff.
type Request struct {
// log entry fields.
log log.Entry
// Current backoff dur.
backoff time.Duration
@ -46,6 +43,9 @@ type Request struct {
// be attempted.
done bool
// log fields.
log.Entry
// underlying request.
*http.Request
}
@ -55,7 +55,7 @@ type Request struct {
func WrapRequest(r *http.Request) Request {
var rr Request
rr.Request = r
rr.log = log.WithContext(r.Context()).
rr.Entry = log.WithContext(r.Context()).
WithField("method", r.Method).
WithField("url", r.URL.String()).
WithField("contentType", r.Header.Get("Content-Type"))

View file

@ -79,6 +79,7 @@ func (t *transport) BatchDeliver(ctx context.Context, obj map[string]interface{}
reqs = append(reqs, req)
}
// Push prepared request list to the delivery queue.
t.controller.state.Workers.Delivery.Queue.Push(reqs...)
// Return combined err.
@ -109,6 +110,7 @@ func (t *transport) Deliver(ctx context.Context, obj map[string]interface{}, to
return err
}
// Push prepared request to the delivery queue.
t.controller.state.Workers.Delivery.Queue.Push(req)
return nil