You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Override insecure when endpoint URL is set (#5944)
When an endpoint is set in both Environment variable with "http" and passed in WithEndpointURL with "https", Insecure is set to true while the endpoint is used from WithEndpointURL. Example - OTEL_EXPORTER_OTLP_ENDPOINT is set to "http://env.endpoint/prefix" - WithEndpointURL is passed "https://someendpoint/somepath" The real endpoint used is "http://someendpoint/somepath", which is actually neither of both. --------- Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
@@ -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)
|
- 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 `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
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,21 @@ func TestNewConfig(t *testing.T) {
|
|||||||
retryCfg: newSetting(defaultRetryCfg),
|
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",
|
name: "LogEnvironmentVariables",
|
||||||
envars: map[string]string{
|
envars: map[string]string{
|
||||||
@@ -235,6 +250,21 @@ func TestNewConfig(t *testing.T) {
|
|||||||
retryCfg: newSetting(defaultRetryCfg),
|
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",
|
name: "EnvironmentVariablesPrecedence",
|
||||||
envars: map[string]string{
|
envars: map[string]string{
|
||||||
|
|||||||
@@ -183,11 +183,7 @@ func WithEndpointURL(rawURL string) Option {
|
|||||||
return fnOpt(func(c config) config {
|
return fnOpt(func(c config) config {
|
||||||
c.endpoint = newSetting(u.Host)
|
c.endpoint = newSetting(u.Host)
|
||||||
c.path = newSetting(u.Path)
|
c.path = newSetting(u.Path)
|
||||||
if u.Scheme != "https" {
|
c.insecure = newSetting(u.Scheme != "https")
|
||||||
c.insecure = newSetting(true)
|
|
||||||
} else {
|
|
||||||
c.insecure = newSetting(false)
|
|
||||||
}
|
|
||||||
return c
|
return c
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,6 +167,38 @@ func TestNewConfig(t *testing.T) {
|
|||||||
retryCfg: newSetting(defaultRetryCfg),
|
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",
|
name: "LogEnvironmentVariables",
|
||||||
envars: map[string]string{
|
envars: map[string]string{
|
||||||
|
|||||||
@@ -287,9 +287,7 @@ func WithEndpointURL(v string) GenericOption {
|
|||||||
|
|
||||||
cfg.Metrics.Endpoint = u.Host
|
cfg.Metrics.Endpoint = u.Host
|
||||||
cfg.Metrics.URLPath = u.Path
|
cfg.Metrics.URLPath = u.Path
|
||||||
if u.Scheme != "https" {
|
cfg.Metrics.Insecure = u.Scheme != "https"
|
||||||
cfg.Metrics.Insecure = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -149,6 +149,34 @@ func TestConfigs(t *testing.T) {
|
|||||||
assert.Equal(t, "someendpoint", c.Metrics.Endpoint)
|
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",
|
name: "Test Environment Endpoint",
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
|
|||||||
@@ -287,9 +287,7 @@ func WithEndpointURL(v string) GenericOption {
|
|||||||
|
|
||||||
cfg.Metrics.Endpoint = u.Host
|
cfg.Metrics.Endpoint = u.Host
|
||||||
cfg.Metrics.URLPath = u.Path
|
cfg.Metrics.URLPath = u.Path
|
||||||
if u.Scheme != "https" {
|
cfg.Metrics.Insecure = u.Scheme != "https"
|
||||||
cfg.Metrics.Insecure = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -149,6 +149,34 @@ func TestConfigs(t *testing.T) {
|
|||||||
assert.Equal(t, "someendpoint", c.Metrics.Endpoint)
|
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",
|
name: "Test Environment Endpoint",
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
|
|||||||
@@ -278,9 +278,7 @@ func WithEndpointURL(v string) GenericOption {
|
|||||||
|
|
||||||
cfg.Traces.Endpoint = u.Host
|
cfg.Traces.Endpoint = u.Host
|
||||||
cfg.Traces.URLPath = u.Path
|
cfg.Traces.URLPath = u.Path
|
||||||
if u.Scheme != "https" {
|
cfg.Traces.Insecure = u.Scheme != "https"
|
||||||
cfg.Traces.Insecure = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -147,6 +147,20 @@ func TestConfigs(t *testing.T) {
|
|||||||
assert.Equal(t, "someendpoint", c.Traces.Endpoint)
|
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",
|
name: "Test Environment Endpoint",
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
|
|||||||
@@ -278,9 +278,7 @@ func WithEndpointURL(v string) GenericOption {
|
|||||||
|
|
||||||
cfg.Traces.Endpoint = u.Host
|
cfg.Traces.Endpoint = u.Host
|
||||||
cfg.Traces.URLPath = u.Path
|
cfg.Traces.URLPath = u.Path
|
||||||
if u.Scheme != "https" {
|
cfg.Traces.Insecure = u.Scheme != "https"
|
||||||
cfg.Traces.Insecure = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -147,6 +147,20 @@ func TestConfigs(t *testing.T) {
|
|||||||
assert.Equal(t, "someendpoint", c.Traces.Endpoint)
|
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",
|
name: "Test Environment Endpoint",
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
|
|||||||
@@ -287,9 +287,7 @@ func WithEndpointURL(v string) GenericOption {
|
|||||||
|
|
||||||
cfg.Metrics.Endpoint = u.Host
|
cfg.Metrics.Endpoint = u.Host
|
||||||
cfg.Metrics.URLPath = u.Path
|
cfg.Metrics.URLPath = u.Path
|
||||||
if u.Scheme != "https" {
|
cfg.Metrics.Insecure = u.Scheme != "https"
|
||||||
cfg.Metrics.Insecure = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -149,6 +149,34 @@ func TestConfigs(t *testing.T) {
|
|||||||
assert.Equal(t, "someendpoint", c.Metrics.Endpoint)
|
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",
|
name: "Test Environment Endpoint",
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
|
|||||||
@@ -278,9 +278,7 @@ func WithEndpointURL(v string) GenericOption {
|
|||||||
|
|
||||||
cfg.Traces.Endpoint = u.Host
|
cfg.Traces.Endpoint = u.Host
|
||||||
cfg.Traces.URLPath = u.Path
|
cfg.Traces.URLPath = u.Path
|
||||||
if u.Scheme != "https" {
|
cfg.Traces.Insecure = u.Scheme != "https"
|
||||||
cfg.Traces.Insecure = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -147,6 +147,20 @@ func TestConfigs(t *testing.T) {
|
|||||||
assert.Equal(t, "someendpoint", c.Traces.Endpoint)
|
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",
|
name: "Test Environment Endpoint",
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
|
|||||||
Reference in New Issue
Block a user