Skip to content

Commit

Permalink
[exporter/otlphttpexporter] Use NewDefaultClientConfig instead of man…
Browse files Browse the repository at this point in the history
…ually creating struct

This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct. The updates to defaults are maintained (Timeout, Compression, WriteBufferSize) whereas the fields that match the default are not manually set anymore (Endpoint, Headers).

Issue: open-telemetry#9478 (comment)
  • Loading branch information
mackjmr committed Sep 25, 2024
1 parent 9811830 commit f8650e7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter"
Expand All @@ -33,19 +32,18 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = 30 * time.Second
// Default to gzip compression
clientConfig.Compression = configcompression.TypeGzip
// We almost read 0 bytes, so no need to tune ReadBufferSize.
clientConfig.WriteBufferSize = 512 * 1024

return &Config{
RetryConfig: configretry.NewDefaultBackOffConfig(),
QueueConfig: exporterhelper.NewDefaultQueueConfig(),
Encoding: EncodingProto,
ClientConfig: confighttp.ClientConfig{
Endpoint: "",
Timeout: 30 * time.Second,
Headers: map[string]configopaque.String{},
// Default to gzip compression
Compression: configcompression.TypeGzip,
// We almost read 0 bytes, so no need to tune ReadBufferSize.
WriteBufferSize: 512 * 1024,
},
RetryConfig: configretry.NewDefaultBackOffConfig(),
QueueConfig: exporterhelper.NewDefaultQueueConfig(),
Encoding: EncodingProto,
ClientConfig: clientConfig,
}
}

Expand Down

0 comments on commit f8650e7

Please sign in to comment.