Skip to content

Commit

Permalink
Merge pull request #418 from jj22ee/set-context-alternative
Browse files Browse the repository at this point in the history
Change how SDK sets the context for AWS SDK calls
  • Loading branch information
wangzlei authored Sep 25, 2023
2 parents c59927e + 3d484ac commit 4cdaf99
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions xray/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (

func beginSubsegment(r *request.Request, name string) {
ctx, _ := BeginSubsegment(r.HTTPRequest.Context(), name)
r.HTTPRequest = r.HTTPRequest.WithContext(ctx)
r.SetContext(ctx)
}

func endSubsegment(r *request.Request) {
Expand All @@ -58,7 +58,7 @@ func endSubsegment(r *request.Request) {
return
}
seg.Close(r.Error)
r.HTTPRequest = r.HTTPRequest.WithContext(context.WithValue(r.HTTPRequest.Context(), ContextKey, seg.parent))
r.SetContext(context.WithValue(r.HTTPRequest.Context(), ContextKey, seg.parent))
}

var xRayBeforeValidateHandler = request.NamedHandler{
Expand All @@ -71,7 +71,7 @@ var xRayBeforeValidateHandler = request.NamedHandler{
opseg.Namespace = "aws"
marshalctx, _ := BeginSubsegment(ctx, "marshal")

r.HTTPRequest = r.HTTPRequest.WithContext(marshalctx)
r.SetContext(marshalctx)
r.HTTPRequest.Header.Set(TraceIDHeaderKey, opseg.DownstreamHeader().String())
},
}
Expand All @@ -91,7 +91,7 @@ var xRayBeforeSignHandler = request.NamedHandler{
return
}
ct, _ := NewClientTrace(ctx)
r.HTTPRequest = r.HTTPRequest.WithContext(httptrace.WithClientTrace(ctx, ct.httpTrace))
r.SetContext(httptrace.WithClientTrace(ctx, ct.httpTrace))
},
}

Expand Down Expand Up @@ -139,7 +139,7 @@ var xRayBeforeRetryHandler = request.NamedHandler{
endSubsegment(r) // end attempt subsegment
ctx, _ := BeginSubsegment(r.HTTPRequest.Context(), "wait")

r.HTTPRequest = r.HTTPRequest.WithContext(ctx)
r.SetContext(ctx)
},
}

Expand Down

0 comments on commit 4cdaf99

Please sign in to comment.