diff --git a/CHANGELOG.md b/CHANGELOG.md index 802f25448f3..3a0f76604fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Use `context.Background()` as default context instead of nil in `go.opentelemetry.io/contrib/bridges/otellogr`. (#6527) - Convert Prometheus histogram buckets to non-cumulative otel histogram buckets in `go.opentelemetry.io/contrib/bridges/prometheus`. (#6685) - Don't start spans that never end for filtered out gRPC stats handler in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#6695) +- Fix a possible nil dereference panic in `NewSDK` of `go.opentelemetry.io/contrib/config/v0.3.0`. (#6752) diff --git a/config/v0.3.0/config.go b/config/v0.3.0/config.go index b4097ac2552..1dd458d5a4a 100644 --- a/config/v0.3.0/config.go +++ b/config/v0.3.0/config.go @@ -155,7 +155,9 @@ func ParseYAML(file []byte) (*OpenTelemetryConfiguration, error) { func toStringMap(pairs []NameStringValuePair) map[string]string { output := make(map[string]string) for _, v := range pairs { - output[v.Name] = *v.Value + if v.Value != nil && len(v.Name) > 0 { + output[v.Name] = *v.Value + } } return output } diff --git a/config/v0.3.0/config_test.go b/config/v0.3.0/config_test.go index 868d928e3df..0e9dfa60b8d 100644 --- a/config/v0.3.0/config_test.go +++ b/config/v0.3.0/config_test.go @@ -568,6 +568,12 @@ func TestCreateTLSConfig(t *testing.T) { } } +func TestToStringMap(t *testing.T) { + require.Equal(t, map[string]string{}, toStringMap([]NameStringValuePair{})) + require.Equal(t, map[string]string{}, toStringMap([]NameStringValuePair{{Name: "test"}})) + require.Equal(t, map[string]string{}, toStringMap([]NameStringValuePair{{Value: ptr("test")}})) +} + func ptr[T any](v T) *T { return &v }