Skip to content

Commit

Permalink
Don't include the http.status_code when 2xx in server. (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
dengliming committed Aug 11, 2020
1 parent b483259 commit c1d1eb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions middleware/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
code := ri.getStatusCode()
sCode := strconv.Itoa(code)
if code > 399 {
h.errHandler(sp, nil, code)
if code < 200 || code > 299 {
zipkin.TagHTTPStatusCode.Set(sp, sCode)
if code > 399 {
h.errHandler(sp, nil, code)
}
}
zipkin.TagHTTPStatusCode.Set(sp, sCode)
if h.tagResponseSize && atomic.LoadUint64(&ri.size) > 0 {
zipkin.TagHTTPResponseSize.Set(sp, ri.getResponseSize())
}
Expand Down
5 changes: 5 additions & 0 deletions middleware/http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func TestHTTPDefaultSpanName(t *testing.T) {
httpRecorder = httptest.NewRecorder()
requestBuf = bytes.NewBufferString("incoming data")
methodType = "POST"
code = ""
)

request, err := http.NewRequest(methodType, "/test", requestBuf)
Expand All @@ -203,6 +204,10 @@ func TestHTTPDefaultSpanName(t *testing.T) {
if want, have := methodType, span.Name; want != have {
t.Errorf("Expected span name %s, got %s", want, have)
}

if want, have := code, span.Tags["http.status_code"]; want != have {
t.Errorf("Expected span status code %s, got %s", want, have)
}
}

func TestHTTPRequestSampler(t *testing.T) {
Expand Down

0 comments on commit c1d1eb5

Please sign in to comment.