opentelemetry-go-instrumentation icon indicating copy to clipboard operation
opentelemetry-go-instrumentation copied to clipboard

Regarding the issue of Traceparent

Open guolifu opened this issue 10 months ago • 2 comments

Describe the bug

I have created a service using an HTTP server, and in the GET method, I called another API. I added a header, Traceparent, at the entry point of the request. However, strangely, the traceID did not propagate smoothly, but instead, a new traceID was generated. Through debugging, I found an exception message: bpf_trace_printk: context c0000a6010 not found in context map. In the uprobe_Transport_roundTrip method, struct span_context *parent_span_ctx = get_parent_span_context(context_ptr_val); returns NULL. I don't know where the problem lies. It seems that the probe startup is working fine.

Environment

  • OS: [Linux ubuntu2204 5.15.0-105-generic x86_64]
  • Go Version: [1.18.3]
  • Version: [in main branch]

To Reproduce

Steps to reproduce the behavior: 1.

http.HandleFunc("/get2", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Println("curl request:", request)
		resp, err := http.Get("http://localhost:82/user")
		if err != nil {
			fmt.Println("error:", err)
			return
		}
		defer resp.Body.Close()

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			fmt.Println("error:", err)
			return
		}
		_, _ = io.WriteString(writer, "81 resp")
		fmt.Println("resp:", string(body))
	})

	fmt.Println("HTTP start")

	if err := http.ListenAndServe("0.0.0.0:81", nil); err != nil {
		fmt.Println("error:", err)
		return
	}
  1. build it

  2. OTEL_GO_AUTO_TARGET_EXE=/opt/github/opentelemetry-go-instrumentation/demo/ebpf/ebpfdemo OTEL_SERVICE_NAME=my_service OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4317 ./otel-go-instrumentation

  3. curl -H "Traceparent: 00-95b5ec2b81e2374a4a27ce36ab71d349-18f65a5a3ab22213-01" http://10.211.55.27:81/get2

image

Expected behavior

TraceId should remain consistent.

Additional context

Add any other context about the problem here.

guolifu avatar Apr 24 '24 06:04 guolifu

Hey, I think that passing the context object from the incoming request to the outgoing one will resolve this. (i.e Using NewRequestWithContext to perform the get request)

RonFed avatar Apr 24 '24 06:04 RonFed

Hey, I think that passing the context object from the incoming request to the outgoing one will resolve this. (i.e Using NewRequestWithContext to perform the get request)

Thank you very much for your assistance. 👍🏻 Following your advice, it did indeed run successfully as expected. However, for some of the code already written and deployed, we have extensively utilized the http.Get(Post) method. Are there any effective adaptation methods available to us?

guolifu avatar Apr 24 '24 07:04 guolifu