diff --git a/CHANGELOG.md b/CHANGELOG.md index baab4d165f4..9d8c6b5b25e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - Prometheus exporter will register with a prometheus registerer on creation, there are options to control this. (#3239) +- OTLP exporters now recognize: + - `OTEL_EXPORTER_OTLP_INSECURE` + - `OTEL_EXPORTER_OTLP_TRACES_INSECURE` + - `OTEL_EXPORTER_OTLP_METRICS_INSECURE` + - `OTEL_EXPORTER_OTLP_CLIENT_KEY` + - `OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY` + - `OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY` + - `OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE` + - `OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE` + - `OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE` ### Changed diff --git a/exporters/otlp/internal/envconfig/envconfig.go b/exporters/otlp/internal/envconfig/envconfig.go index d97da06a35e..eb5b0a7962c 100644 --- a/exporters/otlp/internal/envconfig/envconfig.go +++ b/exporters/otlp/internal/envconfig/envconfig.go @@ -63,9 +63,8 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) { func WithBool(n string, fn func(bool)) func(e *EnvOptionsReader) { return func(e *EnvOptionsReader) { if v, ok := e.GetEnvValue(n); ok { - if b, err := strconv.ParseBool(v); err == nil { - fn(b) - } + b := strings.ToLower(v) == "true" + fn(b) } } } @@ -101,7 +100,8 @@ func WithURL(n string, fn func(*url.URL)) func(e *EnvOptionsReader) { } } -// WithTLSConfig retrieves the specified config and passes it to ConfigFn as a crypto/tls.Config. +// WithCertPool retrieves the specified config and passes it to ConfigFn as a crypto/x509.CertPool +// constructed from reading the certificate at the given path. func WithCertPool(n string, fn func(*x509.CertPool)) func(e *EnvOptionsReader) { return func(e *EnvOptionsReader) { if v, ok := e.GetEnvValue(n); ok { @@ -114,6 +114,8 @@ func WithCertPool(n string, fn func(*x509.CertPool)) func(e *EnvOptionsReader) { } } +// WithCertPool retrieves the specified configs and passes it to ConfigFn as a crypto/tls.Certificate +// constructed from reading the key pair at the given paths. Both files must exist. func WithClientCert(nc, nk string, fn func(tls.Certificate)) func(e *EnvOptionsReader) { return func(e *EnvOptionsReader) { vc, okc := e.GetEnvValue(nc) diff --git a/exporters/otlp/internal/envconfig/envconfig_test.go b/exporters/otlp/internal/envconfig/envconfig_test.go index cdbd4d23e67..cc6b89dcbfe 100644 --- a/exporters/otlp/internal/envconfig/envconfig_test.go +++ b/exporters/otlp/internal/envconfig/envconfig_test.go @@ -188,7 +188,11 @@ func TestEnvConfig(t *testing.T) { options = append(options, testOption{TestBool: b}) }), }, - expectedOptions: []testOption{}, + expectedOptions: []testOption{ + { + TestBool: false, + }, + }, }, { name: "with a duration config", @@ -382,6 +386,24 @@ func TestWithClientCert(t *testing.T) { }), ) assert.Equal(t, cert, option.TestTLS.Certificates[0]) + + reader.ReadFile = func(s string) ([]byte, error) { return []byte{}, nil } + option.TestTLS = nil + reader.Apply( + WithClientCert("CLIENT_CERTIFICATE", "CLIENT_KEY", func(c tls.Certificate) { + option = testOption{TestTLS: &tls.Config{Certificates: []tls.Certificate{c}}} + }), + ) + assert.Equal(t, nil, option.TestTLS.Certificates) + + reader.GetEnv = func(s string) string { return "" } + option.TestTLS = nil + reader.Apply( + WithClientCert("CLIENT_CERTIFICATE", "CLIENT_KEY", func(c tls.Certificate) { + option = testOption{TestTLS: &tls.Config{Certificates: []tls.Certificate{c}}} + }), + ) + assert.Equal(t, nil, option.TestTLS.Certificates) } func TestStringToHeader(t *testing.T) {