← Back to Pull requests

fix(otelhttp,otelmux): retain flush and body-read errors in shared wrappers #10352

Open
helmipradita opened this pull request with 238 lines diff across 13 files
View on GitHub
helmipradita helmipradita commented on Nov 20, 2026 01:25 UTC
Author

Fixes #10344

Fix the two error-retention gaps in the shared request/response wrappers:

1. RespWriterWrapper.FlushWithError now stores a non-nil flush error, so Error() reports it. A later successful flush/write/copy does not clear the earlier failure (same retention rule already used by Write/ReadFrom).
2. BodyWrapper.updateReadData no longer lets io.EOF overwrite an earlier non-EOF read failure. Plain EOF with no prior failure is still recorded, so ordinary completion stays clean for telemetry.

Changes are made in internal/shared/request/*.go.tmpl and regenerated for both otelhttp and otelmux.

Tests:

  • Extended TestRespWriterFlushWithError to assert retention and that a later successful flush keeps the error.

  • Added TestBodyWrapperRetainsReadErrorAfterEOF covering sentinel-then-EOF across repeated reads.

  • go test ./... passes in both instrumentation/net/http/otelhttp and instrumentation/github.com/gorilla/mux/otelmux.
  • Error classification / error.type wiring is intentionally left to #9754 and #9404, per the issue scope.

    Diff: 238 lines (+229 / -9) across 13 files Reviewer: helmipradita Review duration: 15274m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.67) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.67 · 238 lines diff across 13 files
    0.67
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.95 · 5 substantive comment(s)
    0.95
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.328
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    27 items
    opentelemetry-pr-dashboard[bot] opentelemetry-pr-dashboard[bot] commented on Nov 20, 2026 01:25 UTC
    Bot

    <!-- pull-request-dashboard-status -->
    <!-- pull-request-dashboard-status-revision:24 -->
    <!-- pull-request-dashboard-author-nudge-episode:42c3ebdd43994d5391d7e11df0bca675 -->

    Pull request dashboard status

    Waiting on the author · refreshed 2026-11-28 07:49 UTC

    Respond to 7 review items (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1, 2, 3, 4, 5, 6, 7
  • <details>
    <summary>Status above doesn't look right?</summary>

    <br>

  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.

  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.

  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.
  • </details>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 01:27 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No active review issues block the changes to preserve flush and request-body read failures.

    No open issues 🎉

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Fixes #10344 by preserving flush and request-body read failures in the shared wrappers used by otelhttp and otelmux. Error classification and error.type reporting remain outside this PR’s scope.

    Changes:

  • Retains flush errors without clearing them after a successful flush.

  • Prevents EOF from replacing an earlier body-read failure.

  • Adds regression tests and regenerates both instrumentations’ wrappers and tests.
  • No review issues were identified. Tests were not independently run.

    | File | Description |
    | ---- | ----------- |
    | internal/​shared/​request/​resp_writer_wrapper.go.tmpl | Retains non-nil flush errors. |
    | internal/​shared/​request/​resp_writer_wrapper_test.go.tmpl | Tests retention after failed and successful flushes. |
    | internal/​shared/​request/​body_wrapper.go.tmpl | Preserves earlier read failures through EOF. |
    | internal/​shared/​request/​body_wrapper_test.go.tmpl | Tests read-error retention after EOF. |
    | instrumentation/​net/​http/​otelhttp/​internal/​request/​resp_writer_wrapper.go | Regenerates flush-error retention for otelhttp. |
    | instrumentation/​net/​http/​otelhttp/​internal/​request/​resp_writer_wrapper_test.go | Regenerates flush regression tests. |
    | instrumentation/​net/​http/​otelhttp/​internal/​request/​body_wrapper.go | Regenerates body-read error retention for otelhttp. |
    | instrumentation/​net/​http/​otelhttp/​internal/​request/​body_wrapper_test.go | Regenerates body-read regression tests. |
    | instrumentation/​github.com/​gorilla/​mux/​otelmux/​internal/​request/​resp_writer_wrapper.go | Regenerates flush-error retention for otelmux. |
    | instrumentation/​github.com/​gorilla/​mux/​otelmux/​internal/​request/​resp_writer_wrapper_test.go | Regenerates flush regression tests. |
    | instrumentation/​github.com/​gorilla/​mux/​otelmux/​internal/​request/​body_wrapper.go | Regenerates body-read error retention for otelmux. |
    | instrumentation/​github.com/​gorilla/​mux/​otelmux/​internal/​request/​body_wrapper_test.go | Regenerates body-read regression tests. |
    </details>

    <sub>Review effort: Balanced</sub>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 01:37 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No active review issues remain for the shared HTTP wrapper error-retention fixes.

    No open issues 🎉

    <sub>Review effort: Balanced</sub>

    Copilot Copilot commented on code on Nov 24, 2026 06:45 UTC
    Code Review
    internal/shared/request/body_wrapper.go.tmpl:1
    @@ -53,7 +54,9 @@ func (w *BodyWrapper) updateReadData(n int64, err error) {
     	defer w.mu.Unlock()
     
     	w.read += n
    -	if err != nil {
    +	// Retain a non-EOF read failure; EOF alone is clean completion but must not
    +	// replace an earlier real failure.
    +	if err != nil && (w.err == nil || !errors.Is(err, io.EOF)) {

    errors.Is(err, io.EOF) suppresses wrapped EOF failures too, although io.ReadAll and otelmux's failure classification treat only literal io.EOF as clean completion. After plain EOF followed by fmt.Errorf("upload failed: %w", io.EOF), the caller receives a failure but Error() still reports plain EOF; a wrapped EOF also cannot replace an earlier non-EOF failure. Compare err != io.EOF, remove the unused errors import, add a regression for this sequence, and regenerate the body wrappers in both otelhttp and otelmux.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 24, 2026 06:45 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    The body wrapper suppresses wrapped EOF failures as clean completion, causing Error() to misreport failures returned to callers.

    <details open>
    <summary><strong>1 open issue</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Treat only literal EOF as a clean body-read completion · New

  • </details>

    <sub>Review effort: Balanced</sub>

    codecov[bot] codecov[bot] commented on Nov 25, 2026 09:53 UTC
    Bot

    Codecov Report


    :white_check_mark: All modified and coverable lines are covered by tests.
    :white_check_mark: Project coverage is 90.7%. Comparing base (b4214b4) to head (feb256b).
    :warning: Report is 27 commits behind head on main.

    <details><summary>Additional details and impacted files</summary>

    ![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/10352?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)

    @@           Coverage Diff           @@
    ##            main   #10352    +/-   ##
    =======================================
      Coverage   90.6%    90.7%            
    =======================================
      Files        230      232     +2     
      Lines      16648    16804   +156     
    =======================================
    + Hits       15099    15253   +154     
    - Misses      1549     1551     +2     
    

    | Files with missing lines | Coverage Δ | |
    |---|---|---|
    | ...rilla/mux/otelmux/internal/request/body\_wrapper.go | 95.6% <100.0%> (+0.6%) | :arrow_up: |
    | ...ux/otelmux/internal/request/resp\_writer\_wrapper.go | 100.0% <100.0%> (ø) | |
    | ...net/http/otelhttp/internal/request/body\_wrapper.go | 95.6% <100.0%> (+0.6%) | :arrow_up: |
    | ...p/otelhttp/internal/request/resp\_writer\_wrapper.go | 100.0% <100.0%> (ø) | |

    ... and 9 files with indirect coverage changes
    </details>
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    helmipradita helmipradita commented on code on Nov 27, 2026 05:08 UTC
    Code Review
    internal/shared/request/body_wrapper.go.tmpl:1
    @@ -53,7 +54,9 @@ func (w *BodyWrapper) updateReadData(n int64, err error) {
     	defer w.mu.Unlock()
     
     	w.read += n
    -	if err != nil {
    +	// Retain a non-EOF read failure; EOF alone is clean completion but must not
    +	// replace an earlier real failure.
    +	if err != nil && (w.err == nil || !errors.Is(err, io.EOF)) {

    Fixed in 98bc2f07. updateReadData now treats only a literal io.EOF as clean completion: a wrapped EOF is stored as a failure and replaces an earlier clean EOF, while a clean EOF never erases an earlier real failure. Removed the errors import, added TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure, and regenerated the otelhttp and otelmux wrappers. go test ./internal/request/... passes in both modules.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 27, 2026 05:11 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No active review issues remain for the changes that preserve I/O failures in the shared HTTP wrappers.

    No open issues 🎉

    <details>
    <summary><strong>1 resolved since last review</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Treat only literal EOF as a clean body-read completion

  • </details>

    <sub>Review effort: Balanced</sub>

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    instrumentation/net/http/otelhttp/internal/request/body_wrapper.go:1
    @@ -53,8 +53,14 @@ func (w *BodyWrapper) updateReadData(n int64, err error) {
     	defer w.mu.Unlock()
     
     	w.read += n
    +	// Only a literal io.EOF is clean completion; a wrapped EOF is a failure.
    +	// A clean EOF must not erase an earlier failure, but a later failure must
    +	// replace one that was recorded as clean completion.
     	if err != nil {
    -		w.err = err
    +		cleanEOF := err == io.EOF
    +		if !cleanEOF || w.err == nil || w.err == io.EOF {
    +			w.err = err
    +		}
     	}

    The retention condition is hard to follow. cleanEOF is used once, and w.err == nil || w.err == io.EOF overlaps with what the comment says. Early returns read more directly, and the three-line comment can shrink to one:

    	// A clean io.EOF must not overwrite an earlier recorded error.
    	if err == nil || (err == io.EOF && w.err != nil) {
    		return
    	}
    	w.err = err
    

    This behaves the same: when err == io.EOF and w.err is nil or io.EOF, the old code stored io.EOF again, and the new code stores it through the final assignment. The same change applies to internal/shared/request/body_wrapper.go.tmpl and the otelmux copy.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    internal/shared/request/body_wrapper.go.tmpl:1
    @@ -53,8 +53,14 @@ func (w *BodyWrapper) updateReadData(n int64, err error) {
     	defer w.mu.Unlock()
     
     	w.read += n
    +	// Only a literal io.EOF is clean completion; a wrapped EOF is a failure.
    +	// A clean EOF must not erase an earlier failure, but a later failure must
    +	// replace one that was recorded as clean completion.
     	if err != nil {
    -		w.err = err
    +		cleanEOF := err == io.EOF

    The two wrappers disagree about which failure wins. FlushWithError and Write overwrite with the latest error, while the body wrapper keeps the earlier non-EOF error, and only a later non-EOF error replaces it. Please pick one policy and apply it to both, or add a comment on each explaining why they differ.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    CHANGELOG.md:1
    @@ -78,6 +78,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
     ### Fixed
     
     - Bound Azure VM metadata requests to ten seconds and reject responses over 1 MiB in `go.opentelemetry.io/contrib/detectors/azure/azurevm`. (#10299)
    +- Retain flush errors and non-EOF request body read errors in the shared wrappers of `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` and `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`, so `Error()` reports failed I/O instead of staying nil or being overwritten by `io.EOF`. (#10352)

    This also changes behavior for wrapped EOFs: fmt.Errorf("...: %w", io.EOF) is now recorded as a failure, not as clean completion. That's the right call, but the entry only mentions "non-EOF request body read errors". Please add a few words about wrapped EOFs so users who see a new error status know why.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {

    There's no test for two different non-EOF errors in a row. Please add one asserting that the second replaces the first, so the "last non-EOF error wins" behavior is pinned down.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    internal/shared/request/resp_writer_wrapper_test.go.tmpl:1
    @@ -62,9 +62,14 @@ func TestRespWriterFlushWithError(t *testing.T) {
     	})
     
     	assert.ErrorIs(t, err, wantErr)
    +	assert.ErrorIs(t, rw.Error(), wantErr)
     	assert.Equal(t, 1, flushCalls)
     	assert.Equal(t, http.StatusOK, rw.StatusCode())
     	assert.Equal(t, http.StatusOK, responseRecorder.Code)
    +
    +	err = rw.FlushWithError(func() error { return nil })
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, rw.Error(), wantErr)

    This covers a later successful flush not clearing the error. Please also assert that a later failing flush with a different error replaces the stored one, which pins the "keep the last non-nil error" comment in FlushWithError.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&errorThenEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.ErrorIs(t, err, errFirstCall)
    +	require.ErrorIs(t, bw.Error(), errFirstCall)
    +
    +	_, err = io.ReadAll(bw)
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, bw.Error(), errFirstCall)
    +}
    +
    +type cleanEOFThenWrappedEOFReader struct {
    +	calls int
    +}
    +
    +func (r *cleanEOFThenWrappedEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, io.EOF
    +	}
    +
    +	return 0, fmt.Errorf("upload failed: %w", io.EOF)
    +}
    +
    +func TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&cleanEOFThenWrappedEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.NoError(t, err)
    +	require.Equal(t, io.EOF, bw.Error())
    +
    +	_, err = io.ReadAll(bw)
    +	require.ErrorIs(t, err, io.EOF)
    +	assert.Equal(t, "upload failed: EOF", bw.Error().Error())
    +}

    errorThenEOFReader and cleanEOFThenWrappedEOFReader are the same stub with different scripted results. Please replace them with one reader that returns a slice of errors in order, and turn the two tests (plus the one requested above) into a table-driven test. That cuts the boilerplate and makes the cases easy to extend.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&errorThenEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.ErrorIs(t, err, errFirstCall)
    +	require.ErrorIs(t, bw.Error(), errFirstCall)
    +
    +	_, err = io.ReadAll(bw)
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, bw.Error(), errFirstCall)
    +}
    +
    +type cleanEOFThenWrappedEOFReader struct {
    +	calls int
    +}
    +
    +func (r *cleanEOFThenWrappedEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, io.EOF
    +	}
    +
    +	return 0, fmt.Errorf("upload failed: %w", io.EOF)
    +}
    +
    +func TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&cleanEOFThenWrappedEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.NoError(t, err)
    +	require.Equal(t, io.EOF, bw.Error())

    Use require.ErrorIs(t, bw.Error(), io.EOF) here instead of comparing the error value with Equal.

    dmathieu dmathieu commented on code on Nov 27, 2026 08:55 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&errorThenEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.ErrorIs(t, err, errFirstCall)
    +	require.ErrorIs(t, bw.Error(), errFirstCall)
    +
    +	_, err = io.ReadAll(bw)
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, bw.Error(), errFirstCall)
    +}
    +
    +type cleanEOFThenWrappedEOFReader struct {
    +	calls int
    +}
    +
    +func (r *cleanEOFThenWrappedEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, io.EOF
    +	}
    +
    +	return 0, fmt.Errorf("upload failed: %w", io.EOF)
    +}
    +
    +func TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&cleanEOFThenWrappedEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.NoError(t, err)
    +	require.Equal(t, io.EOF, bw.Error())
    +
    +	_, err = io.ReadAll(bw)
    +	require.ErrorIs(t, err, io.EOF)
    +	assert.Equal(t, "upload failed: EOF", bw.Error().Error())

    Use assert.EqualError(t, bw.Error(), "upload failed: EOF") instead of comparing the .Error() string. Same for the generated test copies.

    helmipradita helmipradita commented on Nov 27, 2026 09:36 UTC
    Author

    Addressed the errorlint findings in the regenerated wrappers: literal-EOF detection now uses an errors.Is helper that excludes wrapped errors, without treating a wrapped EOF as clean completion. Head is feb256b6; golangci-lint reports 0 issues and go test ./internal/request/... passes in both otelhttp and otelmux. The remaining check-links failure is an external 503 for the semantic-conventions migration URL in CHANGELOG.md, unrelated to this change.

    helmipradita helmipradita commented on code on Nov 28, 2026 07:45 UTC
    Code Review
    instrumentation/net/http/otelhttp/internal/request/body_wrapper.go:1
    @@ -53,8 +53,14 @@ func (w *BodyWrapper) updateReadData(n int64, err error) {
     	defer w.mu.Unlock()
     
     	w.read += n
    +	// Only a literal io.EOF is clean completion; a wrapped EOF is a failure.
    +	// A clean EOF must not erase an earlier failure, but a later failure must
    +	// replace one that was recorded as clean completion.
     	if err != nil {
    -		w.err = err
    +		cleanEOF := err == io.EOF
    +		if !cleanEOF || w.err == nil || w.err == io.EOF {
    +			w.err = err
    +		}
     	}

    @/tmp/opencode/replies/.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:45 UTC
    Code Review
    internal/shared/request/body_wrapper.go.tmpl:1
    @@ -53,8 +53,14 @@ func (w *BodyWrapper) updateReadData(n int64, err error) {
     	defer w.mu.Unlock()
     
     	w.read += n
    +	// Only a literal io.EOF is clean completion; a wrapped EOF is a failure.
    +	// A clean EOF must not erase an earlier failure, but a later failure must
    +	// replace one that was recorded as clean completion.
     	if err != nil {
    -		w.err = err
    +		cleanEOF := err == io.EOF

    @/tmp/opencode/replies/.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:45 UTC
    Code Review
    CHANGELOG.md:1
    @@ -78,6 +78,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
     ### Fixed
     
     - Bound Azure VM metadata requests to ten seconds and reject responses over 1 MiB in `go.opentelemetry.io/contrib/detectors/azure/azurevm`. (#10299)
    +- Retain flush errors and non-EOF request body read errors in the shared wrappers of `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` and `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`, so `Error()` reports failed I/O instead of staying nil or being overwritten by `io.EOF`. (#10352)

    @/tmp/opencode/replies/.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:45 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {

    @/tmp/opencode/replies/.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:45 UTC
    Code Review
    internal/shared/request/resp_writer_wrapper_test.go.tmpl:1
    @@ -62,9 +62,14 @@ func TestRespWriterFlushWithError(t *testing.T) {
     	})
     
     	assert.ErrorIs(t, err, wantErr)
    +	assert.ErrorIs(t, rw.Error(), wantErr)
     	assert.Equal(t, 1, flushCalls)
     	assert.Equal(t, http.StatusOK, rw.StatusCode())
     	assert.Equal(t, http.StatusOK, responseRecorder.Code)
    +
    +	err = rw.FlushWithError(func() error { return nil })
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, rw.Error(), wantErr)

    @/tmp/opencode/replies/.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:48 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&errorThenEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.ErrorIs(t, err, errFirstCall)
    +	require.ErrorIs(t, bw.Error(), errFirstCall)
    +
    +	_, err = io.ReadAll(bw)
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, bw.Error(), errFirstCall)
    +}
    +
    +type cleanEOFThenWrappedEOFReader struct {
    +	calls int
    +}
    +
    +func (r *cleanEOFThenWrappedEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, io.EOF
    +	}
    +
    +	return 0, fmt.Errorf("upload failed: %w", io.EOF)
    +}
    +
    +func TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&cleanEOFThenWrappedEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.NoError(t, err)
    +	require.Equal(t, io.EOF, bw.Error())
    +
    +	_, err = io.ReadAll(bw)
    +	require.ErrorIs(t, err, io.EOF)
    +	assert.Equal(t, "upload failed: EOF", bw.Error().Error())
    +}

    @/tmp/opencode/replies/ot_0955.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:49 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&errorThenEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.ErrorIs(t, err, errFirstCall)
    +	require.ErrorIs(t, bw.Error(), errFirstCall)
    +
    +	_, err = io.ReadAll(bw)
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, bw.Error(), errFirstCall)
    +}
    +
    +type cleanEOFThenWrappedEOFReader struct {
    +	calls int
    +}
    +
    +func (r *cleanEOFThenWrappedEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, io.EOF
    +	}
    +
    +	return 0, fmt.Errorf("upload failed: %w", io.EOF)
    +}
    +
    +func TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&cleanEOFThenWrappedEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.NoError(t, err)
    +	require.Equal(t, io.EOF, bw.Error())

    @/tmp/opencode/replies/ot_0962.txt

    helmipradita helmipradita commented on code on Nov 28, 2026 07:49 UTC
    Code Review
    internal/shared/request/body_wrapper_test.go.tmpl:1
    @@ -63,6 +64,56 @@ func TestBodyWrapperWithErrors(t *testing.T) {
     	require.Equal(t, errorWrapper{}, bw.Error())
     }
     
    +type errorThenEOFReader struct {
    +	calls int
    +}
    +
    +func (r *errorThenEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, errFirstCall
    +	}
    +
    +	return 0, io.EOF
    +}
    +
    +func TestBodyWrapperRetainsReadErrorAfterEOF(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&errorThenEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.ErrorIs(t, err, errFirstCall)
    +	require.ErrorIs(t, bw.Error(), errFirstCall)
    +
    +	_, err = io.ReadAll(bw)
    +	require.NoError(t, err)
    +	assert.ErrorIs(t, bw.Error(), errFirstCall)
    +}
    +
    +type cleanEOFThenWrappedEOFReader struct {
    +	calls int
    +}
    +
    +func (r *cleanEOFThenWrappedEOFReader) Read([]byte) (int, error) {
    +	r.calls++
    +	if r.calls == 1 {
    +		return 0, io.EOF
    +	}
    +
    +	return 0, fmt.Errorf("upload failed: %w", io.EOF)
    +}
    +
    +func TestBodyWrapperReplacesCleanEOFWithWrappedEOFFailure(t *testing.T) {
    +	bw := NewBodyWrapper(io.NopCloser(&cleanEOFThenWrappedEOFReader{}), func(int64) {})
    +
    +	_, err := io.ReadAll(bw)
    +	require.NoError(t, err)
    +	require.Equal(t, io.EOF, bw.Error())
    +
    +	_, err = io.ReadAll(bw)
    +	require.ErrorIs(t, err, io.EOF)
    +	assert.Equal(t, "upload failed: EOF", bw.Error().Error())

    @/tmp/opencode/replies/ot_0968.txt

    dmathieu dmathieu commented on Nov 30, 2026 08:51 UTC
    Contributor

    Your comments are broken.

    Reviewers
    Assignees
    helmipradita helmipradita
    Labels
    risk: low confidence: 81.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 67.3% (HIGH) · Higher = larger blast radius
    67.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.8% · Lower = rushed or shallow review
    81.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.3% · Safe to merge
    12.3%