open-telemetry / opentelemetry-go-contrib

Collection of extensions for OpenTelemetry-Go.
https://opentelemetry.io/
Apache License 2.0
1.16k stars 551 forks source link

Parent traceID not propogating to REST calls using otelgin.Middleware #4204

Open Connect2naga opened 1 year ago

Connect2naga commented 1 year ago

HI

Trying sample Application using Gin and otelgin.Middleware() to stich chain of REST API calls. Below is the scenario tried.

  1. Make rest call to Books Application
  2. Books applications make call to Stores Applications to get all books from All stores
  3. Store applications just return empty.

image

Actually Books API call and Store Api calls' should be linked. But it not happening and both calls having different TraceID.

Note : Same tried with Mux it is working. Signoz used for view traces

Screenshots: Books Application: image

Store Application: image

Example code available in https://github.com/Connect2naga/Examples/tree/main/Standalone

Please correct me if any thing missed or need to change the confirguration.

Connect2naga commented 1 year ago

is it really a config issue or Bug, could you please confirm?

dmathieu commented 1 year ago

You're making outgoing requests with the default net/http client. https://github.com/Connect2naga/Examples/blob/main/Standalone/book/main.go#L102

You need to use the otelhttp one (or at least its transport), or outgoing HTTP requests won't include the trace ID and can't be propagated. https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/client.go#L28

Connect2naga commented 1 year ago

ok, Shouldn't be the same case in mux as well. for mux i am able to create propagate the traceID, let me check above configuration.

rasert commented 2 months ago

Any news about this? Are there any workarounds?

dmathieu commented 2 months ago

@rasert this issue appeared to have been a configuration problem. You need to use the otelhttp client for outgoing requests. This isn't a bug, and the workaround is to use the library as documented.

https://github.com/open-telemetry/opentelemetry-go-contrib/blob/7ce8deb5b42cccf5237d848b99469dca0ef519c9/instrumentation/net/http/otelhttp/client.go#L17