Skip to content

Commit

Permalink
[fix][tracer] DD_TRACE_HEADER_TAGS treats trailing colon as invalid i…
Browse files Browse the repository at this point in the history
…nput (#2913)
  • Loading branch information
mtoffl01 authored and darccio committed Oct 23, 2024
1 parent 4f1c6f8 commit 3d0a818
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 3d0a818

Please sign in to comment.