Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
laodaming 2023-08-28 10:34:36 +08:00
commit 48ddc3eb98

View File

@ -9,6 +9,10 @@ import (
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logc"
"github.com/zeromicro/go-zero/core/logx" "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 { func NewClient(ctx context.Context, c *Config) Client {
@ -18,6 +22,21 @@ func NewClient(ctx context.Context, c *Config) Client {
// 设置超时时间为 5 分钟 // 设置超时时间为 5 分钟
client.SetTimeout(5 * time.Minute) 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 { if c.HeaderData != nil {
for k, v := range c.HeaderData { for k, v := range c.HeaderData {
client = client.SetHeader(k, v) client = client.SetHeader(k, v)