From 8b889c04bdeab05d2c851e798399f0860442bc42 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Fri, 27 Oct 2023 15:34:10 -0400 Subject: [PATCH] health: use request context when logging Signed-off-by: Cory Snider --- health/health.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/health/health.go b/health/health.go index 57a714b6..67873f59 100644 --- a/health/health.go +++ b/health/health.go @@ -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) { p, err := json.Marshal(checks) 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 { ServerError string `json:"server_error"` }{ @@ -291,7 +291,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m status = http.StatusInternalServerError 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 } } @@ -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.WriteHeader(status) 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) } }