diff --git a/CHANGELOG.md b/CHANGELOG.md index d3636e22d58..9fc7aa395a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Global MeterProvider registration unwraps global instrument Observers, the undocumented Unwrap() methods are now private. (#5881) - Fix `go.opentelemetry.io/otel/exporters/prometheus` trying to add exemplars to Gauge metrics, which is unsupported. (#5912) +- Fix `WithEndpointURL` to always use a secure connection when an https URL is passed in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#5944) +- Fix `WithEndpointURL` to always use a secure connection when an https URL is passed in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#5944) +- Fix `WithEndpointURL` to always use a secure connection when an https URL is passed in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#5944) +- Fix `WithEndpointURL` to always use a secure connection when an https URL is passed in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5944) ### Changed diff --git a/exporters/otlp/otlplog/otlploggrpc/config_test.go b/exporters/otlp/otlplog/otlploggrpc/config_test.go index 51d864b6282..cb21786b2c4 100644 --- a/exporters/otlp/otlplog/otlploggrpc/config_test.go +++ b/exporters/otlp/otlplog/otlploggrpc/config_test.go @@ -169,6 +169,21 @@ func TestNewConfig(t *testing.T) { retryCfg: newSetting(defaultRetryCfg), }, }, + { + name: "WithEndpointURL secure when Environment Endpoint is set insecure", + envars: map[string]string{ + "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "http://env.endpoint:8080/prefix", + }, + options: []Option{ + WithEndpointURL("https://test:8080/path"), + }, + want: config{ + endpoint: newSetting("test:8080"), + insecure: newSetting(false), + timeout: newSetting(defaultTimeout), + retryCfg: newSetting(defaultRetryCfg), + }, + }, { name: "LogEnvironmentVariables", envars: map[string]string{ @@ -235,6 +250,21 @@ func TestNewConfig(t *testing.T) { retryCfg: newSetting(defaultRetryCfg), }, }, + { + name: "WithEndpointURL secure when Environment insecure is set false", + envars: map[string]string{ + "OTEL_EXPORTER_OTLP_LOGS_INSECURE": "true", + }, + options: []Option{ + WithEndpointURL("https://test:8080/path"), + }, + want: config{ + endpoint: newSetting("test:8080"), + insecure: newSetting(false), + timeout: newSetting(defaultTimeout), + retryCfg: newSetting(defaultRetryCfg), + }, + }, { name: "EnvironmentVariablesPrecedence", envars: map[string]string{ diff --git a/exporters/otlp/otlplog/otlploghttp/config.go b/exporters/otlp/otlplog/otlploghttp/config.go index f348672f466..bfe768091e3 100644 --- a/exporters/otlp/otlplog/otlploghttp/config.go +++ b/exporters/otlp/otlplog/otlploghttp/config.go @@ -183,11 +183,7 @@ func WithEndpointURL(rawURL string) Option { return fnOpt(func(c config) config { c.endpoint = newSetting(u.Host) c.path = newSetting(u.Path) - if u.Scheme != "https" { - c.insecure = newSetting(true) - } else { - c.insecure = newSetting(false) - } + c.insecure = newSetting(u.Scheme != "https") return c }) } diff --git a/exporters/otlp/otlplog/otlploghttp/config_test.go b/exporters/otlp/otlplog/otlploghttp/config_test.go index 456499a5886..1a7568921db 100644 --- a/exporters/otlp/otlplog/otlploghttp/config_test.go +++ b/exporters/otlp/otlplog/otlploghttp/config_test.go @@ -167,6 +167,38 @@ func TestNewConfig(t *testing.T) { retryCfg: newSetting(defaultRetryCfg), }, }, + { + name: "WithEndpointURL secure when Environment Endpoint is set insecure", + envars: map[string]string{ + "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "http://env.endpoint:8080/prefix", + }, + options: []Option{ + WithEndpointURL("https://test:8080/path"), + }, + want: config{ + endpoint: newSetting("test:8080"), + path: newSetting("/path"), + insecure: newSetting(false), + timeout: newSetting(defaultTimeout), + retryCfg: newSetting(defaultRetryCfg), + }, + }, + { + name: "WithEndpointURL secure when Environment insecure is set false", + envars: map[string]string{ + "OTEL_EXPORTER_OTLP_LOGS_INSECURE": "true", + }, + options: []Option{ + WithEndpointURL("https://test:8080/path"), + }, + want: config{ + endpoint: newSetting("test:8080"), + path: newSetting("/path"), + insecure: newSetting(false), + timeout: newSetting(defaultTimeout), + retryCfg: newSetting(defaultRetryCfg), + }, + }, { name: "LogEnvironmentVariables", envars: map[string]string{ diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go index f66c471212f..c016b4dbe97 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go @@ -287,9 +287,7 @@ func WithEndpointURL(v string) GenericOption { cfg.Metrics.Endpoint = u.Host cfg.Metrics.URLPath = u.Path - if u.Scheme != "https" { - cfg.Metrics.Insecure = true - } + cfg.Metrics.Insecure = u.Scheme != "https" 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 53092631ea6..41816152733 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -149,6 +149,34 @@ func TestConfigs(t *testing.T) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) }, }, + { + name: "Test With WithEndpointURL secure when Environment Endpoint is set insecure", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://env.endpoint/prefix", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Metrics.Endpoint) + assert.Equal(t, "/somepath", c.Metrics.URLPath) + assert.False(t, c.Metrics.Insecure) + }, + }, + { + name: "Test With WithEndpointURL secure when Environment insecure is set true", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_INSECURE": "true", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Metrics.Endpoint) + assert.Equal(t, "/somepath", c.Metrics.URLPath) + assert.False(t, c.Metrics.Insecure) + }, + }, { name: "Test Environment Endpoint", env: map[string]string{ diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go index 9a582cdbbaa..33363193de5 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go @@ -287,9 +287,7 @@ func WithEndpointURL(v string) GenericOption { cfg.Metrics.Endpoint = u.Host cfg.Metrics.URLPath = u.Path - if u.Scheme != "https" { - cfg.Metrics.Insecure = true - } + cfg.Metrics.Insecure = u.Scheme != "https" 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 0445e3786ab..36858bc3077 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -149,6 +149,34 @@ func TestConfigs(t *testing.T) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) }, }, + { + name: "Test With WithEndpointURL secure when Environment Endpoint is set insecure", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://env.endpoint/prefix", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Metrics.Endpoint) + assert.Equal(t, "/somepath", c.Metrics.URLPath) + assert.False(t, c.Metrics.Insecure) + }, + }, + { + name: "Test With WithEndpointURL secure when Environment insecure is set true", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_INSECURE": "true", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Metrics.Endpoint) + assert.Equal(t, "/somepath", c.Metrics.URLPath) + assert.False(t, c.Metrics.Insecure) + }, + }, { name: "Test Environment Endpoint", env: map[string]string{ diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go index 8d4b4bf0898..3ee452ef72b 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go @@ -278,9 +278,7 @@ func WithEndpointURL(v string) GenericOption { cfg.Traces.Endpoint = u.Host cfg.Traces.URLPath = u.Path - if u.Scheme != "https" { - cfg.Traces.Insecure = true - } + cfg.Traces.Insecure = u.Scheme != "https" 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 56b540a5970..47c984f6cf1 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -147,6 +147,20 @@ func TestConfigs(t *testing.T) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) }, }, + { + name: "Test With WithEndpointURL secure when Environment Endpoint is set insecure", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://env.endpoint/prefix", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Traces.Endpoint) + assert.Equal(t, "/somepath", c.Traces.URLPath) + assert.False(t, c.Traces.Insecure) + }, + }, { name: "Test Environment Endpoint", env: map[string]string{ diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go index 4cfd6c27f58..131906b1ff3 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go @@ -278,9 +278,7 @@ func WithEndpointURL(v string) GenericOption { cfg.Traces.Endpoint = u.Host cfg.Traces.URLPath = u.Path - if u.Scheme != "https" { - cfg.Traces.Insecure = true - } + cfg.Traces.Insecure = u.Scheme != "https" 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 7a09669343d..55a3ad96986 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -147,6 +147,20 @@ func TestConfigs(t *testing.T) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) }, }, + { + name: "Test With WithEndpointURL secure when Environment Endpoint is set insecure", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://env.endpoint/prefix", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Traces.Endpoint) + assert.Equal(t, "/somepath", c.Traces.URLPath) + assert.False(t, c.Traces.Insecure) + }, + }, { name: "Test Environment Endpoint", env: map[string]string{ diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 1f7cc658768..f6a21c6137e 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -287,9 +287,7 @@ func WithEndpointURL(v string) GenericOption { cfg.Metrics.Endpoint = u.Host cfg.Metrics.URLPath = u.Path - if u.Scheme != "https" { - cfg.Metrics.Insecure = true - } + cfg.Metrics.Insecure = u.Scheme != "https" 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 5a136567cb5..9e2862e835d 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl @@ -149,6 +149,34 @@ func TestConfigs(t *testing.T) { assert.Equal(t, "someendpoint", c.Metrics.Endpoint) }, }, + { + name: "Test With WithEndpointURL secure when Environment Endpoint is set insecure", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://env.endpoint/prefix", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Metrics.Endpoint) + assert.Equal(t, "/somepath", c.Metrics.URLPath) + assert.False(t, c.Metrics.Insecure) + }, + }, + { + name: "Test With WithEndpointURL secure when Environment insecure is set true", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_INSECURE": "true", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Metrics.Endpoint) + assert.Equal(t, "/somepath", c.Metrics.URLPath) + assert.False(t, c.Metrics.Insecure) + }, + }, { name: "Test Environment Endpoint", env: map[string]string{ diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl index a7f79c3efb4..e99663f3cfd 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl @@ -278,9 +278,7 @@ func WithEndpointURL(v string) GenericOption { cfg.Traces.Endpoint = u.Host cfg.Traces.URLPath = u.Path - if u.Scheme != "https" { - cfg.Traces.Insecure = true - } + cfg.Traces.Insecure = u.Scheme != "https" 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 8bbc8a1c974..9170ce71dc7 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl @@ -147,6 +147,20 @@ func TestConfigs(t *testing.T) { assert.Equal(t, "someendpoint", c.Traces.Endpoint) }, }, + { + name: "Test With WithEndpointURL secure when Environment Endpoint is set insecure", + env: map[string]string{ + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://env.endpoint/prefix", + }, + opts: []GenericOption{ + WithEndpointURL("https://someendpoint/somepath"), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Equal(t, "someendpoint", c.Traces.Endpoint) + assert.Equal(t, "/somepath", c.Traces.URLPath) + assert.False(t, c.Traces.Insecure) + }, + }, { name: "Test Environment Endpoint", env: map[string]string{