Skip to content

Commit

Permalink
should be the last test failing
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Feb 7, 2025
1 parent 9b4506b commit d5012b4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 27 deletions.
10 changes: 5 additions & 5 deletions contrib/internal/telemetrytest/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry/telemetrytest"
Expand All @@ -23,14 +25,12 @@ import (
// sends the correct data to the telemetry client.
func TestIntegrationInfo(t *testing.T) {
// mux.NewRouter() uses the net/http and gorilla/mux integration
client := new(telemetrytest.MockClient)
client.On("AppStart").Return()
client.On("MarkIntegrationAsLoaded", telemetry.Integration{Name: "net/http", Version: "", Error: ""}).Return()
client.On("MarkIntegrationAsLoaded", telemetry.Integration{Name: "gorilla/mux", Version: "", Error: ""}).Return()
client := new(telemetrytest.RecordClient)
telemetry.StartApp(client)
_ = mux.NewRouter()

client.AssertExpectations(t)
assert.Contains(t, client.Integrations, telemetry.Integration{Name: "net/http", Version: "", Error: ""})
assert.Contains(t, client.Integrations, telemetry.Integration{Name: "gorilla/mux", Version: "", Error: ""})
}

type contribPkg struct {
Expand Down
4 changes: 1 addition & 3 deletions ddtrace/opentelemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func TestTelemetry(t *testing.T) {
t.Setenv(k, v)
}
telemetryClient := new(telemetrytest.RecordClient)
original := telemetry.GlobalClient()
telemetry.SwapClient(telemetryClient)
defer telemetry.SwapClient(original)
defer telemetry.MockClient(telemetryClient)()

p := NewTracerProvider()
p.Tracer("")
Expand Down
4 changes: 1 addition & 3 deletions ddtrace/opentelemetry/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ func TestShutdownOnce(t *testing.T) {

func TestSpanTelemetry(t *testing.T) {
telemetryClient := new(telemetrytest.RecordClient)
original := telemetry.GlobalClient()
telemetry.SwapClient(telemetryClient)
defer telemetry.SwapClient(original)
defer telemetry.MockClient(telemetryClient)()
tp := NewTracerProvider()
otel.SetTracerProvider(tp)
tr := otel.Tracer("")
Expand Down
4 changes: 1 addition & 3 deletions ddtrace/opentracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ func TestExtractError(t *testing.T) {

func TestSpanTelemetry(t *testing.T) {
telemetryClient := new(telemetrytest.RecordClient)
original := telemetry.GlobalClient()
telemetry.SwapClient(telemetryClient)
defer telemetry.SwapClient(original)
defer telemetry.MockClient(telemetryClient)()
opentracing.SetGlobalTracer(New())
_ = opentracing.StartSpan("opentracing.span")
assert.NotZero(t, telemetryClient.Count(telemetry.NamespaceTracers, "spans_created", telemetryTags).Get())
Expand Down
4 changes: 1 addition & 3 deletions ddtrace/tracer/otel_dd_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ func TestAssessSource(t *testing.T) {
})
t.Run("both", func(t *testing.T) {
telemetryClient := new(telemetrytest.RecordClient)
original := telemetry.GlobalClient()
telemetry.SwapClient(telemetryClient)
defer telemetry.SwapClient(original)
defer telemetry.MockClient(telemetryClient)()
// DD_SERVICE prevails
t.Setenv("DD_SERVICE", "abc")
t.Setenv("OTEL_SERVICE_NAME", "123")
Expand Down
12 changes: 2 additions & 10 deletions profiler/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ import (
"github.com/stretchr/testify/assert"
)

func mockGlobalClient(client telemetry.Client) func() {
orig := telemetry.GlobalClient()
telemetry.SwapClient(client)
return func() {
telemetry.SwapClient(orig)
}
}

// Test that the profiler sends the correct telemetry information
func TestTelemetryEnabled(t *testing.T) {
t.Run("tracer start, profiler start", func(t *testing.T) {
telemetryClient := new(telemetrytest.RecordClient)
defer mockGlobalClient(telemetryClient)()
defer telemetry.MockClient(telemetryClient)()

tracer.Start()
defer tracer.Stop()
Expand All @@ -44,7 +36,7 @@ func TestTelemetryEnabled(t *testing.T) {
})
t.Run("only profiler start", func(t *testing.T) {
telemetryClient := new(telemetrytest.RecordClient)
defer mockGlobalClient(telemetryClient)()
defer telemetry.MockClient(telemetryClient)()
Start(
WithProfileTypes(
HeapProfile,
Expand Down

0 comments on commit d5012b4

Please sign in to comment.