diff --git a/clihttp/client.go b/clihttp/client.go index e40e7502..b6bbad51 100644 --- a/clihttp/client.go +++ b/clihttp/client.go @@ -88,6 +88,8 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) { c.tracer.Inject(clientSpan.Context(), opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header)) response, err := c.underlying.Do(req) if err != nil { + ext.Error.Set(clientSpan, true) + clientSpan.LogFields(log.String("event", "error"), log.String("message", err.Error())) return response, err } diff --git a/clihttp/client_test.go b/clihttp/client_test.go index a3a1518c..a536e14b 100644 --- a/clihttp/client_test.go +++ b/clihttp/client_test.go @@ -38,6 +38,11 @@ func TestClient_Do(t *testing.T) { func() *http.Request { r, _ := http.NewRequest("GET", "https://example.com/", nil); return r }(), []Option{WithResponseLogThreshold(1)}, }, + { + "error", + func() *http.Request { r, _ := http.NewRequest("GET", "https://non-exist-domain.com/", nil); return r }(), + []Option{}, + }, } for _, c := range cases { c := c @@ -45,7 +50,11 @@ func TestClient_Do(t *testing.T) { t.Parallel() tracer := mocktracer.New() client := NewClient(tracer, c.Option...) - resp, _ := client.Do(c.request) + resp, err := client.Do(c.request) + if err != nil { + assert.True(t, tracer.FinishedSpans()[0].Tags()["error"].(bool)) + return + } defer resp.Body.Close() assert.NotEmpty(t, tracer.FinishedSpans()) byt, _ := ioutil.ReadAll(resp.Body)