health: use request context when logging

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2023-10-27 15:34:10 -04:00
parent 97f8a6c959
commit 8b889c04bd

View file

@ -282,7 +282,7 @@ func Handler(handler http.Handler) http.Handler {
func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks map[string]string) { func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks map[string]string) {
p, err := json.Marshal(checks) p, err := json.Marshal(checks)
if err != nil { if err != nil {
dcontext.GetLogger(dcontext.Background()).Errorf("error serializing health status: %v", err) dcontext.GetLogger(r.Context()).Errorf("error serializing health status: %v", err)
p, err = json.Marshal(struct { p, err = json.Marshal(struct {
ServerError string `json:"server_error"` ServerError string `json:"server_error"`
}{ }{
@ -291,7 +291,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m
status = http.StatusInternalServerError status = http.StatusInternalServerError
if err != nil { if err != nil {
dcontext.GetLogger(dcontext.Background()).Errorf("error serializing health status failure message: %v", err) dcontext.GetLogger(r.Context()).Errorf("error serializing health status failure message: %v", err)
return return
} }
} }
@ -300,7 +300,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m
w.Header().Set("Content-Length", fmt.Sprint(len(p))) w.Header().Set("Content-Length", fmt.Sprint(len(p)))
w.WriteHeader(status) w.WriteHeader(status)
if _, err := w.Write(p); err != nil { if _, err := w.Write(p); err != nil {
dcontext.GetLogger(dcontext.Background()).Errorf("error writing health status response body: %v", err) dcontext.GetLogger(r.Context()).Errorf("error writing health status response body: %v", err)
} }
} }