From aa999074037da957d6177c7f0125bff7a4d5d082 Mon Sep 17 00:00:00 2001 From: Sotirios Mantziaris Date: Mon, 1 Jul 2019 12:12:46 +0300 Subject: [PATCH] Fixed HTTP metrics bug Signed-off-by: Sotirios Mantziaris --- sync/http/middleware.go | 2 +- trace/trace.go | 1 + trace/trace_test.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sync/http/middleware.go b/sync/http/middleware.go index b0c8ca22a..dcfe02406 100644 --- a/sync/http/middleware.go +++ b/sync/http/middleware.go @@ -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()) }) } diff --git a/trace/trace.go b/trace/trace.go index b6fd7aadb..79d35162d 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -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() } diff --git a/trace/trace_test.go b/trace/trace_test.go index 9f57f4d7e..7b05cefca 100644 --- a/trace/trace_test.go +++ b/trace/trace_test.go @@ -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": "/",