fix(otelhttp): report correct read bytes in client instrumentation#8684
fix(otelhttp): report correct read bytes in client instrumentation#8684Xio-Shark wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14e286e8a8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _ = wb.closeBody() | ||
| wb.recordMetricsOnce() |
There was a problem hiding this comment.
Avoid closing response body when Read returns EOF
wrappedBody.Read now calls closeBody() on every io.EOF, which changes behavior for upgraded/duplex responses (io.ReadWriteCloser) from transparent wrapping to forced shutdown. In protocol-switch or CONNECT-style streams, a read-side EOF can happen while the write side is still valid (TCP half-close); this automatic close tears down the underlying connection before user code calls Close, so subsequent writes can fail unexpectedly. The previous implementation finalized metrics/span on EOF without closing the body, which preserved caller control over stream lifetime.
Useful? React with 👍 / 👎.
|
Friendly follow-up: EasyCLA already reported success on March 17, 2026, but this PR still has the |
|
Pushed follow-up commit What changed:
Local validation:
Both passed in The |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 890ab4f346
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| trackedBody = newRequestBodyTracker(body, func() { | ||
| if currentTrackedBody() == trackedBody { | ||
| recordMetrics() |
There was a problem hiding this comment.
Synchronize recordMetrics callback publication
The request-body onClose callback can run on the transport write goroutine while RoundTrip later reassigns recordMetrics after t.rt.RoundTrip(r) returns, but this read/write of the captured function variable is unsynchronized. In practice (notably with net/http's concurrent write loop), this is a data race and can cause nondeterministic behavior, including invoking the stale no-op callback and dropping http.client.request.body.size/duration emission for that request. Please publish/access the callback through synchronization (e.g., mutex/atomic or a stable closure that reads synchronized state) before any concurrent close path can observe it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This file is not necessary, please remove it.
Additionally, please read first: https://github.com/open-telemetry/community/blob/main/policies/genai.md#frequently-asked-questions---contributors
890ab4f to
8757c34
Compare
|
Hi @flc1125, I've pushed the follow-up on top of the rebased branch. Changes included:
Validation:
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Hi @flc1125, thanks for the review. I've addressed all three points:
I've also read the OpenTelemetry GenAI policy you linked. Could you please take another look when you have a moment? The |
|
Hi @flc1125, friendly reminder that the EasyCLA check was already passed on 2026-03-17 ("The committers listed above are authorized under a signed CLA."). Could you please help remove the "blocked: CLA" label so this PR can move forward to review? Thank you! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8684 +/- ##
=======================================
- Coverage 83.3% 82.4% -1.0%
=======================================
Files 193 193
Lines 15826 19794 +3968
=======================================
+ Hits 13191 16314 +3123
- Misses 2152 2997 +845
Partials 483 483
🚀 New features to boost your workflow:
|
Summary: 修复
otelhttpclient instrumentation 中 read bytes 统计不准确问题Changes:
Motivation:
Testing:
go test ./instrumentation/net/http/otelhttp/...