diff --git a/CHANGELOG.md b/CHANGELOG.md index 8571901b892..e21619fc364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added -- Add concurrent-safe `Reset` method to `SpanRecorder` in `go.opentelemetry.io/otel/sdk/trace/tracetest`. (#5994) +- Add `Reset` method to `SpanRecorder` in `go.opentelemetry.io/otel/sdk/trace/tracetest`. (#5994) ### Changed diff --git a/sdk/trace/tracetest/recorder.go b/sdk/trace/tracetest/recorder.go index 5b76df2e3ba..732669a17ad 100644 --- a/sdk/trace/tracetest/recorder.go +++ b/sdk/trace/tracetest/recorder.go @@ -74,12 +74,12 @@ func (sr *SpanRecorder) Started() []sdktrace.ReadWriteSpan { // This method is safe to be called concurrently. func (sr *SpanRecorder) Reset() { sr.startedMu.Lock() - sr.started = nil - sr.startedMu.Unlock() - sr.endedMu.Lock() + defer sr.startedMu.Unlock() + defer sr.endedMu.Unlock() + + sr.started = nil sr.ended = nil - sr.endedMu.Unlock() } // Ended returns a copy of all ended spans that have been recorded.