diff --git a/utils/curl/client_resty.go b/utils/curl/client_resty.go index 6cb0423f..022892b1 100644 --- a/utils/curl/client_resty.go +++ b/utils/curl/client_resty.go @@ -9,6 +9,10 @@ import ( "github.com/go-resty/resty/v2" "github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/trace" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + oteltrace "go.opentelemetry.io/otel/trace" ) func NewClient(ctx context.Context, c *Config) Client { @@ -18,6 +22,21 @@ func NewClient(ctx context.Context, c *Config) Client { // 设置超时时间为 5 分钟 client.SetTimeout(5 * time.Minute) + /* 传输链路 */ + tracer := otel.GetTracerProvider().Tracer(trace.TraceName) + spanCtx, span := tracer.Start( + ctx, + "client_resty_send", + oteltrace.WithSpanKind(oteltrace.SpanKindClient), + ) + carrier := &propagation.HeaderCarrier{} + otel.GetTextMapPropagator().Inject(spanCtx, carrier) + for _, cacarrierKey := range carrier.Keys() { + client.SetHeader(cacarrierKey, carrier.Get(cacarrierKey)) + } + defer span.End() + /* 传输链路 */ + if c.HeaderData != nil { for k, v := range c.HeaderData { client = client.SetHeader(k, v)