diff --git a/debug.go b/debug.go index 9b2264c560a4..817061927f5e 100644 --- a/debug.go +++ b/debug.go @@ -11,7 +11,13 @@ import ( const debugGoroutineIDTag = "_initial_goroutine" type errAssertionFailed struct { - msg string + span *spanImpl + msg string +} + +// Error implements the error interface. +func (err *errAssertionFailed) Error() string { + return fmt.Sprintf("%s:\n%+v", err.msg, err.span) } func (s *spanImpl) Lock() { @@ -22,9 +28,7 @@ func (s *spanImpl) Lock() { func (s *spanImpl) maybeAssertSanityLocked() { if s.tracer == nil { s.Mutex.Unlock() - panic(&errAssertionFailed{ - msg: fmt.Sprintf("span used after Finish()"), - }) + panic(&errAssertionFailed{span: s, msg: "span used after call to Finish()"}) } if s.tracer.options.DebugAssertSingleGoroutine { startID := curGoroutineID() @@ -37,7 +41,8 @@ func (s *spanImpl) maybeAssertSanityLocked() { if startID != curID { s.Mutex.Unlock() panic(&errAssertionFailed{ - msg: fmt.Sprintf("span started on goroutine %d, but now running on %d", startID, curID), + span: s, + msg: fmt.Sprintf("span started on goroutine %d, but now running on %d", startID, curID), }) } } diff --git a/span.go b/span.go index d88e74bd6d25..917214c16587 100644 --- a/span.go +++ b/span.go @@ -171,7 +171,9 @@ func (s *spanImpl) FinishWithOptions(opts opentracing.FinishOptions) { if s.tracer.options.DebugAssertUseAfterFinish { // This makes it much more likely to catch a panic on any subsequent // operation since s.tracer is accessed on every call to `Lock`. - s.reset() + // We don't call `reset()` here to preserve the logs in the Span + // which are printed when the assertion triggers. + s.tracer = nil } if poolEnabled {