From d061788bf0049512df9057ac776330501f2f3033 Mon Sep 17 00:00:00 2001 From: Abdullah Almariah Date: Tue, 16 Jun 2020 23:25:29 +0200 Subject: [PATCH 1/4] set othttp span status from HTTP status code --- instrumentation/othttp/handler.go | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/othttp/handler.go b/instrumentation/othttp/handler.go index ea4ca36b549..4c06c5cec03 100644 --- a/instrumentation/othttp/handler.go +++ b/instrumentation/othttp/handler.go @@ -143,6 +143,7 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, kv = append(kv, WriteErrorKey.String(werr.Error())) } span.SetAttributes(kv...) + span.SetStatus(standard.SpanStatusFromHTTPStatusCode(int(statusCode))) } // WithRouteTag annotates a span with the provided route name using the From 3190372023f0093dd224f0911f6d18947f5415b6 Mon Sep 17 00:00:00 2001 From: Abdullah Almariah Date: Tue, 16 Jun 2020 23:31:38 +0200 Subject: [PATCH 2/4] set othttp span status from HTTP status code --- instrumentation/othttp/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/othttp/handler.go b/instrumentation/othttp/handler.go index 4c06c5cec03..de05575d9b0 100644 --- a/instrumentation/othttp/handler.go +++ b/instrumentation/othttp/handler.go @@ -120,6 +120,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.handler.ServeHTTP(rww, r.WithContext(ctx)) setAfterServeAttributes(span, bw.read, rww.written, rww.statusCode, bw.err, rww.err) + span.SetStatus(standard.SpanStatusFromHTTPStatusCode(int(rww.statusCode))) } func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, rerr, werr error) { @@ -142,8 +143,7 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, if werr != nil && werr != io.EOF { kv = append(kv, WriteErrorKey.String(werr.Error())) } - span.SetAttributes(kv...) - span.SetStatus(standard.SpanStatusFromHTTPStatusCode(int(statusCode))) + span.SetAttributes(kv...) } // WithRouteTag annotates a span with the provided route name using the From 4bbd543015831f25c1dfee2f0ae00c01d97b6c2c Mon Sep 17 00:00:00 2001 From: Abdullah Almariah Date: Tue, 16 Jun 2020 23:33:06 +0200 Subject: [PATCH 3/4] set othttp span status from HTTP status code --- instrumentation/othttp/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/othttp/handler.go b/instrumentation/othttp/handler.go index de05575d9b0..1e0a28dc49a 100644 --- a/instrumentation/othttp/handler.go +++ b/instrumentation/othttp/handler.go @@ -143,7 +143,7 @@ func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, if werr != nil && werr != io.EOF { kv = append(kv, WriteErrorKey.String(werr.Error())) } - span.SetAttributes(kv...) + span.SetAttributes(kv...) } // WithRouteTag annotates a span with the provided route name using the From 1991ace212a4cfa103a0dd526d741e19fe128316 Mon Sep 17 00:00:00 2001 From: Abdullah Almariah Date: Wed, 17 Jun 2020 14:47:42 +0200 Subject: [PATCH 4/4] remove the cast to int of statusCode --- instrumentation/othttp/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/othttp/handler.go b/instrumentation/othttp/handler.go index 1e0a28dc49a..52db46e322d 100644 --- a/instrumentation/othttp/handler.go +++ b/instrumentation/othttp/handler.go @@ -120,7 +120,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.handler.ServeHTTP(rww, r.WithContext(ctx)) setAfterServeAttributes(span, bw.read, rww.written, rww.statusCode, bw.err, rww.err) - span.SetStatus(standard.SpanStatusFromHTTPStatusCode(int(rww.statusCode))) + span.SetStatus(standard.SpanStatusFromHTTPStatusCode(rww.statusCode)) } func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, rerr, werr error) {