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

* Fix rename tracing.WithPropagators to tracing.WithPropagator
pull/1098/head
包子 4 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"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/trace/jaeger"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv"
@ -85,9 +84,6 @@ func main() {
// Configuring tracing Middleware
tracing.Server(
tracing.WithTracerProvider(tp),
tracing.WithPropagators(
propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}),
),
),
logging.Server(logger),
),

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

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

@ -14,13 +14,13 @@ type Option func(*options)
type options struct {
TracerProvider trace.TracerProvider
Propagators propagation.TextMapPropagator
Propagator propagation.TextMapPropagator
}
// WithPropagators with tracer proagators.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
// WithPropagator with tracer proagator.
func WithPropagator(propagator propagation.TextMapPropagator) Option {
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)))
// 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}
ctx, aboveSpan := tracer.Start(transport.NewClientContext(context.Background(), ts), ts.Kind().String(), ts.Operation(), ts.Header())
defer tracer.End(ctx, aboveSpan, nil)
// 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}
ctx, span := tracer.Start(transport.NewServerContext(ctx, ts), ts.Kind().String(), ts.Operation(), ts.Header())

Loading…
Cancel
Save