Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client.go: set peer.address tag from req.URL.Host; log hostPort in getConn() #58

Merged
merged 3 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions nethttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions nethttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=*"},
Expand All @@ -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())
}
}
}
}