fix: get body using request.GetBody to enable request reuse#8352
Merged
dmathieu merged 16 commits intoopen-telemetry:mainfrom Jan 9, 2026
Merged
fix: get body using request.GetBody to enable request reuse#8352dmathieu merged 16 commits intoopen-telemetry:mainfrom
dmathieu merged 16 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8352 +/- ##
=====================================
Coverage 82.3% 82.3%
=====================================
Files 186 186
Lines 13765 13772 +7
=====================================
+ Hits 11330 11337 +7
Misses 2030 2030
Partials 405 405
🚀 New features to boost your workflow:
|
dmathieu
reviewed
Jan 7, 2026
dmathieu
reviewed
Jan 7, 2026
Co-authored-by: Damien Mathieu <[email protected]>
flc1125
reviewed
Jan 7, 2026
dmathieu
approved these changes
Jan 7, 2026
flc1125
approved these changes
Jan 8, 2026
ash2k
reviewed
Feb 3, 2026
| if r.GetBody != nil { | ||
| b, err := r.GetBody() | ||
| if err != nil { | ||
| otel.Handle(fmt.Errorf("http.Request GetBody returned an error: %w", err)) |
Contributor
There was a problem hiding this comment.
Shouldn't this just return the error, as the stdlib does?
https://github.com/golang/go/blob/go1.25.6/src/net/http/client.go#L673
Contributor
There was a problem hiding this comment.
There are two issues, actually:
- If I use
transport := http.DefaultTransportand set a breakpoint in theGetBodyimpl in that test, it is not triggered by the test execution. But it is triggered with the OTEL transport. This means OTEL transport callsGetBodywhen stdlib does not. stdlib only calls it if it needs another instance of the body (i.e. for second, third, etc attempts). - stdlib returns the error from
GetBody, it does not proceed. OTEL transport reports it and proceeds.
The unit test encodes incorrect behavior.
My understanding is that the code should:
- wrap the body that is set in the request, if it is not
niland notNoBody. - wrap the
GetBodyfunc but not call it. The underlying transport will call it if necessary.
| } | ||
| } | ||
|
|
||
| bw := request.NewBodyWrapper(body, func(int64) {}) |
Contributor
There was a problem hiding this comment.
I think this should only be allocated if it is actually needed - to reduce RAM usage.
Also, this object is unconditionally used below - it shouldn't be if it is not used as a body.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #8258
get http request body from
GetBodyif it is set, otherwise fallback toBodyfield.This allows reusing the request body bytes if the same http request struct is reused on subsequent requests.