From c8d11cdc2d57f1d66caec4c876aac3d13e50b4ef Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 17:07:35 +0200 Subject: [PATCH 01/19] add support for passing a custom proxy function to otlp metric exporter http client --- CHANGELOG.md | 1 + exporters/otlp/otlpmetric/otlpmetrichttp/client.go | 10 ++++++---- exporters/otlp/otlpmetric/otlpmetrichttp/config.go | 8 ++++++++ .../otlpmetrichttp/internal/oconf/options.go | 12 ++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be07aae6bd4..f827fdcde7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The next release will require at least [Go 1.21]. ### Added - Support [Go 1.22]. (#4890) +- Support configuring a custom Proxy Function for the `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` HTTP Client Transport. ## [1.23.1] 2024-02-07 diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index 73463c91d5f..33e80a240e7 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -65,14 +65,16 @@ var ourTransport = &http.Transport{ // newClient creates a new HTTP metric client. func newClient(cfg oconf.Config) (*client, error) { + clonedTransport := ourTransport.Clone() httpClient := &http.Client{ - Transport: ourTransport, + Transport: clonedTransport, Timeout: cfg.Metrics.Timeout, } if cfg.Metrics.TLSCfg != nil { - transport := ourTransport.Clone() - transport.TLSClientConfig = cfg.Metrics.TLSCfg - httpClient.Transport = transport + clonedTransport.TLSClientConfig = cfg.Metrics.TLSCfg + } + if cfg.Metrics.Proxy != nil { + clonedTransport.Proxy = cfg.Metrics.Proxy } u := &url.URL{ diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go index 5948e2d9d73..4bc429306ad 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go @@ -217,3 +217,11 @@ func WithTemporalitySelector(selector metric.TemporalitySelector) Option { func WithAggregationSelector(selector metric.AggregationSelector) Option { return wrappedOption{oconf.WithAggregationSelector(selector)} } + +// WithProxyFunc sets the Proxy function the client will use to determine the +// proxy to use for an HTTP request. If this option is not used, the client +// will use the default proxy settings from the +// exporters/otlp/otlpmetric/otlpmetrichttp package (adhering to the Golang's DefaultTransport from net/http). +func WithProxyFunc(pf oconf.HTTPTransportProxyFunc) Option { + return wrappedOption{oconf.WithProxyFunc(pf)} +} diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go index 253539d7a3c..e3286055ddc 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go @@ -20,6 +20,7 @@ package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlp import ( "crypto/tls" "fmt" + "net/http" "net/url" "path" "strings" @@ -53,6 +54,8 @@ const ( ) type ( + HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + SignalConfig struct { Endpoint string Insecure bool @@ -67,6 +70,8 @@ type ( TemporalitySelector metric.TemporalitySelector AggregationSelector metric.AggregationSelector + + Proxy HTTPTransportProxyFunc } Config struct { @@ -371,3 +376,10 @@ func WithAggregationSelector(selector metric.AggregationSelector) GenericOption return cfg }) } + +func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { + return newGenericOption(func(cfg Config) Config { + cfg.Metrics.Proxy = pf + return cfg + }) +} From a337029c1d767b920070ae5b61e691ed79b9c9a9 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 17:23:29 +0200 Subject: [PATCH 02/19] update otlp http exporter options template to include new proxy func configuration --- internal/shared/otlp/otlpmetric/oconf/options.go.tmpl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 8fb706f76c9..6c5135b6b9a 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -53,6 +53,8 @@ const ( ) type ( + HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + SignalConfig struct { Endpoint string Insecure bool @@ -67,6 +69,8 @@ type ( TemporalitySelector metric.TemporalitySelector AggregationSelector metric.AggregationSelector + + Proxy HTTPTransportProxyFunc } Config struct { @@ -371,3 +375,10 @@ func WithAggregationSelector(selector metric.AggregationSelector) GenericOption return cfg }) } + +func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { + return newGenericOption(func(cfg Config) Config { + cfg.Metrics.Proxy = pf + return cfg + }) +} From a38fbad906898374ed6e5b9a5272c325c4cbc9e0 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 17:28:49 +0200 Subject: [PATCH 03/19] update missing import in template for net http --- .../otlpmetricgrpc/internal/oconf/options.go | 12 ++++++++++++ .../shared/otlp/otlpmetric/oconf/options.go.tmpl | 1 + 2 files changed, 13 insertions(+) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go index e2d99dc22c1..0f144c299fb 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go @@ -20,6 +20,7 @@ package oconf // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlp import ( "crypto/tls" "fmt" + "net/http" "net/url" "path" "strings" @@ -53,6 +54,8 @@ const ( ) type ( + HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + SignalConfig struct { Endpoint string Insecure bool @@ -67,6 +70,8 @@ type ( TemporalitySelector metric.TemporalitySelector AggregationSelector metric.AggregationSelector + + Proxy HTTPTransportProxyFunc } Config struct { @@ -371,3 +376,10 @@ func WithAggregationSelector(selector metric.AggregationSelector) GenericOption return cfg }) } + +func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { + return newGenericOption(func(cfg Config) Config { + cfg.Metrics.Proxy = pf + return cfg + }) +} diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 6c5135b6b9a..613de533967 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -20,6 +20,7 @@ package oconf import ( "crypto/tls" "fmt" + "net/http" "net/url" "path" "strings" From 9c8288eea7ad93479e96a89227a34daf32ca2011 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 17:44:16 +0200 Subject: [PATCH 04/19] Update otlp trace grpc http transport configuration to support custom proxy function --- .../otlptracegrpc/internal/otlpconfig/options.go | 12 ++++++++++++ exporters/otlp/otlptrace/otlptracehttp/client.go | 10 ++++++---- .../otlptracehttp/internal/otlpconfig/options.go | 12 ++++++++++++ .../shared/otlp/otlpmetric/oconf/options.go.tmpl | 2 +- .../shared/otlp/otlptrace/otlpconfig/options.go.tmpl | 12 ++++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go index f0203cbe723..af48334ebf6 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go @@ -20,6 +20,7 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/ import ( "crypto/tls" "fmt" + "net/http" "net/url" "path" "strings" @@ -46,6 +47,8 @@ const ( ) type ( + HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + SignalConfig struct { Endpoint string Insecure bool @@ -57,6 +60,8 @@ type ( // gRPC configurations GRPCCredentials credentials.TransportCredentials + + Proxy HTTPTransportProxyFunc } Config struct { @@ -343,3 +348,10 @@ func WithTimeout(duration time.Duration) GenericOption { return cfg }) } + +func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { + return newGenericOption(func(cfg Config) Config { + cfg.Traces.Proxy = pf + return cfg + }) +} diff --git a/exporters/otlp/otlptrace/otlptracehttp/client.go b/exporters/otlp/otlptrace/otlptracehttp/client.go index 3b5f3839f27..d9e68606b3f 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client.go @@ -81,14 +81,16 @@ var _ otlptrace.Client = (*client)(nil) func NewClient(opts ...Option) otlptrace.Client { cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(opts)...) + clonedTransport := ourTransport.Clone() httpClient := &http.Client{ - Transport: ourTransport, + Transport: clonedTransport, Timeout: cfg.Traces.Timeout, } if cfg.Traces.TLSCfg != nil { - transport := ourTransport.Clone() - transport.TLSClientConfig = cfg.Traces.TLSCfg - httpClient.Transport = transport + clonedTransport.TLSClientConfig = cfg.Traces.TLSCfg + } + if cfg.Traces.Proxy != nil { + clonedTransport.Proxy = cfg.Traces.Proxy } stopCh := make(chan struct{}) diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go index 3b81641a764..996d67620fe 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go @@ -20,6 +20,7 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/ import ( "crypto/tls" "fmt" + "net/http" "net/url" "path" "strings" @@ -46,6 +47,8 @@ const ( ) type ( + HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + SignalConfig struct { Endpoint string Insecure bool @@ -57,6 +60,8 @@ type ( // gRPC configurations GRPCCredentials credentials.TransportCredentials + + Proxy HTTPTransportProxyFunc } Config struct { @@ -343,3 +348,10 @@ func WithTimeout(duration time.Duration) GenericOption { return cfg }) } + +func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { + return newGenericOption(func(cfg Config) Config { + cfg.Traces.Proxy = pf + return cfg + }) +} diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 613de533967..158483d80c3 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -71,7 +71,7 @@ type ( TemporalitySelector metric.TemporalitySelector AggregationSelector metric.AggregationSelector - Proxy HTTPTransportProxyFunc + Proxy HTTPTransportProxyFunc } Config struct { diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl index 1d5613c44fd..ce921bb53a0 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl @@ -20,6 +20,7 @@ package otlpconfig import ( "crypto/tls" "fmt" + "net/http" "net/url" "path" "strings" @@ -46,6 +47,8 @@ const ( ) type ( + HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + SignalConfig struct { Endpoint string Insecure bool @@ -57,6 +60,8 @@ type ( // gRPC configurations GRPCCredentials credentials.TransportCredentials + + Proxy HTTPTransportProxyFunc } Config struct { @@ -343,3 +348,10 @@ func WithTimeout(duration time.Duration) GenericOption { return cfg }) } + +func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { + return newGenericOption(func(cfg Config) Config { + cfg.Traces.Proxy = pf + return cfg + }) +} From 147b4eb38575706e8490264652ab3c122789f187 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 17:56:02 +0200 Subject: [PATCH 05/19] add tests for new proxy configuration --- .../internal/oconf/options_test.go | 25 +++++++++++++++++++ .../internal/oconf/options_test.go | 25 +++++++++++++++++++ .../internal/otlpconfig/options_test.go | 25 +++++++++++++++++++ .../internal/otlpconfig/options_test.go | 25 +++++++++++++++++++ .../otlpmetric/oconf/options_test.go.tmpl | 25 +++++++++++++++++++ .../otlptrace/otlpconfig/options_test.go.tmpl | 25 +++++++++++++++++++ 6 files changed, 150 insertions(+) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go index b4631fb22c0..62bcfa7e256 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -19,6 +19,8 @@ package oconf import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -455,6 +457,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, metric.AggregationDrop{}, got(undefinedKind)) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Metrics.Proxy) + proxyUrl, err := c.Metrics.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Metrics.Proxy) + }, + }, } for _, tt := range tests { diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go index c20869e60e8..137a81bc721 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -19,6 +19,8 @@ package oconf import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -455,6 +457,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, metric.AggregationDrop{}, got(undefinedKind)) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Metrics.Proxy) + proxyUrl, err := c.Metrics.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Metrics.Proxy) + }, + }, } for _, tt := range tests { diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go index 254d38bef49..0f71f23876d 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -19,6 +19,8 @@ package otlpconfig import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -419,6 +421,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, c.Traces.Timeout, 5*time.Second) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Traces.Proxy) + proxyUrl, err := c.Traces.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Traces.Proxy) + }, + }, } for _, tt := range tests { diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go index 91d59985286..8b92179b640 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -19,6 +19,8 @@ package otlpconfig import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -419,6 +421,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, c.Traces.Timeout, 5*time.Second) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Traces.Proxy) + proxyUrl, err := c.Traces.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Traces.Proxy) + }, + }, } for _, tt := range tests { diff --git a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl index abd12c80ca7..fae0d20a7c5 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl @@ -19,6 +19,8 @@ package oconf import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -455,6 +457,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, metric.AggregationDrop{}, got(undefinedKind)) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Metrics.Proxy) + proxyURL, err := c.Metrics.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyURL.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Metrics.Proxy) + }, + }, } for _, tt := range tests { diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl index 8b614b0c47b..d0748c8582e 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl @@ -19,6 +19,8 @@ package otlpconfig import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -419,6 +421,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, c.Traces.Timeout, 5*time.Second) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Traces.Proxy) + proxyURL, err := c.Traces.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyURL.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Traces.Proxy) + }, + }, } for _, tt := range tests { From f754cef94013f1f2a804c6ac2cb154401e6fd6a9 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 18:54:15 +0200 Subject: [PATCH 06/19] options tests for proxy configuration --- .../otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go | 4 ++-- .../otlpmetric/otlpmetrichttp/internal/oconf/options_test.go | 4 ++-- .../otlptracegrpc/internal/otlpconfig/options_test.go | 4 ++-- .../otlptracehttp/internal/otlpconfig/options_test.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go index 62bcfa7e256..b46421cfee5 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -468,9 +468,9 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.NotNil(t, c.Metrics.Proxy) - proxyUrl, err := c.Metrics.Proxy(&http.Request{}) + proxyURL, err := c.Metrics.Proxy(&http.Request{}) assert.NoError(t, err) - assert.Equal(t, "http://proxy.com", proxyUrl.String()) + assert.Equal(t, "http://proxy.com", proxyURL.String()) }, }, { diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go index 137a81bc721..2217a7d6475 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -468,9 +468,9 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.NotNil(t, c.Metrics.Proxy) - proxyUrl, err := c.Metrics.Proxy(&http.Request{}) + proxyURL, err := c.Metrics.Proxy(&http.Request{}) assert.NoError(t, err) - assert.Equal(t, "http://proxy.com", proxyUrl.String()) + assert.Equal(t, "http://proxy.com", proxyURL.String()) }, }, { diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go index 0f71f23876d..e3a8a6021df 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -432,9 +432,9 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.NotNil(t, c.Traces.Proxy) - proxyUrl, err := c.Traces.Proxy(&http.Request{}) + proxyURL, err := c.Traces.Proxy(&http.Request{}) assert.NoError(t, err) - assert.Equal(t, "http://proxy.com", proxyUrl.String()) + assert.Equal(t, "http://proxy.com", proxyURL.String()) }, }, { diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go index 8b92179b640..e59071ed8be 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -432,9 +432,9 @@ func TestConfigs(t *testing.T) { }, asserts: func(t *testing.T, c *Config, grpcOption bool) { assert.NotNil(t, c.Traces.Proxy) - proxyUrl, err := c.Traces.Proxy(&http.Request{}) + proxyURL, err := c.Traces.Proxy(&http.Request{}) assert.NoError(t, err) - assert.Equal(t, "http://proxy.com", proxyUrl.String()) + assert.Equal(t, "http://proxy.com", proxyURL.String()) }, }, { From fd4bf04098cc30668ca7f080fa7f2d1834025c10 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 11 Feb 2024 18:56:30 +0200 Subject: [PATCH 07/19] rename WithProxyFunc to WithProxy to adhere to naming convention of the project --- .../otlpmetric/otlpmetricgrpc/internal/oconf/options.go | 2 +- .../otlpmetricgrpc/internal/oconf/options_test.go | 2 +- exporters/otlp/otlpmetric/otlpmetrichttp/config.go | 6 +++--- .../otlpmetric/otlpmetrichttp/internal/oconf/options.go | 2 +- .../otlpmetrichttp/internal/oconf/options_test.go | 2 +- .../otlptrace/otlptracegrpc/internal/otlpconfig/options.go | 2 +- .../otlptracegrpc/internal/otlpconfig/options_test.go | 2 +- .../otlptrace/otlptracehttp/internal/otlpconfig/options.go | 2 +- .../otlptracehttp/internal/otlpconfig/options_test.go | 2 +- internal/shared/otlp/otlpmetric/oconf/options.go.tmpl | 2 +- internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl | 2 +- internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl | 2 +- .../shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go index 0f144c299fb..2a9cd4e546f 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go @@ -377,7 +377,7 @@ func WithAggregationSelector(selector metric.AggregationSelector) GenericOption }) } -func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { +func WithProxy(pf HTTPTransportProxyFunc) GenericOption { return newGenericOption(func(cfg Config) Config { cfg.Metrics.Proxy = pf return cfg diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go index b46421cfee5..dfb9d7712db 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -462,7 +462,7 @@ func TestConfigs(t *testing.T) { { name: "Test With Proxy", opts: []GenericOption{ - WithProxyFunc(func(r *http.Request) (*url.URL, error) { + WithProxy(func(r *http.Request) (*url.URL, error) { return url.Parse("http://proxy.com") }), }, diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go index 4bc429306ad..058c4e83164 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go @@ -218,10 +218,10 @@ func WithAggregationSelector(selector metric.AggregationSelector) Option { return wrappedOption{oconf.WithAggregationSelector(selector)} } -// WithProxyFunc sets the Proxy function the client will use to determine the +// WithProxy sets the Proxy function the client will use to determine the // proxy to use for an HTTP request. If this option is not used, the client // will use the default proxy settings from the // exporters/otlp/otlpmetric/otlpmetrichttp package (adhering to the Golang's DefaultTransport from net/http). -func WithProxyFunc(pf oconf.HTTPTransportProxyFunc) Option { - return wrappedOption{oconf.WithProxyFunc(pf)} +func WithProxy(pf oconf.HTTPTransportProxyFunc) Option { + return wrappedOption{oconf.WithProxy(pf)} } diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go index e3286055ddc..3ae97824695 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go @@ -377,7 +377,7 @@ func WithAggregationSelector(selector metric.AggregationSelector) GenericOption }) } -func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { +func WithProxy(pf HTTPTransportProxyFunc) GenericOption { return newGenericOption(func(cfg Config) Config { cfg.Metrics.Proxy = pf return cfg diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go index 2217a7d6475..70595ef3113 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -462,7 +462,7 @@ func TestConfigs(t *testing.T) { { name: "Test With Proxy", opts: []GenericOption{ - WithProxyFunc(func(r *http.Request) (*url.URL, error) { + WithProxy(func(r *http.Request) (*url.URL, error) { return url.Parse("http://proxy.com") }), }, diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go index af48334ebf6..485e12d8488 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go @@ -349,7 +349,7 @@ func WithTimeout(duration time.Duration) GenericOption { }) } -func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { +func WithProxy(pf HTTPTransportProxyFunc) GenericOption { return newGenericOption(func(cfg Config) Config { cfg.Traces.Proxy = pf return cfg diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go index e3a8a6021df..5bbe38969d2 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -426,7 +426,7 @@ func TestConfigs(t *testing.T) { { name: "Test With Proxy", opts: []GenericOption{ - WithProxyFunc(func(r *http.Request) (*url.URL, error) { + WithProxy(func(r *http.Request) (*url.URL, error) { return url.Parse("http://proxy.com") }), }, diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go index 996d67620fe..0d116f69a9b 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go @@ -349,7 +349,7 @@ func WithTimeout(duration time.Duration) GenericOption { }) } -func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { +func WithProxy(pf HTTPTransportProxyFunc) GenericOption { return newGenericOption(func(cfg Config) Config { cfg.Traces.Proxy = pf return cfg diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go index e59071ed8be..72b57202410 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -426,7 +426,7 @@ func TestConfigs(t *testing.T) { { name: "Test With Proxy", opts: []GenericOption{ - WithProxyFunc(func(r *http.Request) (*url.URL, error) { + WithProxy(func(r *http.Request) (*url.URL, error) { return url.Parse("http://proxy.com") }), }, diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 158483d80c3..1a550e6f2f5 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -377,7 +377,7 @@ func WithAggregationSelector(selector metric.AggregationSelector) GenericOption }) } -func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { +func WithProxy(pf HTTPTransportProxyFunc) GenericOption { return newGenericOption(func(cfg Config) Config { cfg.Metrics.Proxy = pf return cfg diff --git a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl index fae0d20a7c5..ea80af285d6 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl @@ -462,7 +462,7 @@ func TestConfigs(t *testing.T) { { name: "Test With Proxy", opts: []GenericOption{ - WithProxyFunc(func(r *http.Request) (*url.URL, error) { + WithProxy(func(r *http.Request) (*url.URL, error) { return url.Parse("http://proxy.com") }), }, diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl index ce921bb53a0..ff6979f4a09 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl @@ -349,7 +349,7 @@ func WithTimeout(duration time.Duration) GenericOption { }) } -func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption { +func WithProxy(pf HTTPTransportProxyFunc) GenericOption { return newGenericOption(func(cfg Config) Config { cfg.Traces.Proxy = pf return cfg diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl index d0748c8582e..c750149ccaa 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl @@ -426,7 +426,7 @@ func TestConfigs(t *testing.T) { { name: "Test With Proxy", opts: []GenericOption{ - WithProxyFunc(func(r *http.Request) (*url.URL, error) { + WithProxy(func(r *http.Request) (*url.URL, error) { return url.Parse("http://proxy.com") }), }, From 8e8da1eb61c579bf562e7620c83fd8aed42b7b00 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Mon, 12 Feb 2024 11:54:30 +0200 Subject: [PATCH 08/19] update changelog with PR id and expand description --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f827fdcde7c..88f34eaa3e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ The next release will require at least [Go 1.21]. ### Added - Support [Go 1.22]. (#4890) -- Support configuring a custom Proxy Function for the `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` HTTP Client Transport. +- Support configuring a custom Proxy Function for the metric: `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` and trace: `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp` OTLP Exporter HTTP Client Transport. (#4906) ## [1.23.1] 2024-02-07 From 8b96a0cfaec1ee326f44648768a77abf654d9afc Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Wed, 14 Feb 2024 11:22:26 +0200 Subject: [PATCH 09/19] add test and withproxy config to trace client --- .../otlpmetric/otlpmetrichttp/client_test.go | 19 +++++++++++++++++++ .../otlptrace/otlptracehttp/client_test.go | 19 +++++++++++++++++++ .../otlp/otlptrace/otlptracehttp/options.go | 8 ++++++++ 3 files changed, 46 insertions(+) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go index f631c49fe2e..5d302d51159 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "net/http" + "net/url" "strings" "testing" "time" @@ -238,4 +239,22 @@ func TestConfig(t *testing.T) { require.Contains(t, got, key) assert.Equal(t, got[key], []string{headers[key]}) }) + + t.Run("WithProxy", func(t *testing.T) { + headerKeySetInProxy := http.CanonicalHeaderKey("X-Using-Proxy") + headerValueSetInProxy := "true" + exp, coll := factoryFunc("", nil, WithProxy(func(r *http.Request) (*url.URL, error) { + r.Header.Set(headerKeySetInProxy, headerValueSetInProxy) + return r.URL, nil + })) + ctx := context.Background() + t.Cleanup(func() { require.NoError(t, coll.Shutdown(ctx)) }) + require.NoError(t, exp.Export(ctx, &metricdata.ResourceMetrics{})) + // Ensure everything is flushed. + require.NoError(t, exp.Shutdown(ctx)) + + got := coll.Headers() + require.Contains(t, got, headerKeySetInProxy) + assert.Equal(t, got[headerKeySetInProxy], []string{headerValueSetInProxy}) + }) } diff --git a/exporters/otlp/otlptrace/otlptracehttp/client_test.go b/exporters/otlp/otlptrace/otlptracehttp/client_test.go index 73bd3efaedd..b4bc2f4cfa5 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client_test.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "net/http" + "net/url" "strings" "testing" "time" @@ -47,6 +48,10 @@ var ( customUserAgentHeader = map[string]string{ "user-agent": "custome-user-agent", } + + customProxyHeader = map[string]string{ + "header-added-via-proxy": "proxy-value", + } ) func TestEndToEnd(t *testing.T) { @@ -161,6 +166,20 @@ func TestEndToEnd(t *testing.T) { ExpectedHeaders: customUserAgentHeader, }, }, + { + name: "with custom proxy", + opts: []otlptracehttp.Option{ + otlptracehttp.WithProxy(func(r *http.Request) (*url.URL, error) { + for k, v := range customProxyHeader { + r.Header.Set(k, v) + } + return r.URL, nil + }), + }, + mcCfg: mockCollectorConfig{ + ExpectedHeaders: customProxyHeader, + }, + }, } for _, tc := range tests { diff --git a/exporters/otlp/otlptrace/otlptracehttp/options.go b/exporters/otlp/otlptrace/otlptracehttp/options.go index ea6b767a27f..c2c7c7992d2 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/options.go @@ -143,3 +143,11 @@ func WithTimeout(duration time.Duration) Option { func WithRetry(rc RetryConfig) Option { return wrappedOption{otlpconfig.WithRetry(retry.Config(rc))} } + +// WithProxy sets the Proxy function the client will use to determine the +// proxy to use for an HTTP request. If this option is not used, the client +// will use the default proxy settings from the +// exporters/otlp/otlpmetric/otlptracehttp package (adhering to the Golang's DefaultTransport from net/http). +func WithProxy(pf otlpconfig.HTTPTransportProxyFunc) Option { + return wrappedOption{otlpconfig.WithProxy(pf)} +} From fced1c55e6f47bca3017cad6b6ee8f69a7124c2e Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Thu, 15 Feb 2024 10:26:33 +0200 Subject: [PATCH 10/19] only clone transport if needed --- .../otlp/otlpmetric/otlpmetrichttp/client.go | 19 ++++++++++++------- .../otlp/otlptrace/otlptracehttp/client.go | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index 33e80a240e7..232c345aafb 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -65,16 +65,21 @@ var ourTransport = &http.Transport{ // newClient creates a new HTTP metric client. func newClient(cfg oconf.Config) (*client, error) { - clonedTransport := ourTransport.Clone() httpClient := &http.Client{ - Transport: clonedTransport, + Transport: ourTransport, Timeout: cfg.Metrics.Timeout, } - if cfg.Metrics.TLSCfg != nil { - clonedTransport.TLSClientConfig = cfg.Metrics.TLSCfg - } - if cfg.Metrics.Proxy != nil { - clonedTransport.Proxy = cfg.Metrics.Proxy + + if cfg.Metrics.TLSCfg != nil || cfg.Metrics.Proxy != nil { + clonedTransport := ourTransport.Clone() + httpClient.Transport = clonedTransport + + if cfg.Metrics.TLSCfg != nil { + clonedTransport.TLSClientConfig = cfg.Metrics.TLSCfg + } + if cfg.Metrics.Proxy != nil { + clonedTransport.Proxy = cfg.Metrics.Proxy + } } u := &url.URL{ diff --git a/exporters/otlp/otlptrace/otlptracehttp/client.go b/exporters/otlp/otlptrace/otlptracehttp/client.go index d9e68606b3f..60d1681ccc9 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client.go @@ -81,16 +81,21 @@ var _ otlptrace.Client = (*client)(nil) func NewClient(opts ...Option) otlptrace.Client { cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(opts)...) - clonedTransport := ourTransport.Clone() httpClient := &http.Client{ - Transport: clonedTransport, + Transport: ourTransport, Timeout: cfg.Traces.Timeout, } - if cfg.Traces.TLSCfg != nil { - clonedTransport.TLSClientConfig = cfg.Traces.TLSCfg - } - if cfg.Traces.Proxy != nil { - clonedTransport.Proxy = cfg.Traces.Proxy + + if cfg.Traces.TLSCfg != nil || cfg.Traces.Proxy != nil { + clonedTransport := ourTransport.Clone() + httpClient.Transport = clonedTransport + + if cfg.Traces.TLSCfg != nil { + clonedTransport.TLSClientConfig = cfg.Traces.TLSCfg + } + if cfg.Traces.Proxy != nil { + clonedTransport.Proxy = cfg.Traces.Proxy + } } stopCh := make(chan struct{}) From 8919bbf9910c0b8195199e42530a48fdd599cd9c Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Thu, 15 Feb 2024 10:27:29 +0200 Subject: [PATCH 11/19] lint --- exporters/otlp/otlpmetric/otlpmetrichttp/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index 232c345aafb..5f3c7144c8d 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -69,7 +69,7 @@ func newClient(cfg oconf.Config) (*client, error) { Transport: ourTransport, Timeout: cfg.Metrics.Timeout, } - + if cfg.Metrics.TLSCfg != nil || cfg.Metrics.Proxy != nil { clonedTransport := ourTransport.Clone() httpClient.Transport = clonedTransport From b6d75e51ca6321698ff25adbba1d821c19232b3e Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 25 Feb 2024 14:05:23 +0200 Subject: [PATCH 12/19] rewrite changes for WithProxy option --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c891974e15c..db6f8b29942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ The next release will require at least [Go 1.21]. - Support [Go 1.22]. (#4890) - Add exemplar support to `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#4900) - Add exemplar support to `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4900) +- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906) +- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906) - The `go.opentelemetry.io/otel/log` module is added. This module includes OpenTelemetry Go's implementation of the Logs Bridge API. This module is in an alpha state, it is subject to breaking changes. @@ -27,8 +29,6 @@ The next release will require at least [Go 1.21]. - Fix registration of multiple callbacks when using the global meter provider from `go.opentelemetry.io/otel`. (#4945) - Fix negative buckets in output of exponential histograms. (#4956) -- Add custom Proxy function support to: `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906) -- Add custom Proxy function support to: `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906) ## [1.23.1] 2024-02-07 From 26e48c49ed0d5ccc22f612ef65b09c413c1a98a8 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 25 Feb 2024 14:08:04 +0200 Subject: [PATCH 13/19] update documentation for default of WithProxy option --- exporters/otlp/otlpmetric/otlpmetrichttp/config.go | 3 +-- exporters/otlp/otlptrace/otlptracehttp/options.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go index 058c4e83164..e5f1ce9c389 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go @@ -220,8 +220,7 @@ func WithAggregationSelector(selector metric.AggregationSelector) Option { // WithProxy sets the Proxy function the client will use to determine the // proxy to use for an HTTP request. If this option is not used, the client -// will use the default proxy settings from the -// exporters/otlp/otlpmetric/otlpmetrichttp package (adhering to the Golang's DefaultTransport from net/http). +// will use [http.ProxyFromEnvironment]. func WithProxy(pf oconf.HTTPTransportProxyFunc) Option { return wrappedOption{oconf.WithProxy(pf)} } diff --git a/exporters/otlp/otlptrace/otlptracehttp/options.go b/exporters/otlp/otlptrace/otlptracehttp/options.go index be65dcc2f2c..c3edcbf17e4 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/options.go @@ -146,8 +146,7 @@ func WithRetry(rc RetryConfig) Option { // WithProxy sets the Proxy function the client will use to determine the // proxy to use for an HTTP request. If this option is not used, the client -// will use the default proxy settings from the -// exporters/otlp/otlpmetric/otlptracehttp package (adhering to the Golang's DefaultTransport from net/http). +// will use [http.ProxyFromEnvironment]. func WithProxy(pf otlpconfig.HTTPTransportProxyFunc) Option { return wrappedOption{otlpconfig.WithProxy(pf)} } From acf4fa147b1028793c0b7bff15a3ebcb7c5ffb2b Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 25 Feb 2024 14:29:59 +0200 Subject: [PATCH 14/19] add documentation to type --- .../otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go | 2 ++ .../otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go | 2 ++ .../otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go | 2 ++ internal/shared/otlp/otlpmetric/oconf/options.go.tmpl | 2 ++ internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl | 2 ++ 5 files changed, 10 insertions(+) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go index 3ae97824695..927592e595c 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go @@ -54,6 +54,8 @@ const ( ) type ( + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. + // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go index 485e12d8488..5f6936f015e 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go @@ -47,6 +47,8 @@ const ( ) type ( + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. + // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go index 0d116f69a9b..0a98da5cdd9 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go @@ -47,6 +47,8 @@ const ( ) type ( + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. + // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 1a550e6f2f5..5e9f075b1bd 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -54,6 +54,8 @@ const ( ) type ( + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. + // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl index ff6979f4a09..f138acf156d 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl @@ -47,6 +47,8 @@ const ( ) type ( + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. + // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { From e5a82c6efebbebf21ca241e6833d2b23e0c956eb Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Sun, 25 Feb 2024 14:31:09 +0200 Subject: [PATCH 15/19] generate options --- .../otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go index 2a9cd4e546f..9b1a76b2d2c 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go @@ -54,6 +54,8 @@ const ( ) type ( + // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. + // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { From 274dd8cc5f79908131e8aae7f2ed2ecca4505c1d Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Wed, 6 Mar 2024 14:43:00 +0200 Subject: [PATCH 16/19] add public type for HTTPTransportProxyFunc --- exporters/otlp/otlpmetric/otlpmetrichttp/config.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go index 8c685d3011d..28b058e1634 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/config.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/config.go @@ -5,6 +5,8 @@ package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpme import ( "crypto/tls" + "net/http" + "net/url" "time" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf" @@ -16,6 +18,11 @@ import ( // collector. type Compression oconf.Compression +// HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. +// This type is compatible with http.Transport.Proxy and can be used to set a custom proxy function +// to the OTLP HTTP client. +type HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + const ( // NoCompression tells the driver to send payloads without // compression. @@ -210,6 +217,6 @@ func WithAggregationSelector(selector metric.AggregationSelector) Option { // WithProxy sets the Proxy function the client will use to determine the // proxy to use for an HTTP request. If this option is not used, the client // will use [http.ProxyFromEnvironment]. -func WithProxy(pf oconf.HTTPTransportProxyFunc) Option { - return wrappedOption{oconf.WithProxy(pf)} +func WithProxy(pf HTTPTransportProxyFunc) Option { + return wrappedOption{oconf.WithProxy(oconf.HTTPTransportProxyFunc(pf))} } From a1320f556ec6e361c7666d49eca332bedb7002ee Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Wed, 6 Mar 2024 17:09:00 +0200 Subject: [PATCH 17/19] add public type for HTTPTransportProxyFunc --- exporters/otlp/otlptrace/otlptracehttp/options.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/exporters/otlp/otlptrace/otlptracehttp/options.go b/exporters/otlp/otlptrace/otlptracehttp/options.go index ed204403b56..a3bb2b66faa 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/options.go @@ -5,6 +5,8 @@ package otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptra import ( "crypto/tls" + "net/http" + "net/url" "time" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig" @@ -15,6 +17,11 @@ import ( // collector. type Compression otlpconfig.Compression +// HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. +// This type is compatible with http.Transport.Proxy and can be used to set a custom proxy function +// to the OTLP HTTP client. +type HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) + const ( // NoCompression tells the driver to send payloads without // compression. @@ -136,6 +143,6 @@ func WithRetry(rc RetryConfig) Option { // WithProxy sets the Proxy function the client will use to determine the // proxy to use for an HTTP request. If this option is not used, the client // will use [http.ProxyFromEnvironment]. -func WithProxy(pf otlpconfig.HTTPTransportProxyFunc) Option { - return wrappedOption{otlpconfig.WithProxy(pf)} +func WithProxy(pf HTTPTransportProxyFunc) Option { + return wrappedOption{otlpconfig.WithProxy(otlpconfig.HTTPTransportProxyFunc(pf))} } From 00e596c3ce40e12348b1fdcb5751a8a980df63c4 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Wed, 6 Mar 2024 17:39:11 +0200 Subject: [PATCH 18/19] fix changelog due to bad merge, move WithProxy additions to Unreleased section --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b51cb4d1710..81d4fae50b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - Clarify the documentation about equivalence guarantees for the `Set` and `Distinct` types in `go.opentelemetry.io/otel/attribute`. (#5027) +- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906) +- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906) ### Removed @@ -26,8 +28,6 @@ The next release will require at least [Go 1.21]. - Support [Go 1.22]. (#4890) - Add exemplar support to `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#4900) - Add exemplar support to `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4900) -- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906) -- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906) - The `go.opentelemetry.io/otel/log` module is added. This module includes OpenTelemetry Go's implementation of the Logs Bridge API. This module is in an alpha state, it is subject to breaking changes. @@ -2859,7 +2859,8 @@ It contains api and sdk for trace and meter. - CircleCI build CI manifest files. - CODEOWNERS file to track owners of this project. -[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.23.1...HEAD +[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.24.0...HEAD +[1.24.0/0.46.0/0.0.1-alpha]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.24.0 [1.23.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.23.1 [1.23.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.23.0 [1.23.0-rc.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.23.0-rc.1 From 21eda4bfb723ba65c263fde843ce8ef4d225a1a1 Mon Sep 17 00:00:00 2001 From: Mickael Alliel Date: Mon, 11 Mar 2024 13:29:28 +0200 Subject: [PATCH 19/19] fix changelog after main branch merge --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d4fae50b1..d27ec9b0663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] -### Fixed +### Added -- Clarify the documentation about equivalence guarantees for the `Set` and `Distinct` types in `go.opentelemetry.io/otel/attribute`. (#5027) - Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906) - Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906) +### Fixed + +- Clarify the documentation about equivalence guarantees for the `Set` and `Distinct` types in `go.opentelemetry.io/otel/attribute`. (#5027) + ### Removed - Drop support for [Go 1.20]. (#4967)