Skip to content

Commit

Permalink
Fixed HTTP metrics bug
Browse files Browse the repository at this point in the history
Signed-off-by: Sotirios Mantziaris <[email protected]>
  • Loading branch information
mantzas authored Jul 1, 2019
1 parent c37adcc commit aa99907
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sync/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewTracingMiddleware(path string) MiddlewareFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
sp, r := trace.HTTPSpan(path, r)
lw := newResponseWriter(w)
next.ServeHTTP(w, r)
next.ServeHTTP(lw, r)
trace.FinishHTTPSpan(sp, lw.Status())
})
}
Expand Down
1 change: 1 addition & 0 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func HTTPSpan(path string, r *http.Request) (opentracing.Span, *http.Request) {
// FinishHTTPSpan finishes a HTTP span by providing a HTTP status code.
func FinishHTTPSpan(sp opentracing.Span, code int) {
ext.HTTPStatusCode.Set(sp, uint16(code))
ext.Error.Set(sp, code >= http.StatusInternalServerError)
sp.Finish()
}

Expand Down
1 change: 1 addition & 0 deletions trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func TestHTTPStartFinishSpan(t *testing.T) {
assert.Equal(t, map[string]interface{}{
"span.kind": ext.SpanKindRPCServerEnum,
"component": "http",
"error": false,
"http.method": "GET",
"http.status_code": uint16(200),
"http.url": "/",
Expand Down

0 comments on commit aa99907

Please sign in to comment.