Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Oct 4, 2024
1 parent 966abf2 commit b903f6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ func newConfig(opts ...StartOption) *config {
}
c.headerAsTags = newDynamicConfig("trace_header_tags", nil, setHeaderTags, equalSlice[string])
if v := os.Getenv("DD_TRACE_HEADER_TAGS"); v != "" {
c.headerAsTags.update(strings.Split(v, ","), telemetry.OriginEnvVar)
htSlice := strings.Split(v, ",")
c.headerAsTags.update(htSlice, telemetry.OriginEnvVar)
// Required to ensure that the startup header tags are set on reset.
c.headerAsTags.startup = c.headerAsTags.current
// setHeaderTags(htSlice)
}
if v := getDDorOtelConfig("resourceAttributes"); v != "" {
tags := internal.ParseTagString(v)
Expand Down Expand Up @@ -1290,6 +1292,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
10 changes: 10 additions & 0 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,16 @@ 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("env-override", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
Expand Down
2 changes: 2 additions & 0 deletions internal/normalizer/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package normalizer

import (
"fmt"
"net/textproto"
"regexp"
"strings"
Expand All @@ -25,6 +26,7 @@ var headerTagRegexp = regexp.MustCompile("[^a-zA-Z0-9 -]")
// The returned header is in canonical MIMEHeader format.
func HeaderTag(headerAsTag string) (header string, tag string) {
header = strings.ToLower(strings.TrimSpace(headerAsTag))
fmt.Printf("In HeaderTag: header is '%v'\n", header)
// if a colon is found in `headerAsTag`
if last := strings.LastIndex(header, ":"); last >= 0 {
header, tag = header[:last], header[last+1:]
Expand Down

0 comments on commit b903f6e

Please sign in to comment.