Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][tracer] DD_TRACE_HEADER_TAGS treats trailing colon as invalid input #2913

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,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
Expand Down
22 changes: 22 additions & 0 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading