From 79e9f936447334701ed38cd89d4a22af7fb7bcb7 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Mon, 9 Dec 2024 13:27:20 +0100 Subject: [PATCH] Remove use of testing.Testing() --- ddtrace/tracer/telemetry.go | 6 ------ internal/telemetry/telemetrytest/telemetrytest.go | 11 +++++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ddtrace/tracer/telemetry.go b/ddtrace/tracer/telemetry.go index d871adf971..9fa60de2dc 100644 --- a/ddtrace/tracer/telemetry.go +++ b/ddtrace/tracer/telemetry.go @@ -7,9 +7,7 @@ package tracer import ( "fmt" - "slices" "strings" - "testing" "gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry" ) @@ -79,10 +77,6 @@ func startTelemetry(c *config) { telemetryConfigs = append(telemetryConfigs, telemetry.Configuration{Name: "orchestrion_" + k, Value: v}) orchestrionEnabledTags = append(orchestrionEnabledTags, k+":"+v) } - if testing.Testing() { - // In tests, ensure tags are consistently ordered... Ordering is irrelevant outside of tests. - slices.Sort(orchestrionEnabledTags) - } } // Apply the GlobalClient options... diff --git a/internal/telemetry/telemetrytest/telemetrytest.go b/internal/telemetry/telemetrytest/telemetrytest.go index f6977645bb..8861c966d6 100644 --- a/internal/telemetry/telemetrytest/telemetrytest.go +++ b/internal/telemetry/telemetrytest/telemetrytest.go @@ -7,6 +7,7 @@ package telemetrytest import ( + "slices" "sync" "gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry" @@ -69,10 +70,12 @@ func (c *MockClient) productChange(namespace telemetry.Namespace, enabled bool) } // Record stores the value for the given metric. It is currently mocked for `Gauge` and `Distribution` metric types. -func (c *MockClient) Record(ns telemetry.Namespace, _ telemetry.MetricKind, name string, val float64, tags []string, common bool) { - c.On("Gauge", ns, name, val, tags, common).Return() - c.On("Record", ns, name, val, tags, common).Return() - _ = c.Called(ns, name, val, tags, common) +func (c *MockClient) Record(ns telemetry.Namespace, kind telemetry.MetricKind, name string, val float64, tags []string, common bool) { + // Ensure consistent ordering through expectations + slices.Sort(tags) + + c.On("Record", ns, kind, name, val, tags, common).Return() + _ = c.Called(ns, kind, name, val, tags, common) // record the val for tests that assert based on the value if _, ok := c.Metrics[ns]; !ok { if c.Metrics == nil {