From da05004515d1b215d994f41f000802677b60dddf Mon Sep 17 00:00:00 2001 From: askuy Date: Fri, 29 Dec 2023 10:43:49 +0800 Subject: [PATCH] fix resty http trace id bug --- client/ehttp/interceptor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/ehttp/interceptor.go b/client/ehttp/interceptor.go index 50c9546c..c9980824 100644 --- a/client/ehttp/interceptor.go +++ b/client/ehttp/interceptor.go @@ -13,6 +13,7 @@ import ( "github.com/go-resty/resty/v2" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/propagation" semconv "go.opentelemetry.io/otel/semconv/v1.7.0" "go.opentelemetry.io/otel/trace" @@ -169,7 +170,9 @@ func traceInterceptor(name string, config *Config, logger *elog.Component, build semconv.RPCSystemKey.String("http"), } beforeFn := func(cli *resty.Client, req *resty.Request) error { - ctx, span := tracer.Start(req.Context(), req.Method, nil, trace.WithAttributes(attrs...)) + // 需要拿到header,才能将链路穿起来 + carrier := propagation.HeaderCarrier(req.Header) + ctx, span := tracer.Start(req.Context(), req.Method, carrier, trace.WithAttributes(attrs...)) span.SetAttributes( semconv.PeerServiceKey.String(name), semconv.HTTPMethodKey.String(req.Method),