diff --git a/nethttp/client.go b/nethttp/client.go index 948ab96..16d2078 100644 --- a/nethttp/client.go +++ b/nethttp/client.go @@ -34,7 +34,7 @@ type Transport struct { type clientOptions struct { operationName string componentName string - urlTagFunc func(u *url.URL) string + urlTagFunc func(u *url.URL) string disableClientTrace bool disableInjectSpanContext bool spanObserver func(span opentracing.Span, r *http.Request) @@ -186,6 +186,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { ext.HTTPMethod.Set(tracer.sp, req.Method) ext.HTTPUrl.Set(tracer.sp, tracer.opts.urlTagFunc(req.URL)) + ext.PeerAddress.Set(tracer.sp, req.URL.Host) tracer.opts.spanObserver(tracer.sp, req) if !tracer.opts.disableInjectSpanContext { @@ -282,8 +283,7 @@ func (h *Tracer) clientTrace() *httptrace.ClientTrace { } func (h *Tracer) getConn(hostPort string) { - ext.HTTPUrl.Set(h.sp, hostPort) - h.sp.LogFields(log.String("event", "GetConn")) + h.sp.LogFields(log.String("event", "GetConn"), log.String("hostPort", hostPort)) } func (h *Tracer) gotConn(info httptrace.GotConnInfo) { diff --git a/nethttp/client_test.go b/nethttp/client_test.go index c72e176..9f922bf 100644 --- a/nethttp/client_test.go +++ b/nethttp/client_test.go @@ -288,8 +288,8 @@ func TestClientCustomURL(t *testing.T) { tag string }{ // These first cases fail early - {[]ClientOption{}, "/ok?token=a", srv.Listener.Addr().String()}, - {[]ClientOption{URLTagFunc(fn)}, "/ok?token=c", srv.Listener.Addr().String()}, + {[]ClientOption{}, "/ok?token=a", srv.URL + "/ok?token=a"}, + {[]ClientOption{URLTagFunc(fn)}, "/ok?token=c", srv.URL + "/ok?token=*"}, // Disable ClientTrace to fire RoundTrip {[]ClientOption{ClientTrace(false)}, "/ok?token=b", srv.URL + "/ok?token=b"}, {[]ClientOption{ClientTrace(false), URLTagFunc(fn)}, "/ok?token=c", srv.URL + "/ok?token=*"}, @@ -312,5 +312,12 @@ func TestClientCustomURL(t *testing.T) { if got, want := tag, tt.tag; got != want { t.Fatalf("got %s tag name, expected %s", got, want) } + peerAddress, ok := clientSpan.Tags()["peer.address"] + if !ok { + t.Fatal("cannot find peer.address tag") + } + if peerAddress != srv.Listener.Addr().String() { + t.Fatalf("got %s want %s in peer.address tag", peerAddress, srv.Listener.Addr().String()) + } } -} \ No newline at end of file +}