diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go index ef95706f40f..e2d99dc22c1 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go @@ -32,6 +32,7 @@ import ( "google.golang.org/grpc/encoding/gzip" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry" + "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/metric" ) @@ -280,14 +281,18 @@ func WithEndpoint(endpoint string) GenericOption { }) } -func WithEndpointURL(r string) GenericOption { +func WithEndpointURL(v string) GenericOption { return newGenericOption(func(cfg Config) Config { - if u, err := url.Parse(r); err == nil { - cfg.Metrics.Endpoint = u.Host - cfg.Metrics.URLPath = u.Path - if u.Scheme != "https" { - cfg.Metrics.Insecure = true - } + u, err := url.Parse(v) + if err != nil { + global.Error(err, "otlpmetric: parse endpoint url", "url", v) + return cfg + } + + cfg.Metrics.Endpoint = u.Host + cfg.Metrics.URLPath = u.Path + if u.Scheme != "https" { + cfg.Metrics.Insecure = true } return cfg diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go index 563f4a9e205..253539d7a3c 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go @@ -32,6 +32,7 @@ import ( "google.golang.org/grpc/encoding/gzip" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry" + "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/metric" ) @@ -280,14 +281,18 @@ func WithEndpoint(endpoint string) GenericOption { }) } -func WithEndpointURL(r string) GenericOption { +func WithEndpointURL(v string) GenericOption { return newGenericOption(func(cfg Config) Config { - if u, err := url.Parse(r); err == nil { - cfg.Metrics.Endpoint = u.Host - cfg.Metrics.URLPath = u.Path - if u.Scheme != "https" { - cfg.Metrics.Insecure = true - } + u, err := url.Parse(v) + if err != nil { + global.Error(err, "otlpmetric: parse endpoint url", "url", v) + return cfg + } + + cfg.Metrics.Endpoint = u.Host + cfg.Metrics.URLPath = u.Path + if u.Scheme != "https" { + cfg.Metrics.Insecure = true } return cfg diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go index 5e42fd5bd34..f0203cbe723 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go @@ -33,6 +33,7 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry" + "go.opentelemetry.io/otel/internal/global" ) const ( @@ -266,14 +267,18 @@ func WithEndpoint(endpoint string) GenericOption { }) } -func WithEndpointURL(r string) GenericOption { +func WithEndpointURL(v string) GenericOption { return newGenericOption(func(cfg Config) Config { - if u, err := url.Parse(r); err == nil { - cfg.Traces.Endpoint = u.Host - cfg.Traces.URLPath = u.Path - if u.Scheme != "https" { - cfg.Traces.Insecure = true - } + u, err := url.Parse(v) + if err != nil { + global.Error(err, "otlptrace: parse endpoint url", "url", v) + return cfg + } + + cfg.Traces.Endpoint = u.Host + cfg.Traces.URLPath = u.Path + if u.Scheme != "https" { + cfg.Traces.Insecure = true } return cfg diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go index d9b9ce2f067..3b81641a764 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go @@ -33,6 +33,7 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry" + "go.opentelemetry.io/otel/internal/global" ) const ( @@ -266,14 +267,18 @@ func WithEndpoint(endpoint string) GenericOption { }) } -func WithEndpointURL(r string) GenericOption { +func WithEndpointURL(v string) GenericOption { return newGenericOption(func(cfg Config) Config { - if u, err := url.Parse(r); err == nil { - cfg.Traces.Endpoint = u.Host - cfg.Traces.URLPath = u.Path - if u.Scheme != "https" { - cfg.Traces.Insecure = true - } + u, err := url.Parse(v) + if err != nil { + global.Error(err, "otlptrace: parse endpoint url", "url", v) + return cfg + } + + cfg.Traces.Endpoint = u.Host + cfg.Traces.URLPath = u.Path + if u.Scheme != "https" { + cfg.Traces.Insecure = true } return cfg diff --git a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl index 8cdf4aad2d7..8fb706f76c9 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options.go.tmpl @@ -32,6 +32,7 @@ import ( "google.golang.org/grpc/encoding/gzip" "{{ .retryImportPath }}" + "go.opentelemetry.io/otel/internal/global" "go.opentelemetry.io/otel/sdk/metric" ) @@ -280,14 +281,18 @@ func WithEndpoint(endpoint string) GenericOption { }) } -func WithEndpointURL(r string) GenericOption { +func WithEndpointURL(v string) GenericOption { return newGenericOption(func(cfg Config) Config { - if u, err := url.Parse(r); err == nil { - cfg.Metrics.Endpoint = u.Host - cfg.Metrics.URLPath = u.Path - if u.Scheme != "https" { - cfg.Metrics.Insecure = true - } + u, err := url.Parse(v) + if err != nil { + global.Error(err, "otlpmetric: parse endpoint url", "url", v) + return cfg + } + + cfg.Metrics.Endpoint = u.Host + cfg.Metrics.URLPath = u.Path + if u.Scheme != "https" { + cfg.Metrics.Insecure = true } return cfg diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl index 29fa28c0d84..1d5613c44fd 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl @@ -33,6 +33,7 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "{{ .retryImportPath }}" + "go.opentelemetry.io/otel/internal/global" ) const ( @@ -266,14 +267,18 @@ func WithEndpoint(endpoint string) GenericOption { }) } -func WithEndpointURL(r string) GenericOption { +func WithEndpointURL(v string) GenericOption { return newGenericOption(func(cfg Config) Config { - if u, err := url.Parse(r); err == nil { - cfg.Traces.Endpoint = u.Host - cfg.Traces.URLPath = u.Path - if u.Scheme != "https" { - cfg.Traces.Insecure = true - } + u, err := url.Parse(v) + if err != nil { + global.Error(err, "otlptrace: parse endpoint url", "url", v) + return cfg + } + + cfg.Traces.Endpoint = u.Host + cfg.Traces.URLPath = u.Path + if u.Scheme != "https" { + cfg.Traces.Insecure = true } return cfg