tracing: handle empty protocol (#5474)

This commit is contained in:
Joe Kralicky 2025-02-06 13:19:50 -05:00 committed by GitHub
parent 81a52db749
commit c8323ba744
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 6 deletions

View file

@ -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)
}

View file

@ -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{