Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(otelhttp): fixes the body replacement in otelhttp to not to mutate a nil body. #484

Merged

Conversation

jcchavezs
Copy link
Contributor

@jcchavezs jcchavezs commented Dec 8, 2020

This might break tests when they attempt to read the body when the body isn't nil.

When using a http server, the body received by the handler is http.noBody whereas when calling directly the handler it receives nil. Whether calling the handler directly with a request is the best way to do it or not, by adding the handler in tests we get a nil pointer as any attempt to read a non nil body ends up trying to read a io.ReadCloser which is actually nil (and ends up in a nil pointer fatal error). This creates the so called "observer effect".

Related to hypertrace/goagent#66

Ping @XSAM @MrAlias @Aneurysm9

…ate a nil body.

This might break tests when they attempt to read the body when the body isn't nil.
@jcchavezs jcchavezs force-pushed the fix_handler_observer_effect branch from 11d34b9 to 18cb7b6 Compare December 8, 2020 19:54
@pavolloffay
Copy link
Member

@jmacd could you please review/merge this? This PR fixes a bug that is affecting us.

Copy link
Member

@XSAM XSAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if isReqBodyNil {
setAfterServeAttributes(span, 0, rww.written, rww.statusCode, nil, rww.err)
} else {
setAfterServeAttributes(span, bw.read, rww.written, rww.statusCode, bw.err, rww.err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you avoid these conditionals by setting bw to an empty bodyWrapper above and not replacing r.Body with it? It looks like these are just providing the empty values for those fields if the request body is nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea. Let me try that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jcchavezs
Copy link
Contributor Author

@XSAM @Aneurysm9 could we please include this in 0.15?

Copy link
Member

@XSAM XSAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aneurysm9 Since we do not actually release the v0.15.0 tag, maybe we should include this?

@jchengsfx The last commit fails the compilation.

instrumentation/net/http/otelhttp/handler.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/handler.go Outdated Show resolved Hide resolved
instrumentation/net/http/otelhttp/handler.go Outdated Show resolved Hide resolved
jcchavezs and others added 3 commits December 11, 2020 18:08
Co-authored-by: Sam Xie <xsambundy@gmail.com>
Co-authored-by: Sam Xie <xsambundy@gmail.com>
Co-authored-by: Sam Xie <xsambundy@gmail.com>
@jcchavezs
Copy link
Contributor Author

@XSAM done

@jcchavezs
Copy link
Contributor Author

jcchavezs commented Dec 12, 2020 via email

@Aneurysm9 Aneurysm9 merged commit c1c564f into open-telemetry:master Dec 12, 2020
@jcchavezs jcchavezs deleted the fix_handler_observer_effect branch December 13, 2020 20:07
jcchavezs added a commit to hypertrace/goagent that referenced this pull request Dec 14, 2020
This upgrade aims to prepare goagent to include the changes in open-telemetry/opentelemetry-go-contrib#484 in the next commit.
jcchavezs added a commit to hypertrace/goagent that referenced this pull request Dec 14, 2020
jcchavezs added a commit to hypertrace/goagent that referenced this pull request Dec 14, 2020
* chore(opentelemetry): upgrades opentelemetry to 0.15.0.

This upgrade aims to prepare goagent to include the changes in open-telemetry/opentelemetry-go-contrib#484 in the next commit.

* chore(opentelemetry): includes open-telemetry/opentelemetry-go-contrib#484 in the opentelemetry contrib dependency.

* tests(opencensus): improves coverage of the setAttribute method.

* tests(opentelemetry): adds coverage for setAttribute.
plantfansam referenced this pull request in plantfansam/opentelemetry-go-contrib Mar 18, 2022
…tallNewPipeline (#484)

Co-authored-by: Rahul Patel <rghetia@yahoo.com>
@pellared pellared added this to the untracked milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants