diff --git a/ddtrace/tracer/option.go b/ddtrace/tracer/option.go index 9175c20efe..0c787261f9 100644 --- a/ddtrace/tracer/option.go +++ b/ddtrace/tracer/option.go @@ -1290,6 +1290,10 @@ func setHeaderTags(headerAsTags []string) bool { globalconfig.ClearHeaderTags() for _, h := range headerAsTags { header, tag := normalizer.HeaderTag(h) + if len(header) == 0 || len(tag) == 0 { + log.Debug("Header-tag input is in unsupported format; dropping input value %v", h) + continue + } globalconfig.SetHeaderTag(header, tag) } return true diff --git a/ddtrace/tracer/option_test.go b/ddtrace/tracer/option_test.go index d4259e9f5c..514046e1ed 100644 --- a/ddtrace/tracer/option_test.go +++ b/ddtrace/tracer/option_test.go @@ -1392,6 +1392,28 @@ func TestWithHeaderTags(t *testing.T) { assert.Equal(ext.HTTPRequestHeaders+".2_h_e_a_d_e_r", globalconfig.HeaderTag("2.h.e.a.d.e.r")) }) + t.Run("envvar-invalid", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() + t.Setenv("DD_TRACE_HEADER_TAGS", "header1:") + + assert := assert.New(t) + newConfig() + + assert.Equal(0, globalconfig.HeaderTagsLen()) + }) + + t.Run("envvar-partially-invalid", func(t *testing.T) { + defer globalconfig.ClearHeaderTags() + t.Setenv("DD_TRACE_HEADER_TAGS", "header1,header2:") + + assert := assert.New(t) + newConfig() + + assert.Equal(1, globalconfig.HeaderTagsLen()) + fmt.Println(globalconfig.HeaderTagMap()) + assert.Equal(ext.HTTPRequestHeaders+".header1", globalconfig.HeaderTag("Header1")) + }) + t.Run("env-override", func(t *testing.T) { defer globalconfig.ClearHeaderTags() assert := assert.New(t)