Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
forward context request id to L1s
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzo authored and willscott committed Sep 11, 2023
1 parent bda8d0d commit 013a220
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 013a220

Please sign in to comment.