You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
otlpmetrichttp: Add WithHTTPClient option (#6752)
Follows https://github.com/open-telemetry/opentelemetry-go/pull/6688 Towards (for OTLP metric exporter): - https://github.com/open-telemetry/opentelemetry-go/issues/4536 - https://github.com/open-telemetry/opentelemetry-go/issues/5129 - https://github.com/open-telemetry/opentelemetry-go/issues/2632
This commit is contained in:
@@ -57,13 +57,15 @@ type (
|
||||
Timeout time.Duration
|
||||
URLPath string
|
||||
|
||||
// gRPC configurations
|
||||
GRPCCredentials credentials.TransportCredentials
|
||||
|
||||
TemporalitySelector metric.TemporalitySelector
|
||||
AggregationSelector metric.AggregationSelector
|
||||
|
||||
Proxy HTTPTransportProxyFunc
|
||||
// gRPC configurations
|
||||
GRPCCredentials credentials.TransportCredentials
|
||||
|
||||
// HTTP configurations
|
||||
Proxy HTTPTransportProxyFunc
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
Config struct {
|
||||
@@ -373,3 +375,10 @@ func WithProxy(pf HTTPTransportProxyFunc) GenericOption {
|
||||
return cfg
|
||||
})
|
||||
}
|
||||
|
||||
func WithHTTPClient(c *http.Client) GenericOption {
|
||||
return newGenericOption(func(cfg Config) Config {
|
||||
cfg.Metrics.HTTPClient = c
|
||||
return cfg
|
||||
})
|
||||
}
|
||||
|
||||
@@ -533,6 +533,24 @@ func TestConfigs(t *testing.T) {
|
||||
assert.Nil(t, c.Metrics.Proxy)
|
||||
},
|
||||
},
|
||||
|
||||
// HTTP Client Tests
|
||||
{
|
||||
name: "Test With HTTP Client",
|
||||
opts: []GenericOption{
|
||||
WithHTTPClient(http.DefaultClient),
|
||||
},
|
||||
asserts: func(t *testing.T, c *Config, grpcOption bool) {
|
||||
assert.Equal(t, http.DefaultClient, c.Metrics.HTTPClient)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test Without HTTP Client",
|
||||
opts: []GenericOption{},
|
||||
asserts: func(t *testing.T, c *Config, grpcOption bool) {
|
||||
assert.Nil(t, c.Metrics.HTTPClient)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user