Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelbeego: Refactor option type #853

Merged
merged 3 commits into from
Jul 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions instrumentation/github.com/astaxie/beego/otelbeego/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ type config struct {

// Option applies a configuration to the given config.
type Option interface {
Apply(*config)
apply(*config)
}

// OptionFunc is a function type that applies a particular
// optionFunc is a function type that applies a particular
// configuration to the beego middleware in question.
type OptionFunc func(c *config)
type optionFunc func(c *config)

// Apply will apply the option to the config, c.
func (o OptionFunc) Apply(c *config) {
func (o optionFunc) apply(c *config) {
o(c)
}

Expand All @@ -51,39 +51,39 @@ func (o OptionFunc) Apply(c *config) {
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
// If none is specified, the global provider is used.
func WithTracerProvider(provider trace.TracerProvider) Option {
return OptionFunc(func(cfg *config) {
return optionFunc(func(cfg *config) {
cfg.tracerProvider = provider
})
}

// WithMeterProvider specifies a meter provider to use for creating a meter.
// If none is specified, the global provider is used.
func WithMeterProvider(provider metric.MeterProvider) Option {
return OptionFunc(func(cfg *config) {
return optionFunc(func(cfg *config) {
cfg.meterProvider = provider
})
}

// WithPropagators sets the propagators used in the middleware.
// Defaults to global.Propagators().
func WithPropagators(propagators propagation.TextMapPropagator) OptionFunc {
return OptionFunc(func(c *config) {
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(c *config) {
c.propagators = propagators
})
}

// WithFilter adds the given filter for use in the middleware.
// Defaults to no filters.
func WithFilter(f Filter) OptionFunc {
return OptionFunc(func(c *config) {
func WithFilter(f Filter) Option {
return optionFunc(func(c *config) {
c.filters = append(c.filters, f)
})
}

// WithSpanNameFormatter sets the formatter to be used to format
// span names. Defaults to the path template.
func WithSpanNameFormatter(f SpanNameFormatter) OptionFunc {
return OptionFunc(func(c *config) {
func WithSpanNameFormatter(f SpanNameFormatter) Option {
return optionFunc(func(c *config) {
c.formatter = f
})
}
Expand All @@ -99,7 +99,7 @@ func newConfig(options ...Option) *config {
formatter: defaultSpanNameFormatter,
}
for _, option := range options {
option.Apply(config)
option.apply(config)
}
return config
}