set error tag on http error status codes (#683)
Bas van Beek authored 6 years ago
Peter Bourgon committed 6 years ago
192 | 192 |
func(ctx context.Context, code int, r *http.Request) {
|
193 | 193 |
if span := zipkin.SpanFromContext(ctx); span != nil {
|
194 | 194 |
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 |
}
|
195 | 199 |
if rs, ok := ctx.Value(kithttp.ContextKeyResponseSize).(int64); ok {
|
196 | 200 |
zipkin.TagHTTPResponseSize.Set(span, strconv.FormatInt(rs, 10))
|
197 | 201 |
}
|
1 | 1 |
|
2 | 2 |
import (
|
3 | 3 |
"context"
|
|
4 |
"errors"
|
4 | 5 |
"fmt"
|
5 | 6 |
"net/http"
|
6 | 7 |
"net/http/httptest"
|
|
172 | 173 |
handler := kithttp.NewServer(
|
173 | 174 |
endpoint.Nop,
|
174 | 175 |
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") },
|
176 | 177 |
zipkinkit.HTTPServerTrace(tr),
|
177 | 178 |
)
|
178 | 179 |
|
|
213 | 214 |
if want, have := httpMethod, spans[0].Name; want != have {
|
214 | 215 |
t.Errorf("incorrect span name, want %s, have %s", want, have)
|
215 | 216 |
}
|
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 |
}
|