Skip to content

Commit

Permalink
make trace.TraceContext as default context propagator (#456)
Browse files Browse the repository at this point in the history
* make trace.TraceContext as default context propagator

* Update api/trace/trace_context_propagator.go

Co-Authored-By: Krzesimir Nowak <[email protected]>

* Update plugin/othttp/handler.go

* Update DefaultPropagator in plugin/{http,grpc}trace

* update DefaultPropagator as method instead of var

Co-authored-by: Krzesimir Nowak <[email protected]>
Co-authored-by: Rahul Patel <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2020
1 parent 8fcdf8b commit 32489dd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions api/trace/trace_context_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type TraceContext struct{}
var _ propagation.TextFormat = TraceContext{}
var traceCtxRegExp = regexp.MustCompile("^[0-9a-f]{2}-[a-f0-9]{32}-[a-f0-9]{16}-[a-f0-9]{2}-?")

// DefaultPropagator returns the default trace propagator.
func DefaultPropagator() propagation.TextFormat {
return TraceContext{}
}

func (hp TraceContext) Inject(ctx context.Context, supplier propagation.Supplier) {
sc := SpanFromContext(ctx).SpanContext()
if sc.IsValid() {
Expand Down
2 changes: 1 addition & 1 deletion plugin/grpctrace/grpctrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

var (
propagator = trace.TraceContext{}
propagator = trace.DefaultPropagator()
)

type metadataSupplier struct {
Expand Down
2 changes: 1 addition & 1 deletion plugin/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
HostKey = key.New("http.host")
URLKey = key.New("http.url")

propagator = trace.TraceContext{}
propagator = trace.DefaultPropagator()
)

// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
Expand Down
4 changes: 2 additions & 2 deletions plugin/othttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func WithPublicEndpoint() Option {

// WithPropagator configures the Handler with a specific propagator. If this
// option isn't specificed then
// go.opentelemetry.io/otel/api/trace.TraceContext is used.
// go.opentelemetry.io/otel/api/trace.DefaultPropagator is used.
func WithPropagator(p propagation.TextFormat) Option {
return func(h *Handler) {
h.prop = p
Expand Down Expand Up @@ -130,7 +130,7 @@ func NewHandler(handler http.Handler, operation string, opts ...Option) http.Han
h := Handler{handler: handler, operation: operation}
defaultOpts := []Option{
WithTracer(global.TraceProvider().Tracer("go.opentelemetry.io/plugin/othttp")),
WithPropagator(trace.TraceContext{}),
WithPropagator(trace.DefaultPropagator()),
WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)),
}

Expand Down

0 comments on commit 32489dd

Please sign in to comment.