From a4a81a21c239d389d4daf789aea2b804f7771038 Mon Sep 17 00:00:00 2001 From: Remy Chantenay Date: Wed, 31 May 2023 17:59:21 +0300 Subject: [PATCH 1/4] Fix default endpoints for otlptrace package --- exporters/otlp/otlptrace/README.md | 4 ++-- .../otlptrace/internal/otlpconfig/options.go | 22 ++++++++++++++++--- .../internal/otlpconfig/options_test.go | 1 + .../otlptrace/otlptracehttp/client_test.go | 6 +++++ 4 files changed, 28 insertions(+), 5 deletions(-) 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 { From 8045992b3d2f727ef5a0347f33453acaea4e11bf Mon Sep 17 00:00:00 2001 From: Remy Chantenay Date: Wed, 31 May 2023 18:00:04 +0300 Subject: [PATCH 2/4] Fix default endpoints for otlpmetric package --- CHANGELOG.md | 1 + .../otlp/otlpmetric/internal/oconf/options.go | 23 ++++++++++++++++--- .../otlpmetric/internal/oconf/options_test.go | 1 + .../otlpmetric/otlpmetrichttp/client_test.go | 7 +++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9f145f86d7..b11674e04b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ See our [versioning policy](VERSIONING.md) for more information about these stab ### Fixed - Fix build for BSD based systems in `go.opentelemetry.io/otel/sdk/resource`. (#4077) +- Fix default endpoint (i.e., use `http` instead of `https`) for OTLP exporters. (#4147) ## [1.16.0-rc.1/0.39.0-rc.1] 2023-05-03 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)) }) From 9f10b144bc905eb5a6a1e42097e669efbd00230d Mon Sep 17 00:00:00 2001 From: Remy Chantenay Date: Wed, 31 May 2023 20:30:04 +0300 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b11674e04b9..a898bc11430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +- Fix default endpoint (i.e., use `http` instead of `https`) for OTLP exporters. (#4147) + ## [1.16.0/0.39.0] 2023-05-18 This release contains the first stable release of the OpenTelemetry Go [metric API]. @@ -33,7 +35,6 @@ See our [versioning policy](VERSIONING.md) for more information about these stab ### Fixed - Fix build for BSD based systems in `go.opentelemetry.io/otel/sdk/resource`. (#4077) -- Fix default endpoint (i.e., use `http` instead of `https`) for OTLP exporters. (#4147) ## [1.16.0-rc.1/0.39.0-rc.1] 2023-05-03 From ab5d4ff9fbd53f56231b43145adfcaa7e9daa628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 1 Jun 2023 09:59:13 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: Damien Mathieu <42@dmathieu.com> --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a898bc11430..98bf1eaed7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] -- Fix default endpoint (i.e., use `http` instead of `https`) for OTLP exporters. (#4147) +### Fixed + +- Fix default endpoint (use `http` instead of `https`) for OTLP exporters. (#4155) ## [1.16.0/0.39.0] 2023-05-18