diff --git a/ddtrace/tracer/slog_test.go b/ddtrace/tracer/slog_test.go index 9030a8bda5..352cac0183 100644 --- a/ddtrace/tracer/slog_test.go +++ b/ddtrace/tracer/slog_test.go @@ -19,6 +19,13 @@ func Test_slogHandler(t *testing.T) { rl := &log.RecordLogger{} defer log.UseLogger(rl)() + // Ensure the logger is set to the default level. This may not be the case + // when previous tests pollute the global state. We leave the logger in the + // state we found it to not contribute to this pollution ourselves. + oldLevel := log.GetLevel() + log.SetLevel(log.LevelWarn) + defer log.SetLevel(oldLevel) + // Log a few messages at different levels. The debug message gets discarded // because the internal logger does not have debug enabled by default. l := slog.New(slogHandler{}) diff --git a/ddtrace/tracer/tracer_test.go b/ddtrace/tracer/tracer_test.go index dc88eb1323..2c57d08b4d 100644 --- a/ddtrace/tracer/tracer_test.go +++ b/ddtrace/tracer/tracer_test.go @@ -2147,7 +2147,6 @@ func BenchmarkGenSpanID(b *testing.B) { // startTestTracer returns a Tracer with a DummyTransport func startTestTracer(t testing.TB, opts ...StartOption) (trc *tracer, transport *dummyTransport, flush func(n int), stop func()) { - oldLevel := log.GetLevel() transport = newDummyTransport() tick := make(chan time.Time) o := append([]StartOption{ @@ -2182,7 +2181,6 @@ func startTestTracer(t testing.TB, opts ...StartOption) (trc *tracer, transport tracer.Stop() // clear any service name that was set: we want the state to be the same as startup globalconfig.SetServiceName("") - log.SetLevel(oldLevel) // avoids test failures because of global state } }