Skip to content

Commit

Permalink
otelmux: Refactor option type (#860)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
pellared and MrAlias authored Jul 20, 2021
1 parent 94af9d0 commit 0448364
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions instrumentation/github.com/gorilla/mux/otelmux/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ type config struct {
}

// Option specifies instrumentation configuration options.
type Option func(*config)
type Option interface {
apply(*config)
}

type optionFunc func(*config)

func (o optionFunc) apply(c *config) {
o(c)
}

// WithPropagators specifies propagators to use for extracting
// information from the HTTP requests. If none are specified, global
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return func(cfg *config) {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
}
})
}

// WithTracerProvider specifies a tracer provider to use for creating a tracer.
// If none is specified, the global provider is used.
func WithTracerProvider(provider oteltrace.TracerProvider) Option {
return func(cfg *config) {
return optionFunc(func(cfg *config) {
cfg.TracerProvider = provider
}
})
}
2 changes: 1 addition & 1 deletion instrumentation/github.com/gorilla/mux/otelmux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
func Middleware(service string, opts ...Option) mux.MiddlewareFunc {
cfg := config{}
for _, opt := range opts {
opt(&cfg)
opt.apply(&cfg)
}
if cfg.TracerProvider == nil {
cfg.TracerProvider = otel.GetTracerProvider()
Expand Down

0 comments on commit 0448364

Please sign in to comment.