Fix rename tracing.WithPropagators to tracing.WithPropagator (#1095)

* Fix rename tracing.WithPropagators to tracing.WithPropagator
pull/1098/head
包子 3 years ago committed by GitHub
parent 4236b40c94
commit 4a6eb3e47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      examples/traces/app/message/main.go
  2. 7
      examples/traces/app/user/main.go
  3. 4
      middleware/tracing/tracer.go
  4. 8
      middleware/tracing/tracing.go
  5. 4
      middleware/tracing/tracing_test.go

@ -14,7 +14,6 @@ import (
"github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/grpc"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/trace/jaeger" "go.opentelemetry.io/otel/exporters/trace/jaeger"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace" tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv" "go.opentelemetry.io/otel/semconv"
@ -85,9 +84,6 @@ func main() {
// Configuring tracing Middleware // Configuring tracing Middleware
tracing.Server( tracing.Server(
tracing.WithTracerProvider(tp), tracing.WithTracerProvider(tp),
tracing.WithPropagators(
propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}),
),
), ),
logging.Server(logger), logging.Server(logger),
), ),

@ -16,7 +16,6 @@ import (
"github.com/go-kratos/kratos/v2/transport/http" "github.com/go-kratos/kratos/v2/transport/http"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/trace/jaeger" "go.opentelemetry.io/otel/exporters/trace/jaeger"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace" tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv" "go.opentelemetry.io/otel/semconv"
@ -66,9 +65,6 @@ func (s *server) GetMyMessages(ctx context.Context, in *v1.GetMyMessagesRequest)
recovery.Recovery(), recovery.Recovery(),
tracing.Client( tracing.Client(
tracing.WithTracerProvider(s.tracer), tracing.WithTracerProvider(s.tracer),
tracing.WithPropagators(
propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}),
),
), ),
), ),
grpc.WithTimeout(2*time.Second), grpc.WithTimeout(2*time.Second),
@ -107,9 +103,6 @@ func main() {
// Configuring tracing middleware // Configuring tracing middleware
tracing.Server( tracing.Server(
tracing.WithTracerProvider(tp), tracing.WithTracerProvider(tp),
tracing.WithPropagators(
propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}),
),
), ),
logging.Server(logger), logging.Server(logger),
), ),

@ -26,8 +26,8 @@ func NewTracer(kind trace.SpanKind, opts ...Option) *Tracer {
if options.TracerProvider != nil { if options.TracerProvider != nil {
otel.SetTracerProvider(options.TracerProvider) otel.SetTracerProvider(options.TracerProvider)
} }
if options.Propagators != nil { if options.Propagator != nil {
otel.SetTextMapPropagator(options.Propagators) otel.SetTextMapPropagator(options.Propagator)
} else { } else {
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})) otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}))
} }

@ -14,13 +14,13 @@ type Option func(*options)
type options struct { type options struct {
TracerProvider trace.TracerProvider TracerProvider trace.TracerProvider
Propagators propagation.TextMapPropagator Propagator propagation.TextMapPropagator
} }
// WithPropagators with tracer proagators. // WithPropagator with tracer proagator.
func WithPropagators(propagators propagation.TextMapPropagator) Option { func WithPropagator(propagator propagation.TextMapPropagator) Option {
return func(opts *options) { return func(opts *options) {
opts.Propagators = propagators opts.Propagator = propagator
} }
} }

@ -53,14 +53,14 @@ func TestTracing(t *testing.T) {
tp := tracesdk.NewTracerProvider(tracesdk.WithSampler(tracesdk.TraceIDRatioBased(0))) tp := tracesdk.NewTracerProvider(tracesdk.WithSampler(tracesdk.TraceIDRatioBased(0)))
// caller use Inject // caller use Inject
tracer := NewTracer(trace.SpanKindClient, WithTracerProvider(tp), WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}))) tracer := NewTracer(trace.SpanKindClient, WithTracerProvider(tp), WithPropagator(propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})))
ts := &Transport{kind: transport.KindHTTP, header: carrier} ts := &Transport{kind: transport.KindHTTP, header: carrier}
ctx, aboveSpan := tracer.Start(transport.NewClientContext(context.Background(), ts), ts.Kind().String(), ts.Operation(), ts.Header()) ctx, aboveSpan := tracer.Start(transport.NewClientContext(context.Background(), ts), ts.Kind().String(), ts.Operation(), ts.Header())
defer tracer.End(ctx, aboveSpan, nil) defer tracer.End(ctx, aboveSpan, nil)
// server use Extract fetch traceInfo from carrier // server use Extract fetch traceInfo from carrier
tracer = NewTracer(trace.SpanKindServer, WithPropagators(propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}))) tracer = NewTracer(trace.SpanKindServer, WithPropagator(propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})))
ts = &Transport{kind: transport.KindHTTP, header: carrier} ts = &Transport{kind: transport.KindHTTP, header: carrier}
ctx, span := tracer.Start(transport.NewServerContext(ctx, ts), ts.Kind().String(), ts.Operation(), ts.Header()) ctx, span := tracer.Start(transport.NewServerContext(ctx, ts), ts.Kind().String(), ts.Operation(), ts.Header())

Loading…
Cancel
Save