-
Notifications
You must be signed in to change notification settings - Fork 560
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
Allow respWriterWrapper to call ResponseWriter.WriteHeader multiple times #3580
Allow respWriterWrapper to call ResponseWriter.WriteHeader multiple times #3580
Conversation
|
This also seems to change behavior. Could you write a test? |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3580 +/- ##
=======================================
- Coverage 70.1% 70.1% -0.1%
=======================================
Files 147 147
Lines 6974 6973 -1
=======================================
- Hits 4895 4891 -4
- Misses 1957 1959 +2
- Partials 122 123 +1
|
You're right. I've implemented tests to ensure we propagate WriteHeader calls to underlying ResponseWriters regardless of respWriterWrapper state. |
4346329
to
5454b80
Compare
Thanks for the comment @pellared. I'll answer in the main thread to avoid losing context if the comment is resolved The primary goal for me is to have our system behave the same with and without otelhttp. Today my code can work nicely with multiple calls to WriteHeader since This is not the responsibility of OpenTelemetry in my opinion, and can lead to unknown bad implementations of HTTP Handlers where WriteHeader is called multiple times, or it is called after I believe that otelhttp should report the initially written statusCode, as it does today, and not change reported status based on bad implementations. Changing the reported statusCode on consecutive calls to WriteHeader would lead to discrepancies between the attributes on the span vs what was actually sent to the client. The goal of otelhttp would be to report the first written statusCode on the span without filtering out future WriteHeader calls. If it is something we believe should be implemented I'll go ahead and change the code to document behavior in more detail. |
@jarlefosen I think it makes sense especially that now I see that I do not believe anyone expects the
Documenting behavior in more detail seems fine. |
…imes otelhttp respWriterWrapper no longer interrupts WriteHeader calls to underlying ResponseWriters. This allows stdlib net/http to handle and log incorrect usage of WriteHeader.
…atuses are written
We explicitly capture initial statusCode written while propagating all consecutive calls to the wrapped ResponseWriter without altering state.
a9ecdc7
to
563882f
Compare
@pellared I have finally gotten back to this and updated comments and documentation. |
Co-authored-by: Robert Pająk <pellared@hotmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience and contribution 👍
otelhttp respWriterWrapper blocks multiple calls to underlying WriteHeader which makes it harder to detect bugs in code where multiple calls to WriteHeader would be caught and logged by net/http.
This PR attempts to expose incorrect code by not blocking multiple calls to the underlying
ResponseWriter.WriteHeader
.