From 889e0c8edf819a644924014113c23ea9a1e5f1ca Mon Sep 17 00:00:00 2001 From: Trong Huu Nguyen Date: Fri, 16 Sep 2022 19:23:21 +0200 Subject: [PATCH] feat(middleware/correlationid): use x-request-id header if found in request --- pkg/middleware/correlationid.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/middleware/correlationid.go b/pkg/middleware/correlationid.go index d50f305..c0126b3 100644 --- a/pkg/middleware/correlationid.go +++ b/pkg/middleware/correlationid.go @@ -10,7 +10,10 @@ import ( func CorrelationIDHandler(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - id := uuid.New().String() + id := r.Header.Get(chi_middleware.RequestIDHeader) + if len(id) == 0 { + id = uuid.New().String() + } ctx := r.Context() ctx = context.WithValue(ctx, chi_middleware.RequestIDKey, id)