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

Parent traceID not propogating to REST calls using otelgin.Middleware

Open Connect2naga opened this issue 1 year ago • 5 comments

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 avatar Aug 19 '23 03:08 Connect2naga

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

Connect2naga avatar Aug 26 '23 08:08 Connect2naga

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

dmathieu avatar Aug 28 '23 07:08 dmathieu

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.

Connect2naga avatar Sep 01 '23 18:09 Connect2naga

Any news about this? Are there any workarounds?

rasert avatar Jul 18 '24 19:07 rasert

@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

dmathieu avatar Jul 19 '24 07:07 dmathieu