From 013a2203f79c2d65fac1c6ce338a13f991ec7fda Mon Sep 17 00:00:00 2001 From: Eric Guan Date: Wed, 6 Sep 2023 09:38:00 -0700 Subject: [PATCH] forward context request id to L1s --- fetcher.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fetcher.go b/fetcher.go index 728fd37..f9e3729 100644 --- a/fetcher.go +++ b/fetcher.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/willscott/go-requestcontext" "go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -60,6 +61,7 @@ func (p *pool) fetchResource(ctx context.Context, from *Node, resource string, m requestId := uuid.NewString() goLogger.Debugw("doing fetch", "from", from, "of", resource, "mime", mime, "requestId", requestId) + contextRequestId := requestcontext.IDFromContext(ctx) start := time.Now() response_success_end := time.Now() @@ -197,6 +199,9 @@ func (p *pool) fetchResource(ctx context.Context, from *Node, resource string, m } req.Header.Add("Accept", mime) + if contextRequestId != "" { + req.Header.Add("X-Request-Id", contextRequestId) + } if p.config.ExtraHeaders != nil { for k, vs := range *p.config.ExtraHeaders {