odigos-io / opentelemetry-go-instrumentation

OpenTelemetry auto-instrumentation for Go applications
Apache License 2.0
292 stars 44 forks source link

How to add request-id/trace-id to http request header? #37

Open yfractal opened 2 years ago

yfractal commented 2 years ago

Feature request

Allow opentelemetry-go-instrumentation trace http requests.

How to implement?

A Golang project may send http request to other servers through Golang net/request, for doing distributed tracing need to add the trace id in http headers.

The header is a map https://cs.opensource.google/go/go/+/refs/tags/go1.19.2:src/net/http/request.go;l=148.

If we do this through uprobe, we need edit a Golang map.

So how could we do this? Or do we have other options?

I guess eBPF program can't call a user's function easily, so we have to mange the memory, but map is complex, not sure how to do this.

Maybe we can calculate where we can put the key/value pair(we know the key and can know the length of value), and use the result to do memory management?

edeNFed commented 2 years ago

Hi @yfractal You are right, appending to map is more complex than appending to slice and is not a logic we implemented yet. Until we implement the map operations the way we do it today is by appending to the slice created in the function that iterates over the map. In an HTTP client example a good candidate would be: https://cs.opensource.google/go/go/+/master:src/net/http/header.go;l=173

Both of these tasks (HTTP client support + appending to maps) are on our roadmap and will be implemented in future versions. If you would like to help, we will be happy to accept a PR 😄

yfractal commented 2 years ago

Thanks edeNFed, I will try to figure how to do this, but I'm not sure when I can achieve this, I'm short of knowledge both C, eBPF and golang 😂

edeNFed commented 2 years ago

No worries, this will be added very soon

yfractal commented 2 years ago

Really great, thanks edeNFed!

liyan-ah commented 1 year ago

looking forward!