From 922f33d18919578049fbf2ccb756e6990b66f280 Mon Sep 17 00:00:00 2001 From: Hank Donnay Date: Thu, 26 Jan 2023 16:13:47 -0600 Subject: [PATCH] httptransport: fix request_id logging The final HTTP status message was getting an earlier Context which was missing the request_id key. Signed-off-by: Hank Donnay (cherry picked from commit 378a4b5f35ceb452654e7d9dca12fc455ac1697c) --- httptransport/indexer_v1.go | 3 ++- httptransport/matcher_v1.go | 3 ++- httptransport/notification_v1.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/httptransport/indexer_v1.go b/httptransport/indexer_v1.go index c9c71561c9..ed60937038 100644 --- a/httptransport/indexer_v1.go +++ b/httptransport/indexer_v1.go @@ -56,6 +56,7 @@ var _ http.Handler = (*IndexerV1)(nil) func (h *IndexerV1) ServeHTTP(w http.ResponseWriter, r *http.Request) { start := time.Now() wr := responserecorder.NewResponseRecorder(w) + r = withRequestID(r) defer func() { if f, ok := wr.(http.Flusher); ok { f.Flush() @@ -68,7 +69,7 @@ func (h *IndexerV1) ServeHTTP(w http.ResponseWriter, r *http.Request) { Dur("duration", time.Since(start)). Msg("handled HTTP request") }() - h.inner.ServeHTTP(wr, withRequestID(r)) + h.inner.ServeHTTP(wr, r) } func (h *IndexerV1) indexReport(w http.ResponseWriter, r *http.Request) { diff --git a/httptransport/matcher_v1.go b/httptransport/matcher_v1.go index 494a18a8cf..d2b9e124ec 100644 --- a/httptransport/matcher_v1.go +++ b/httptransport/matcher_v1.go @@ -64,6 +64,7 @@ var _ http.Handler = (*MatcherV1)(nil) func (h *MatcherV1) ServeHTTP(w http.ResponseWriter, r *http.Request) { start := time.Now() wr := responserecorder.NewResponseRecorder(w) + r = withRequestID(r) defer func() { if f, ok := wr.(http.Flusher); ok { f.Flush() @@ -76,7 +77,7 @@ func (h *MatcherV1) ServeHTTP(w http.ResponseWriter, r *http.Request) { Dur("duration", time.Since(start)). Msg("handled HTTP request") }() - h.inner.ServeHTTP(wr, withRequestID(r)) + h.inner.ServeHTTP(wr, r) } func (h *MatcherV1) vulnerabilityReport(w http.ResponseWriter, r *http.Request) { diff --git a/httptransport/notification_v1.go b/httptransport/notification_v1.go index 4e4b5e86bf..513f208a2d 100644 --- a/httptransport/notification_v1.go +++ b/httptransport/notification_v1.go @@ -56,6 +56,7 @@ func NewNotificationV1(_ context.Context, prefix string, srv notifier.Service, t func (h *NotificationV1) ServeHTTP(w http.ResponseWriter, r *http.Request) { start := time.Now() wr := responserecorder.NewResponseRecorder(w) + r = withRequestID(r) defer func() { if f, ok := wr.(http.Flusher); ok { f.Flush() @@ -68,7 +69,7 @@ func (h *NotificationV1) ServeHTTP(w http.ResponseWriter, r *http.Request) { Dur("duration", time.Since(start)). Msg("handled HTTP request") }() - h.inner.ServeHTTP(wr, withRequestID(r)) + h.inner.ServeHTTP(wr, r) } func (h *NotificationV1) serveHTTP(w http.ResponseWriter, r *http.Request) {