-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2: feat(contrib): migrate all pending contribs (#2829)
- Loading branch information
Showing
63 changed files
with
1,231 additions
and
857 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,8 @@ import ( | |
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext" | ||
"github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer" | ||
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer" | ||
"github.com/DataDog/dd-trace-go/v2/internal/appsec" | ||
"github.com/DataDog/dd-trace-go/v2/internal/contrib/namingschematest" | ||
"github.com/DataDog/dd-trace-go/v2/internal/globalconfig" | ||
"github.com/DataDog/dd-trace-go/v2/internal/normalizer" | ||
"github.com/DataDog/dd-trace-go/v2/instrumentation" | ||
"github.com/DataDog/dd-trace-go/v2/instrumentation/testutils" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -155,64 +153,58 @@ func TestWithHeaderTags(t *testing.T) { | |
assert := assert.New(t) | ||
assert.Equal(len(spans), 1) | ||
s := spans[0] | ||
for _, arg := range htArgs { | ||
_, tag := normalizer.HeaderTag(arg) | ||
instrumentation.NewHeaderTags(htArgs).Iter(func(_ string, tag string) { | ||
assert.NotContains(s.Tags(), tag) | ||
} | ||
}) | ||
}) | ||
t.Run("integration", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
htArgs := []string{"[email protected]*r", "2header:tag"} | ||
r := setupReq(WithHeaderTags(htArgs)) | ||
_ = setupReq(WithHeaderTags(htArgs)) | ||
spans := mt.FinishedSpans() | ||
assert := assert.New(t) | ||
assert.Equal(len(spans), 1) | ||
s := spans[0] | ||
|
||
for _, arg := range htArgs { | ||
header, tag := normalizer.HeaderTag(arg) | ||
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag]) | ||
} | ||
assert.Equal("val,val2", s.Tags()["http.request.headers.h_e_a-d_e_r"]) | ||
assert.Equal("2val", s.Tags()["tag"]) | ||
assert.NotContains(s.Tags(), "http.headers.x-datadog-header") | ||
}) | ||
t.Run("global", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
header, tag := normalizer.HeaderTag("3header") | ||
globalconfig.SetHeaderTag(header, tag) | ||
testutils.SetGlobalHeaderTags(t, "3header") | ||
|
||
r := setupReq() | ||
_ = setupReq() | ||
spans := mt.FinishedSpans() | ||
assert := assert.New(t) | ||
assert.Equal(len(spans), 1) | ||
s := spans[0] | ||
|
||
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag]) | ||
assert.Equal("3val", s.Tags()["http.request.headers.3header"]) | ||
assert.NotContains(s.Tags(), "http.request.headers.other") | ||
assert.NotContains(s.Tags(), "http.headers.x-datadog-header") | ||
}) | ||
t.Run("override", func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
globalH, globalT := normalizer.HeaderTag("3header") | ||
globalconfig.SetHeaderTag(globalH, globalT) | ||
testutils.SetGlobalHeaderTags(t, "3header") | ||
|
||
htArgs := []string{"[email protected]*r", "2header:tag"} | ||
r := setupReq(WithHeaderTags(htArgs)) | ||
_ = setupReq(WithHeaderTags(htArgs)) | ||
spans := mt.FinishedSpans() | ||
assert := assert.New(t) | ||
assert.Equal(len(spans), 1) | ||
s := spans[0] | ||
|
||
for _, arg := range htArgs { | ||
header, tag := normalizer.HeaderTag(arg) | ||
assert.Equal(strings.Join(r.Header.Values(header), ","), s.Tags()[tag]) | ||
} | ||
assert.Equal("val,val2", s.Tags()["http.request.headers.h_e_a-d_e_r"]) | ||
assert.Equal("2val", s.Tags()["tag"]) | ||
assert.NotContains(s.Tags(), "http.headers.x-datadog-header") | ||
assert.NotContains(s.Tags(), globalT) | ||
assert.NotContains(s.Tags(), "http.request.headers.3header") | ||
}) | ||
} | ||
|
||
|
@@ -296,9 +288,7 @@ func TestAnalyticsSettings(t *testing.T) { | |
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
rate := globalconfig.AnalyticsRate() | ||
defer globalconfig.SetAnalyticsRate(rate) | ||
globalconfig.SetAnalyticsRate(0.4) | ||
testutils.SetGlobalAnalyticsRate(t, 0.4) | ||
|
||
assertRate(t, mt, 0.4) | ||
}) | ||
|
@@ -321,9 +311,7 @@ func TestAnalyticsSettings(t *testing.T) { | |
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
rate := globalconfig.AnalyticsRate() | ||
defer globalconfig.SetAnalyticsRate(rate) | ||
globalconfig.SetAnalyticsRate(0.4) | ||
testutils.SetGlobalAnalyticsRate(t, 0.4) | ||
|
||
assertRate(t, mt, 0.23, WithAnalyticsRate(0.23)) | ||
}) | ||
|
@@ -407,10 +395,9 @@ func okHandler() http.Handler { | |
} | ||
|
||
func TestAppSec(t *testing.T) { | ||
appsec.Start() | ||
defer appsec.Stop() | ||
testutils.StartAppSec(t) | ||
|
||
if !appsec.Enabled() { | ||
if !instr.AppSecEnabled() { | ||
t.Skip("appsec disabled") | ||
} | ||
|
||
|
@@ -535,23 +522,3 @@ func TestAppSec(t *testing.T) { | |
require.True(t, strings.Contains(event.(string), "crs-933-130")) | ||
}) | ||
} | ||
|
||
func TestNamingSchema(t *testing.T) { | ||
genSpans := namingschematest.GenSpansFn(func(t *testing.T, serviceOverride string) []*mocktracer.Span { | ||
var opts []RouterOption | ||
if serviceOverride != "" { | ||
opts = append(opts, WithService(serviceOverride)) | ||
} | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
mux := NewRouter(opts...) | ||
mux.Handle("/200", okHandler()) | ||
req := httptest.NewRequest("GET", "/200", nil) | ||
w := httptest.NewRecorder() | ||
mux.ServeHTTP(w, req) | ||
|
||
return mt.FinishedSpans() | ||
}) | ||
namingschematest.NewHTTPServerTest(genSpans, "mux.router")(t) | ||
} |
Oops, something went wrong.