Codebase list golang-github-go-kit-kit / 76d4527
set error tag on http error status codes (#683) Bas van Beek authored 6 years ago Peter Bourgon committed 6 years ago
2 changed file(s) with 11 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
192192 func(ctx context.Context, code int, r *http.Request) {
193193 if span := zipkin.SpanFromContext(ctx); span != nil {
194194 zipkin.TagHTTPStatusCode.Set(span, strconv.Itoa(code))
195 if code > 399 {
196 // set http status as error tag (if already set, this is a noop)
197 zipkin.TagError.Set(span, http.StatusText(code))
198 }
195199 if rs, ok := ctx.Value(kithttp.ContextKeyResponseSize).(int64); ok {
196200 zipkin.TagHTTPResponseSize.Set(span, strconv.FormatInt(rs, 10))
197201 }
11
22 import (
33 "context"
4 "errors"
45 "fmt"
56 "net/http"
67 "net/http/httptest"
172173 handler := kithttp.NewServer(
173174 endpoint.Nop,
174175 func(context.Context, *http.Request) (interface{}, error) { return nil, nil },
175 func(context.Context, http.ResponseWriter, interface{}) error { return nil },
176 func(context.Context, http.ResponseWriter, interface{}) error { return errors.New("dummy") },
176177 zipkinkit.HTTPServerTrace(tr),
177178 )
178179
213214 if want, have := httpMethod, spans[0].Name; want != have {
214215 t.Errorf("incorrect span name, want %s, have %s", want, have)
215216 }
216 }
217
218 if want, have := http.StatusText(500), spans[0].Tags["error"]; want != have {
219 t.Fatalf("incorrect error tag, want %s, have %s", want, have)
220 }
221 }