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

contrib/net/http: fix status reporting for empty replies #1140

Merged
merged 11 commits into from
Apr 13, 2022

Conversation

knusbaum
Copy link
Contributor

When no data is written, in an HTTP handler, our wrapped response writer
fails to capture a status code, resulting it the StatusCode tag being
missing from the span. We should detect this situation and record a 200 OK,
which is the default code for an empty response.

When no data is written, in an HTTP handler, our wrapped response writer
fails to capture a status code, resulting it the StatusCode tag being
missing from the span. We should detect this situation and record a 200 OK,
which is the default code for an empty response.
@knusbaum knusbaum added this to the 1.36.0 milestone Jan 21, 2022
@knusbaum knusbaum requested review from gbbr, dianashevchenko and a team January 21, 2022 20:09
@Julio-Guerra Julio-Guerra modified the milestones: 1.36.0, 1.37.0 Jan 25, 2022
contrib/net/http/trace_test.go Show resolved Hide resolved
@@ -81,6 +81,6 @@ func wrapResponseWriter(w http.ResponseWriter, span ddtrace.Span) http.ResponseW
w = mw
}

return w
return w, mw
Copy link
Contributor

@gbbr gbbr Jan 26, 2022

Choose a reason for hiding this comment

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

Why not simply change the type of the return value from http.ResponseWriter to *responseWriter? It should still work, because it still implements http.ResponseWriter. This way you're just returning the same thing twice under different types. Or, have I missed something?

Copy link
Contributor Author

@knusbaum knusbaum Jan 26, 2022

Choose a reason for hiding this comment

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

Unfortunately, w is a http.ResponseWriter since we're inventing them on the fly by combining things into unnamed struct types. At the end, w is not a *responseWriter, but a struct containing one, so we have to return the *responseWriter independently. I agree it's kind of ugly, but I'm not sure a better way without more major refactoring.

Co-authored-by: Gabriel Aszalos <gabriel.aszalos@gmail.com>
@knusbaum knusbaum requested a review from gbbr January 26, 2022 15:41
@Julio-Guerra Julio-Guerra modified the milestones: 1.37.0, 1.38.0 Mar 11, 2022
Copy link
Contributor

@ajgajg1134 ajgajg1134 left a comment

Choose a reason for hiding this comment

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

👍 this looks like a nice improvement

@Julio-Guerra Julio-Guerra merged commit b81e6aa into v1 Apr 13, 2022
@Julio-Guerra Julio-Guerra deleted the knusbaum/improve-http-status-reporting branch April 13, 2022 12:34
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.

None yet

4 participants