Skip to content

otelhttptrace: http.receive spans not finished #4876

Open
@katiehockman

Description

@katiehockman

Description

Spans with the resource name http.receive are being created, but never finished in the lifetime of the program.

Environment

  • OS: iOS
  • Architecture: x85
  • Go Version: go1.21.6 darwin/arm64
  • otelhttptrace version: v0.47.0

Steps To Reproduce

I am using a Datadog tracer for testing, with the following client code, using the example here:

package main

import (
	"context"
	"fmt"
	"net/http"
	"net/http/httptrace"

	ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry"
	ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
	"go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace"
	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
	"go.opentelemetry.io/otel"
)

func main() {
	provider := ddotel.NewTracerProvider(ddtracer.WithDebugMode(true))
	defer provider.Shutdown()
	otel.SetTracerProvider(provider)

	client := http.Client{
		Transport: otelhttp.NewTransport(
			http.DefaultTransport,
			otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace {
				return otelhttptrace.NewClientTrace(ctx)
			}),
		),
	}
	resp, err := client.Get("http://example.com")
	if err != nil {
		fmt.Println(error)
		os.Exit(0)
	}
	defer resp.Body.Close()
}

When I run this code and check the debug logs, I can see that 7 spans are getting started, but only 6 spans are getting finished. The one not getting finished has the following debug line:

2024/01/30 16:20:32 Datadog Tracer v1.61.0-dev DEBUG: Started Span: dd.trace_id="6805150280004253875" dd.span_id="1206165090554086340" dd.parent_id="6805150280004253875", Operation: http.receive, Resource: http.receive, Tags: map[language:go runtime-id:aad56e8c-1c67-48f0-82e2-e6d66ec77559 span.kind:client], map[_sampling_priority_v1:1 process_id:56444]

This is a span named http.receive, which appears to be getting created here:

I can see in the code that there is a function present for finishing this span, but it doesn't appear to be getting called. I don't see any unit tests that use putIdleConn, whereas the other similar methods have them, so I wonder if there could perhaps be a bug where putIdleConn is not being executed as expected.

Expected behavior

I expect all spans that are created to be finished before the program exits. i.e. there should be a line that looks something like this as well:

2024/01/30 16:20:32 Datadog Tracer v1.61.0-dev DEBUG: Finished Span: dd.trace_id="6805150280004253875" dd.span_id="1206165090554086340" dd.parent_id="6805150280004253875", Operation: http.receive, Resource: http.receive, Tags: map[language:go runtime-id:aad56e8c-1c67-48f0-82e2-e6d66ec77559 span.kind:client], map[_sampling_priority_v1:1 process_id:56444]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions