Skip to content

Commit

Permalink
fix: test failure b/c of global log level leak
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Aug 28, 2024
1 parent 0f5b5f6 commit fdd5e08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,7 @@ 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{
Expand Down Expand Up @@ -2160,6 +2161,7 @@ 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
}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func SetLevel(lvl Level) {
level = lvl
}

// GetLevel returns the currrent log level.
func GetLevel() Level {
mu.Lock()
defer mu.Unlock()
return level
}

// DebugEnabled returns true if debug log messages are enabled. This can be used in extremely
// hot code paths to avoid allocating the ...interface{} argument.
func DebugEnabled() bool {
Expand Down

0 comments on commit fdd5e08

Please sign in to comment.