Skip to content

Commit

Permalink
Fix option appending logic in httpConfig functions
Browse files Browse the repository at this point in the history
Ensured options are only appended when they were not initially empty. This corrects potential duplication of options and follows expected behavior. Adjusted logic across traceOptions, metricOptions, and logOptions handlers.

Signed-off-by: Vincent Free <[email protected]>
  • Loading branch information
vincentfree committed Aug 26, 2024
1 parent 29d5f54 commit 84b6501
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions providerconfig/providerconfighttp/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,29 @@ func WithTraceOptions(options ...otlptracehttp.Option) Option {
return func(gc *httpConfig) {
if gc.traceOptions == nil || len(gc.traceOptions) == 0 {
gc.traceOptions = options
} else {
gc.traceOptions = append(gc.traceOptions, options...)
}
gc.traceOptions = append(gc.traceOptions, options...)
}
}

func WithMetricOptions(options ...otlpmetrichttp.Option) Option {
return func(gc *httpConfig) {
if gc.metricOptions == nil || len(gc.metricOptions) == 0 {
gc.metricOptions = options
} else {
gc.metricOptions = append(gc.metricOptions, options...)
}
gc.metricOptions = append(gc.metricOptions, options...)
}
}

func WithLogOptions(options ...otlploghttp.Option) Option {
return func(gc *httpConfig) {
if gc.logOptions == nil || len(gc.logOptions) == 0 {
gc.logOptions = options
} else {
gc.logOptions = append(gc.logOptions, options...)
}
gc.logOptions = append(gc.logOptions, options...)
}
}

Expand Down Expand Up @@ -92,17 +95,20 @@ func WithCollectorEndpoint(url string, port uint16) Option {
return func(gc *httpConfig) {
if len(gc.traceOptions) == 0 {
gc.traceOptions = []otlptracehttp.Option{otlptracehttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port))}
} else {
gc.traceOptions = append(gc.traceOptions, otlptracehttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port)))
}
gc.traceOptions = append(gc.traceOptions, otlptracehttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port)))

if len(gc.metricOptions) == 0 {
gc.metricOptions = []otlpmetrichttp.Option{otlpmetrichttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port))}
} else {
gc.metricOptions = append(gc.metricOptions, otlpmetrichttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port)))
}
gc.metricOptions = append(gc.metricOptions, otlpmetrichttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port)))

if len(gc.logOptions) == 0 {
gc.logOptions = []otlploghttp.Option{otlploghttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port))}
} else {
gc.logOptions = append(gc.logOptions, otlploghttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port)))
}
gc.logOptions = append(gc.logOptions, otlploghttp.WithEndpoint(fmt.Sprintf("%s:%d", url, port)))
}
}

0 comments on commit 84b6501

Please sign in to comment.