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

otelhttp.WithClientTrace lost span when proxy can not connect #6581

Open
ddatsh opened this issue Jan 9, 2025 · 0 comments
Open

otelhttp.WithClientTrace lost span when proxy can not connect #6581

ddatsh opened this issue Jan 9, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ddatsh
Copy link

ddatsh commented Jan 9, 2025

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

  1. 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")
  1. Run ...
  2. See error ...

11

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

22

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",
		}
@ddatsh ddatsh added the bug Something isn't working label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant