Skip to content

Commit

Permalink
tracer: allow x-datadog headers to pass as header tags (#2744)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 authored Jul 11, 2024
1 parent e8dc974 commit be3543a
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 66 deletions.
6 changes: 1 addition & 5 deletions contrib/emicklei/go-restful.v3/restful_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()

container.ServeHTTP(w, r)
Expand All @@ -52,7 +51,7 @@ func TestWithHeaderTags(t *testing.T) {
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -79,7 +78,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("global", func(t *testing.T) {
Expand All @@ -97,7 +95,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -118,7 +115,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/emicklei/go-restful/restful_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()

container.ServeHTTP(w, r)
Expand All @@ -52,7 +51,7 @@ func TestWithHeaderTags(t *testing.T) {
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -79,7 +78,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("global", func(t *testing.T) {
Expand All @@ -97,7 +95,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -118,7 +115,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/gin-gonic/gin/gintrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,14 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()
router.ServeHTTP(w, r)
return r
}
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -484,7 +483,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})
t.Run("global", func(t *testing.T) {
mt := mocktracer.Start()
Expand All @@ -500,7 +498,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -521,7 +518,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/go-chi/chi.v5/chi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()
router.ServeHTTP(w, r)
return r
Expand All @@ -473,7 +472,7 @@ func TestWithHeaderTags(t *testing.T) {
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -500,7 +499,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("global", func(t *testing.T) {
Expand All @@ -517,7 +515,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -538,7 +535,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/go-chi/chi/chi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()
router.ServeHTTP(w, r)
return r
Expand All @@ -204,7 +203,7 @@ func TestWithHeaderTags(t *testing.T) {
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -231,7 +230,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("global", func(t *testing.T) {
Expand All @@ -248,7 +246,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -269,7 +266,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/gorilla/mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,13 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
mux.ServeHTTP(httptest.NewRecorder(), r)
return r
}
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -175,7 +174,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})
t.Run("global", func(t *testing.T) {
mt := mocktracer.Start()
Expand All @@ -191,7 +189,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})
t.Run("override", func(t *testing.T) {
mt := mocktracer.Start()
Expand All @@ -211,7 +208,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
4 changes: 3 additions & 1 deletion contrib/internal/httptrace/httptrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ func TestHeaderTagsFromRequest(t *testing.T) {
r.Header.Set("header1", "val1")
r.Header.Set("header2", " val2 ")
r.Header.Set("header3", "v a l 3")
r.Header.Set("x-datadog-header", "val4")

expectedHeaderTags := map[string]string{
"tag1": "val1",
"tag2": "val2",
"tag3": "v a l 3",
"tag4": "val4",
}

hs := []string{"header1:tag1", "header2:tag2", "header3:tag3"}
hs := []string{"header1:tag1", "header2:tag2", "header3:tag3", "x-datadog-header:tag4"}
ht := internal.NewLockMap(normalizer.HeaderTagSlice(hs))
s, _ := StartRequestSpan(r, HeaderTagsFromRequest(r, ht))
s.Finish()
Expand Down
6 changes: 1 addition & 5 deletions contrib/julienschmidt/httprouter/httprouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()
mux.ServeHTTP(w, r)
return r
Expand All @@ -233,7 +232,7 @@ func TestWithHeaderTags(t *testing.T) {
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -259,7 +258,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})
t.Run("global", func(t *testing.T) {
mt := mocktracer.Start()
Expand All @@ -275,7 +273,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})
t.Run("override", func(t *testing.T) {
mt := mocktracer.Start()
Expand All @@ -295,7 +292,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
6 changes: 1 addition & 5 deletions contrib/labstack/echo.v4/echotrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,14 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()
router.ServeHTTP(w, r)
return r
}
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -550,7 +549,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("global", func(t *testing.T) {
Expand All @@ -567,7 +565,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -588,7 +585,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
6 changes: 1 addition & 5 deletions contrib/labstack/echo/echotrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ func TestWithHeaderTags(t *testing.T) {
r.Header.Add("[email protected]*r", "val2")
r.Header.Set("2header", "2val")
r.Header.Set("3header", "3val")
r.Header.Set("x-datadog-header", "value")
w := httptest.NewRecorder()
router.ServeHTTP(w, r)
return r
}
t.Run("default-off", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
htArgs := []string{"[email protected]*r", "2header", "3header", "x-datadog-header"}
htArgs := []string{"[email protected]*r", "2header", "3header"}
setupReq()
spans := mt.FinishedSpans()
assert := assert.New(t)
Expand All @@ -96,7 +95,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("global", func(t *testing.T) {
Expand All @@ -113,7 +111,6 @@ func TestWithHeaderTags(t *testing.T) {
s := spans[0]

assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
})

t.Run("override", func(t *testing.T) {
Expand All @@ -134,7 +131,6 @@ func TestWithHeaderTags(t *testing.T) {
header, tag := normalizer.HeaderTag(arg)
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag])
}
assert.NotContains(s.Tags(), "http.headers.x-datadog-header")
assert.NotContains(s.Tags(), globalT)
})
}
Expand Down
Loading

0 comments on commit be3543a

Please sign in to comment.