Go does not natively propagate trace context across services; you must use an OpenTelemetry-compatible library like go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp to inject and extract context headers. Install the library and wrap your HTTP handlers and clients to automatically handle trace propagation via W3C Trace Context headers.
go get go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
- Import the otelhttp package in your server and client code.
- Wrap your HTTP server handler with
otelhttp.NewHandlerto extract incoming trace context. - Wrap your HTTP client with
otelhttp.NewTransportto inject trace context into outgoing requests. - Ensure both services use the same OpenTelemetry exporter to visualize the distributed trace.