Skip to content

Commit

Permalink
tracer TestWithHeaderTags: Clear header tags to work with -count=2 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
evanj authored Oct 12, 2023
1 parent b7546cf commit 3b5b794
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,18 +1206,22 @@ func TestWithLogStartup(t *testing.T) {

func TestWithHeaderTags(t *testing.T) {
t.Run("default-off", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
newConfig()
assert.Equal(0, globalconfig.HeaderTagsLen())
})

t.Run("single-header", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
header := "Header"
newConfig(WithHeaderTags([]string{header}))
assert.Equal("http.request.headers.header", globalconfig.HeaderTag(header))
})

t.Run("header-and-tag", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
header := "Header"
tag := "tag"
Expand All @@ -1226,6 +1230,7 @@ func TestWithHeaderTags(t *testing.T) {
})

t.Run("multi-header", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
newConfig(WithHeaderTags([]string{"1header:1tag", "2header", "3header:3tag"}))
assert.Equal("1tag", globalconfig.HeaderTag("1header"))
Expand All @@ -1234,13 +1239,15 @@ func TestWithHeaderTags(t *testing.T) {
})

t.Run("normalization", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
newConfig(WithHeaderTags([]string{" [email protected]*r ", " 2header:t!a@g. "}))
assert.Equal(ext.HTTPRequestHeaders+".h_e_a-d_e_r", globalconfig.HeaderTag("[email protected]*r"))
assert.Equal("t!a@g.", globalconfig.HeaderTag("2header"))
})

t.Run("envvar-only", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
os.Setenv("DD_TRACE_HEADER_TAGS", " 1header:1tag,2.h.e.a.d.e.r ")
defer os.Unsetenv("DD_TRACE_HEADER_TAGS")

Expand All @@ -1252,13 +1259,17 @@ func TestWithHeaderTags(t *testing.T) {
})

t.Run("env-override", func(t *testing.T) {
defer globalconfig.ClearHeaderTags()
assert := assert.New(t)
os.Setenv("DD_TRACE_HEADER_TAGS", "unexpected")
defer os.Unsetenv("DD_TRACE_HEADER_TAGS")
newConfig(WithHeaderTags([]string{"expected"}))
assert.Equal(ext.HTTPRequestHeaders+".expected", globalconfig.HeaderTag("Expected"))
assert.Equal(1, globalconfig.HeaderTagsLen())
})

// ensures we cleaned up global state correctly
assert.Equal(t, 0, globalconfig.HeaderTagsLen())
}

func TestHostnameDisabled(t *testing.T) {
Expand Down

0 comments on commit 3b5b794

Please sign in to comment.