Skip to content

Commit

Permalink
Added guard to prevent Options from setting nil Propagators (#1124)
Browse files Browse the repository at this point in the history
* added guard to prevent options from setting nil propagators

* changed expectation on test for Shopify package

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
  • Loading branch information
erichsueh3 and Aneurysm9 committed Sep 21, 2021
1 parent b6b185d commit eb0df76
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func WithTracerProvider(provider trace.TracerProvider) Option {
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
if propagators != nil {
cfg.Propagators = propagators
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestNewConfig(t *testing.T) {
expected: config{
TracerProvider: otel.GetTracerProvider(),
Tracer: otel.GetTracerProvider().Tracer(defaultTracerName, trace.WithInstrumentationVersion(contrib.SemVersion())),
Propagators: nil,
Propagators: otel.GetTextMapPropagator(),
},
},
}
Expand Down
4 changes: 3 additions & 1 deletion instrumentation/github.com/astaxie/beego/otelbeego/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func WithMeterProvider(provider metric.MeterProvider) Option {
// Defaults to global.Propagators().
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(c *config) {
c.propagators = propagators
if propagators != nil {
c.propagators = propagators
}
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func (o optionFunc) apply(c *config) {
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
if propagators != nil {
cfg.Propagators = propagators
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion instrumentation/github.com/gin-gonic/gin/otelgin/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func (o optionFunc) apply(c *config) {
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
if propagators != nil {
cfg.Propagators = propagators
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion instrumentation/github.com/gorilla/mux/otelmux/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func (o optionFunc) apply(c *config) {
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
if propagators != nil {
cfg.Propagators = propagators
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion instrumentation/github.com/labstack/echo/otelecho/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func (o optionFunc) apply(c *config) {
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
if propagators != nil {
cfg.Propagators = propagators
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion instrumentation/google.golang.org/grpc/otelgrpc/grpctrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func newConfig(opts []Option) *config {
type propagatorsOption struct{ p propagation.TextMapPropagator }

func (o propagatorsOption) apply(c *config) {
c.Propagators = o.p
if o.p != nil {
c.Propagators = o.p
}
}

// WithPropagators returns an Option to use the Propagators when extracting
Expand Down
4 changes: 3 additions & 1 deletion instrumentation/gopkg.in/macaron.v1/otelmacaron/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func newConfig(opts []Option) *config {
type propagatorsOption struct{ p propagation.TextMapPropagator }

func (o propagatorsOption) apply(c *config) {
c.Propagators = o.p
if o.p != nil {
c.Propagators = o.p
}
}

// WithPropagators returns an Option to use the Propagators when extracting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func newConfig(opts []Option) *config {
// WithPropagators sets the propagators to use for Extraction and Injection
func WithPropagators(props propagation.TextMapPropagator) Option {
return optionFunc(func(c *config) {
c.propagators = props
if props != nil {
c.propagators = props
}
})
}

Expand Down
4 changes: 3 additions & 1 deletion instrumentation/net/http/otelhttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func WithPublicEndpoint() Option {
// option isn't specified, then the global TextMapPropagator is used.
func WithPropagators(ps propagation.TextMapPropagator) Option {
return optionFunc(func(c *config) {
c.Propagators = ps
if ps != nil {
c.Propagators = ps
}
})
}

Expand Down

0 comments on commit eb0df76

Please sign in to comment.