diff --git a/internal/telemetry/trace/client.go b/internal/telemetry/trace/client.go index ce82f846d..816f473bc 100644 --- a/internal/telemetry/trace/client.go +++ b/internal/telemetry/trace/client.go @@ -161,7 +161,9 @@ func NewTraceClientFromConfig(opts otelconfig.Config) (otlptrace.Client, error) protocol = *opts.OtelExporterOtlpTracesProtocol } else if opts.OtelExporterOtlpProtocol != nil { protocol = *opts.OtelExporterOtlpProtocol - } else { + } + + if protocol == "" { protocol = BestEffortProtocolFromOTLPEndpoint(endpoint, signalSpecificEndpoint) } diff --git a/internal/telemetry/trace/client_test.go b/internal/telemetry/trace/client_test.go index ab6354f1b..ec4771048 100644 --- a/internal/telemetry/trace/client_test.go +++ b/internal/telemetry/trace/client_test.go @@ -295,7 +295,7 @@ func (h *errHandler) Handle(err error) { h.err = err } -func TestNewRemoteClientFromEnv(t *testing.T) { +func TestNewTraceClientFromConfig(t *testing.T) { env := testenv.New(t, testenv.WithTraceDebugFlags(testenv.StandardTraceDebugFlags)) receiver := scenarios.NewOTLPTraceReceiver() @@ -319,14 +319,22 @@ func TestNewRemoteClientFromEnv(t *testing.T) { expectHeaders map[string][]string }{ { - name: "GRPC endpoint, auto protocol", + name: "GRPC endpoint, unset protocol", env: map[string]string{ "OTEL_TRACES_EXPORTER": "otlp", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": grpcEndpoint.Value(), }, }, { - name: "GRPC endpoint, alternate env, auto protocol", + name: "GRPC endpoint, empty protocol", + env: map[string]string{ + "OTEL_TRACES_EXPORTER": "otlp", + "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": grpcEndpoint.Value(), + "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "", + }, + }, + { + name: "GRPC endpoint, alternate env, unset protocol", env: map[string]string{ "OTEL_TRACES_EXPORTER": "otlp", "OTEL_EXPORTER_OTLP_ENDPOINT": grpcEndpoint.Value(), @@ -334,19 +342,44 @@ func TestNewRemoteClientFromEnv(t *testing.T) { uploadErr: true, }, { - name: "HTTP endpoint, auto protocol", + name: "GRPC endpoint, alternate env, empty protocol", + env: map[string]string{ + "OTEL_TRACES_EXPORTER": "otlp", + "OTEL_EXPORTER_OTLP_ENDPOINT": grpcEndpoint.Value(), + "OTEL_EXPORTER_OTLP_PROTOCOL": "", + }, + uploadErr: true, + }, + { + name: "HTTP endpoint, unset protocol", env: map[string]string{ "OTEL_TRACES_EXPORTER": "otlp", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": httpEndpoint.Value(), }, }, { - name: "HTTP endpoint, alternate env, auto protocol", + name: "HTTP endpoint, empty protocol", + env: map[string]string{ + "OTEL_TRACES_EXPORTER": "otlp", + "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": httpEndpoint.Value(), + "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL": "", + }, + }, + { + name: "HTTP endpoint, alternate env, unset protocol", env: map[string]string{ "OTEL_TRACES_EXPORTER": "otlp", "OTEL_EXPORTER_OTLP_ENDPOINT": strings.TrimSuffix(httpEndpoint.Value(), "/v1/traces"), // path is added automatically by the sdk here }, }, + { + name: "HTTP endpoint, alternate env, empty protocol", + env: map[string]string{ + "OTEL_TRACES_EXPORTER": "otlp", + "OTEL_EXPORTER_OTLP_ENDPOINT": strings.TrimSuffix(httpEndpoint.Value(), "/v1/traces"), + "OTEL_EXPORTER_OTLP_PROTOCOL": "", + }, + }, { name: "GRPC endpoint, explicit protocol", env: map[string]string{