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

Set PeerHostname/PeerPort rather than URL based on connection. #3

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion nethttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package nethttp
import (
"context"
"io"
"net"
"net/http"
"net/http/httptrace"
"strconv"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
Expand Down Expand Up @@ -159,7 +161,15 @@ func (h *Tracer) clientTrace() *httptrace.ClientTrace {
}

func (h *Tracer) getConn(hostPort string) {
ext.HTTPUrl.Set(h.sp, hostPort)
host, portString, err := net.SplitHostPort(hostPort)
if err != nil {
ext.PeerHostname.Set(h.sp, hostPort)
} else {
ext.PeerHostname.Set(h.sp, host)
if port, err := strconv.Atoi(portString); err != nil {
ext.PeerPort.Set(h.sp, uint16(port))
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I think both of these are wrong. The url and peer tags should be set for all traced http requests (i.e. in RoundTrip method), not only those for which httptrace.ClientTrace is enabled. What should really happen here is:

h.sp.LogKV(log.String("event", "GetConn"), log.String("hostPort", hostPort))

(or split host/port into two k/v pairs if not lazy).

I don't know how much more overhead httptrace.ClientTrace adds, it would be nice to make it optional. The RoundTrip is really what's needed for the actual tracing/propagation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a way to get the actual peer hostname from the request context, only via the GotConn callback.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net.URL#Host

h.sp.LogEvent("Get conn")
}

Expand Down