otelhttp.WithClientTrace lost span when proxy can not connect #6581
Open
Description
Description
otelhttp.WithClientTrace lost span when proxy can not connect
Environment
- OS: [e.g. win11]
- Architecture: [e.g. x86]
- Go Version: [e.g. 1.23.4]
go.opentelemetry.io/contrib
version: [e.g. v0.58.0]
Steps To Reproduce
- Using this code ...
t := &http.Transport{}
t.Proxy = func(request *http.Request) (*url.URL, error) {
// 127.0.0.1:10809 can not connect
return &url.URL{Scheme: "http", Host: "127.0.0.1:10809"}, nil
}
client = &http.Client{
Transport: otelhttp.NewTransport(
t,
otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace {
return otelhttptrace.NewClientTrace(ctx)
}),
)}
client.Get("xxxxx")
- Run ...
- See error ...
go.opentelemetry.io\contrib\instrumentation\net\http\httptrace\otelhttptrace clienttrace.go
func (ct *clientTracer) gotConn(info httptrace.GotConnInfo) {
...
ct.end("http.getconn", nil, attrs...) // gotConn() do not call when 127.0.0.1:10809 can not connect
now http.getconn span lost
func (ct *clientTracer) getConn(host string) {
ct.start("http.getconn", "http.getconn", semconv.NetHostName(host))
}
Expected behavior
when 127.0.0.1:10809 works,
net/http/transport.go:1481
case r := <-w.result:
// Trace success but only for HTTP/1.
// HTTP/2 calls trace.GotConn itself.
if r.pc != nil && r.pc.alt == nil && trace != nil && trace.GotConn != nil {
info := httptrace.GotConnInfo{
Conn: r.pc.conn,
Reused: r.pc.isReused(),
}
if !r.idleAt.IsZero() {
info.WasIdle = true
info.IdleTime = time.Since(r.idleAt)
}
trace.GotConn(info) // will call func (ct *clientTracer) getConn(host string) { ct.start("http.getconn",
}