diff --git a/CHANGELOG.md b/CHANGELOG.md index d9f145f86d7..98bf1eaed7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Fixed + +- Fix default endpoint (use `http` instead of `https`) for OTLP exporters. (#4155) + ## [1.16.0/0.39.0] 2023-05-18 This release contains the first stable release of the OpenTelemetry Go [metric API]. diff --git a/exporters/otlp/otlpmetric/internal/oconf/options.go b/exporters/otlp/otlpmetric/internal/oconf/options.go index e696a0f78ba..5e9479ce907 100644 --- a/exporters/otlp/otlpmetric/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/internal/oconf/options.go @@ -89,16 +89,23 @@ func NewHTTPConfig(opts ...HTTPOption) Config { URLPath: DefaultMetricsPath, Compression: NoCompression, Timeout: DefaultTimeout, + Insecure: true, TemporalitySelector: metric.DefaultTemporalitySelector, AggregationSelector: metric.DefaultAggregationSelector, }, RetryConfig: retry.DefaultConfig, } + cfg = ApplyHTTPEnvConfigs(cfg) for _, opt := range opts { cfg = opt.ApplyHTTPOption(cfg) } + + if cfg.Metrics.TLSCfg != nil { + cfg.Metrics.Insecure = false + } + cfg.Metrics.URLPath = internal.CleanPath(cfg.Metrics.URLPath, DefaultMetricsPath) return cfg } @@ -112,6 +119,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { URLPath: DefaultMetricsPath, Compression: NoCompression, Timeout: DefaultTimeout, + Insecure: true, TemporalitySelector: metric.DefaultTemporalitySelector, AggregationSelector: metric.DefaultAggregationSelector, @@ -119,19 +127,28 @@ func NewGRPCConfig(opts ...GRPCOption) Config { RetryConfig: retry.DefaultConfig, DialOptions: []grpc.DialOption{grpc.WithUserAgent(ominternal.GetUserAgentHeader())}, } + cfg = ApplyGRPCEnvConfigs(cfg) for _, opt := range opts { cfg = opt.ApplyGRPCOption(cfg) } + if cfg.Metrics.TLSCfg != nil { + cfg.Metrics.Insecure = false + } + if cfg.ServiceConfig != "" { cfg.DialOptions = append(cfg.DialOptions, grpc.WithDefaultServiceConfig(cfg.ServiceConfig)) } - // Priroritize GRPCCredentials over Insecure (passing both is an error). + // Prioritize GRPCCredentials over Insecure (passing both is an error). if cfg.Metrics.GRPCCredentials != nil { - cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(cfg.Metrics.GRPCCredentials)) + creds := cfg.Metrics.GRPCCredentials + cfg.Metrics.GRPCCredentials = creds + cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(creds)) } else if cfg.Metrics.Insecure { - cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) + creds := insecure.NewCredentials() + cfg.Metrics.GRPCCredentials = creds + cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(creds)) } else { // Default to using the host's root CA. creds := credentials.NewTLS(nil) diff --git a/exporters/otlp/otlpmetric/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/internal/oconf/options_test.go index d2426af84c3..bfb2b577176 100644 --- a/exporters/otlp/otlpmetric/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/internal/oconf/options_test.go @@ -88,6 +88,7 @@ func TestConfigs(t *testing.T) { assert.Equal(t, oconf.NoCompression, c.Metrics.Compression) assert.Equal(t, map[string]string(nil), c.Metrics.Headers) assert.Equal(t, 10*time.Second, c.Metrics.Timeout) + assert.True(t, c.Metrics.Insecure) }, }, diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go index ec6bdd75916..d6d08b6c0df 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go @@ -137,10 +137,9 @@ func TestConfig(t *testing.T) { assert.Len(t, rCh, 0, "failed HTTP responses did not occur") }) - t.Run("WithURLPath", func(t *testing.T) { - path := "/prefix/v2/metrics" - ePt := fmt.Sprintf("http://localhost:0%s", path) - exp, coll := factoryFunc(ePt, nil, WithURLPath(path)) + t.Run("WithInsecure", func(t *testing.T) { + ePt := "http://localhost:0" + exp, coll := factoryFunc(ePt, nil, WithInsecure()) ctx := context.Background() t.Cleanup(func() { require.NoError(t, coll.Shutdown(ctx)) }) t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) }) diff --git a/exporters/otlp/otlptrace/README.md b/exporters/otlp/otlptrace/README.md index 50295223182..042898fa29d 100644 --- a/exporters/otlp/otlptrace/README.md +++ b/exporters/otlp/otlptrace/README.md @@ -40,12 +40,12 @@ specification](https://github.com/open-telemetry/opentelemetry-specification/blo | Environment variable | Option | Default value | | ------------------------------------------------------------------------ |------------------------------ | -------------------------------------------------------- | -| `OTEL_EXPORTER_OTLP_ENDPOINT` `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | `WithEndpoint` `WithInsecure` | `https://localhost:4317` or `https://localhost:4318`[^1] | +| `OTEL_EXPORTER_OTLP_ENDPOINT` `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | `WithEndpoint` `WithInsecure` | `http://localhost:4317` or `http://localhost:4318`[^1] | | `OTEL_EXPORTER_OTLP_CERTIFICATE` `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` | `WithTLSClientConfig` | | | `OTEL_EXPORTER_OTLP_HEADERS` `OTEL_EXPORTER_OTLP_TRACES_HEADERS` | `WithHeaders` | | | `OTEL_EXPORTER_OTLP_COMPRESSION` `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` | `WithCompression` | | | `OTEL_EXPORTER_OTLP_TIMEOUT` `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` | `WithTimeout` | `10s` | -[^1]: The gRPC client defaults to `https://localhost:4317` and the HTTP client `https://localhost:4318`. +[^1]: The gRPC client defaults to `http://localhost:4317` and the HTTP client `http://localhost:4318`. Configuration using options have precedence over the environment variables. diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/internal/otlpconfig/options.go index 1a6bb423b30..c11a0e35ef9 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/options.go @@ -76,13 +76,20 @@ func NewHTTPConfig(opts ...HTTPOption) Config { URLPath: DefaultTracesPath, Compression: NoCompression, Timeout: DefaultTimeout, + Insecure: true, }, RetryConfig: retry.DefaultConfig, } + cfg = ApplyHTTPEnvConfigs(cfg) for _, opt := range opts { cfg = opt.ApplyHTTPOption(cfg) } + + if cfg.Traces.TLSCfg != nil { + cfg.Traces.Insecure = false + } + cfg.Traces.URLPath = internal.CleanPath(cfg.Traces.URLPath, DefaultTracesPath) return cfg } @@ -96,6 +103,7 @@ func NewGRPCConfig(opts ...GRPCOption) Config { URLPath: DefaultTracesPath, Compression: NoCompression, Timeout: DefaultTimeout, + Insecure: true, }, RetryConfig: retry.DefaultConfig, DialOptions: []grpc.DialOption{grpc.WithUserAgent(otinternal.GetUserAgentHeader())}, @@ -105,14 +113,22 @@ func NewGRPCConfig(opts ...GRPCOption) Config { cfg = opt.ApplyGRPCOption(cfg) } + if cfg.Traces.TLSCfg != nil { + cfg.Traces.Insecure = false + } + if cfg.ServiceConfig != "" { cfg.DialOptions = append(cfg.DialOptions, grpc.WithDefaultServiceConfig(cfg.ServiceConfig)) } - // Priroritize GRPCCredentials over Insecure (passing both is an error). + // Prioritize GRPCCredentials over Insecure (passing both is an error). if cfg.Traces.GRPCCredentials != nil { - cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(cfg.Traces.GRPCCredentials)) + creds := cfg.Traces.GRPCCredentials + cfg.Traces.GRPCCredentials = creds + cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(creds)) } else if cfg.Traces.Insecure { - cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) + creds := insecure.NewCredentials() + cfg.Traces.GRPCCredentials = creds + cfg.DialOptions = append(cfg.DialOptions, grpc.WithTransportCredentials(creds)) } else { // Default to using the host's root CA. creds := credentials.NewTLS(nil) diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go index adbdc932f53..62349be8557 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go @@ -85,6 +85,7 @@ func TestConfigs(t *testing.T) { assert.Equal(t, otlpconfig.NoCompression, c.Traces.Compression) assert.Equal(t, map[string]string(nil), c.Traces.Headers) assert.Equal(t, 10*time.Second, c.Traces.Timeout) + assert.True(t, c.Traces.Insecure) }, }, diff --git a/exporters/otlp/otlptrace/otlptracehttp/client_test.go b/exporters/otlp/otlptrace/otlptracehttp/client_test.go index 859c48dd38c..fde87be22c2 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client_test.go @@ -157,6 +157,12 @@ func TestEndToEnd(t *testing.T) { ExpectedHeaders: customUserAgentHeader, }, }, + { + name: "with insecure", + opts: []otlptracehttp.Option{ + otlptracehttp.WithInsecure(), + }, + }, } for _, tc := range tests {