Skip to content

Commit

Permalink
report url parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jan 3, 2024
1 parent f041abe commit b404160
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 42 deletions.
19 changes: 12 additions & 7 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"google.golang.org/grpc/encoding/gzip"

"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry"
)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"google.golang.org/grpc/encoding/gzip"

"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/retry"
)

Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions internal/shared/otlp/otlpmetric/oconf/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"google.golang.org/grpc/encoding/gzip"

"{{ .retryImportPath }}"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/sdk/metric"
)

Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"google.golang.org/grpc/encoding/gzip"

"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/internal/global"
"{{ .retryImportPath }}"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b404160

Please sign in to comment.