opentelemetry-go-instrumentation
opentelemetry-go-instrumentation copied to clipboard
Auto-instrumentation: Incoming and outgoing HTTP requests create separate, uncorrelated traces
Describe the bug
I am using OpenTelemetry auto-instrumentation in a Go application to trace both incoming and outgoing HTTP requests. However, while I can see traces for incoming requests, the outgoing requests are creating entirely new, uncorrelated traces instead of being part of the same trace as the incoming request.
Environment Language: Go Go Version: 1.23.1 OpenTelemetry Go Auto-Instrumentation Version: v0.15.0-alpha OS: Linux (Amazon Linux 2023) Kernel Version: 6.1.0 Tracing Backend: Jaeger
Code -
// this is handler for API -- /v1/thor/rest/flight/home/deals
func DailyStealDealHandlerChain() gin.HandlersChain {
return gin.HandlersChain{
baseRequestParserMiddleware(client.NewDealsBaseHelper),
monitorHelper(handlers.NewMetricNameHelper(internal.MetricPrefixStealDeal)),
authMiddleware(),
requestParser(client.DailyStealDealRequestParser),
pokusMiddleware(),
getController(handlers.DailyStealDealHandler),
}
}
// helper to create gin handlers from common handlers
func getController(handler func(icontext.IContext, http.ResponseWriter, *http.Request)) gin.HandlerFunc {
return func(c *gin.Context) {
iCtx := copyGinContext(c)
generic_logger.NewLoggerWithUpdatedCtx(iCtx)
handler(iCtx, c.Writer, c.Request)
c.Writer.Flush()
}
}
func copyGinContext(c *gin.Context) icontext.IContext {
ctx := icontext.NewContext()
for k, v := range c.Keys {
ctx.SetValue(icontext.ContextKey(k), v)
}
for _, p := range c.Params {
ctx.SetValue(icontext.ContextKey(p.Key), p.Value)
}
return ctx
}
func DailyStealDealHandler(ctx icontext.IContext, w http.ResponseWriter, req *http.Request) {
dealReq := client.GetDailyStealDealRequest(ctx.GetBaseContext())
var clientResp *client.DealsResponse
var err error
clientResp, err = dealHandlerV2(ctx, dealReq)
if err != nil {
client.SendError(w, err)
}
client.SendJsonRespnse(w, clientResp)
}
inside dealHandlerV2 I am making http call to another API flights-b2c-misc/v2/daily-steal-deals.* by craeting this
ctx, _ = context.WithTimeout(ctx, time.Duration(b.Timeout)*time.Millisecond)
req, err := http.NewRequestWithContext(ctx, b.Method, b.Url, b.Body)
but for /v1/thor/rest/flight/home/deals I am getting another trace and for flights-b2c-misc/v2/daily-steal-deals.* I am getting different tarce ideally this sholud be same