diff --git a/lib/observability/tracing/tracing.go b/lib/observability/tracing/tracing.go index 25e45cc4f1cb9..e84341fd82978 100644 --- a/lib/observability/tracing/tracing.go +++ b/lib/observability/tracing/tracing.go @@ -20,6 +20,7 @@ import ( "errors" "net" "net/url" + "strings" "time" "github.com/gravitational/teleport" @@ -124,6 +125,14 @@ func (c *Config) CheckAndSetDefaults() error { return nil } +func (c *Config) Endpoint() string { + if !strings.HasPrefix(c.ExporterURL, c.exporterURL.Scheme) { + return c.ExporterURL + } + + return c.ExporterURL[len(c.exporterURL.Scheme)+3:] +} + var _ otlptrace.Client = (*noopClient)(nil) type noopClient struct{} @@ -195,10 +204,10 @@ func NewClient(cfg Config) (otlptrace.Client, error) { var traceClient otlptrace.Client switch cfg.exporterURL.Scheme { case "http", "https": - httpOptions = append(httpOptions, otlptracehttp.WithEndpoint(cfg.ExporterURL[len(cfg.exporterURL.Scheme)+3:])) + httpOptions = append(httpOptions, otlptracehttp.WithEndpoint(cfg.Endpoint())) traceClient = otlptracehttp.NewClient(httpOptions...) case "grpc": - grpcOptions = append(grpcOptions, otlptracegrpc.WithEndpoint(cfg.ExporterURL[len(cfg.exporterURL.Scheme)+3:])) + grpcOptions = append(grpcOptions, otlptracegrpc.WithEndpoint(cfg.Endpoint())) traceClient = otlptracegrpc.NewClient(grpcOptions...) default: return nil, trace.BadParameter("unsupported exporter scheme: %q", cfg.exporterURL.Scheme) @@ -308,11 +317,9 @@ func NewTraceProvider(ctx context.Context, cfg Config) (*Provider, error) { res, err := resource.New(ctx, resource.WithFromEnv(), - resource.WithProcess(), resource.WithProcessPID(), resource.WithProcessExecutableName(), resource.WithProcessExecutablePath(), - resource.WithProcessOwner(), resource.WithProcessRuntimeName(), resource.WithProcessRuntimeVersion(), resource.WithProcessRuntimeDescription(), diff --git a/lib/observability/tracing/tracing_test.go b/lib/observability/tracing/tracing_test.go index 03f2392bd0786..a5c3cd785c944 100644 --- a/lib/observability/tracing/tracing_test.go +++ b/lib/observability/tracing/tracing_test.go @@ -493,3 +493,55 @@ func TestConfig_CheckAndSetDefaults(t *testing.T) { }) } } + +func TestConfig_Endpoint(t *testing.T) { + cases := []struct { + name string + cfg Config + expected string + }{ + { + name: "with http scheme", + cfg: Config{ + Service: "test", + ExporterURL: "http://localhost:8080", + }, + expected: "localhost:8080", + }, + { + name: "with https scheme", + cfg: Config{ + Service: "test", + ExporterURL: "https://localhost:8080/custom", + }, + expected: "localhost:8080/custom", + }, + { + name: "with grpc scheme", + cfg: Config{ + Service: "test", + ExporterURL: "grpc://collector.opentelemetry.svc:4317", + SamplingRate: 1.0, + DialTimeout: time.Millisecond, + }, + expected: "collector.opentelemetry.svc:4317", + }, + { + name: "without a scheme", + cfg: Config{ + Service: "test", + ExporterURL: "collector.opentelemetry.svc:4317", + SamplingRate: 1.0, + DialTimeout: time.Millisecond, + }, + expected: "collector.opentelemetry.svc:4317", + }, + } + + for _, tt := range cases { + t.Run(tt.name, func(t *testing.T) { + require.NoError(t, tt.cfg.CheckAndSetDefaults()) + require.Equal(t, tt.expected, tt.cfg.Endpoint()) + }) + } +}