Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tracing/zipkin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func HTTPServerTrace(tracer *zipkin.Tracer, options ...TracerOption) kithttp.Ser
func(ctx context.Context, code int, r *http.Request) {
if span := zipkin.SpanFromContext(ctx); span != nil {
zipkin.TagHTTPStatusCode.Set(span, strconv.Itoa(code))
if code > 399 {
// set http status as error tag (if already set, this is a noop)
zipkin.TagError.Set(span, http.StatusText(code))
}
if rs, ok := ctx.Value(kithttp.ContextKeyResponseSize).(int64); ok {
zipkin.TagHTTPResponseSize.Set(span, strconv.FormatInt(rs, 10))
}
Expand Down
7 changes: 6 additions & 1 deletion tracing/zipkin/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zipkin_test

import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -173,7 +174,7 @@ func TestHTTPServerTrace(t *testing.T) {
handler := kithttp.NewServer(
endpoint.Nop,
func(context.Context, *http.Request) (interface{}, error) { return nil, nil },
func(context.Context, http.ResponseWriter, interface{}) error { return nil },
func(context.Context, http.ResponseWriter, interface{}) error { return errors.New("dummy") },
zipkinkit.HTTPServerTrace(tr),
)

Expand Down Expand Up @@ -214,4 +215,8 @@ func TestHTTPServerTrace(t *testing.T) {
if want, have := httpMethod, spans[0].Name; want != have {
t.Errorf("incorrect span name, want %s, have %s", want, have)
}

if want, have := http.StatusText(500), spans[0].Tags["error"]; want != have {
t.Fatalf("incorrect error tag, want %s, have %s", want, have)
}
}