Skip to content

Commit 32489dd

Browse files
clsungkrnowakrghetia
authored
make trace.TraceContext as default context propagator (#456)
* 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]>
1 parent 8fcdf8b commit 32489dd

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

api/trace/trace_context_propagator.go

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ type TraceContext struct{}
4242
var _ propagation.TextFormat = TraceContext{}
4343
var traceCtxRegExp = regexp.MustCompile("^[0-9a-f]{2}-[a-f0-9]{32}-[a-f0-9]{16}-[a-f0-9]{2}-?")
4444

45+
// DefaultPropagator returns the default trace propagator.
46+
func DefaultPropagator() propagation.TextFormat {
47+
return TraceContext{}
48+
}
49+
4550
func (hp TraceContext) Inject(ctx context.Context, supplier propagation.Supplier) {
4651
sc := SpanFromContext(ctx).SpanContext()
4752
if sc.IsValid() {

plugin/grpctrace/grpctrace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
var (
27-
propagator = trace.TraceContext{}
27+
propagator = trace.DefaultPropagator()
2828
)
2929

3030
type metadataSupplier struct {

plugin/httptrace/httptrace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
HostKey = key.New("http.host")
2828
URLKey = key.New("http.url")
2929

30-
propagator = trace.TraceContext{}
30+
propagator = trace.DefaultPropagator()
3131
)
3232

3333
// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.

plugin/othttp/handler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func WithPublicEndpoint() Option {
7979

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

0 commit comments

Comments
 (0)