diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a213fe6cf1..330e197e129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 💡 Enhancements 💡 - Add `linux-ppc64le` architecture to cross build tests in CI +- `client`: perform case insensitive lookups in case the requested metadata value isn't found (#5646) ### 🧰 Bug fixes 🧰 diff --git a/client/client.go b/client/client.go index b5974e53a06..4b3f701badb 100644 --- a/client/client.go +++ b/client/client.go @@ -91,6 +91,7 @@ package client // import "go.opentelemetry.io/collector/client" import ( "context" "net" + "strings" ) type ctxKey struct{} @@ -160,7 +161,19 @@ func NewMetadata(md map[string][]string) Metadata { func (m Metadata) Get(key string) []string { vals := m.data[key] if len(vals) == 0 { - return nil + // we didn't find the key, but perhaps it just has different cases? + for k, v := range m.data { + if strings.EqualFold(key, k) { + vals = v + // we optimize for the next lookup + m.data[key] = v + } + } + + // if it's still not found, it's really not here + if len(vals) == 0 { + return nil + } } ret := make([]string, len(vals)) diff --git a/client/client_test.go b/client/client_test.go index 3249e84e905..a43fecc7e0b 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -91,6 +91,7 @@ func TestMetadata(t *testing.T) { source := map[string][]string{"test-key": {"test-val"}} md := NewMetadata(source) assert.Equal(t, []string{"test-val"}, md.Get("test-key")) + assert.Equal(t, []string{"test-val"}, md.Get("test-KEY")) // case insensitive lookup // test if copy. In regular use, source cannot change val := md.Get("test-key")