1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-25 22:41:46 +02:00

sdk/trace: Fix goroutine leak in simpleSpanProcessor.Shutdown (#6368)

Side-effect when working towards
https://github.com/open-telemetry/opentelemetry-go/issues/6360

- Fix goroutine leaks from tests in places where batch processor was not
shut down
- Fix goroutine leak in simpleSpanProcessor.Shutdown
This commit is contained in:
Robert Pająk
2025-02-26 23:32:15 +01:00
committed by GitHub
parent 7f724dbc44
commit 44d50457d9
13 changed files with 57 additions and 4 deletions

View File

@@ -12,8 +12,6 @@ import (
"testing"
"time"
ottest "go.opentelemetry.io/otel/sdk/internal/internaltest"
"github.com/go-logr/logr"
"github.com/go-logr/logr/funcr"
"github.com/stretchr/testify/assert"
@@ -21,6 +19,7 @@ import (
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/sdk/internal/env"
ottest "go.opentelemetry.io/otel/sdk/internal/internaltest"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"
@@ -544,6 +543,9 @@ func TestBatchSpanProcessorForceFlushCancellation(t *testing.T) {
cancel()
bsp := sdktrace.NewBatchSpanProcessor(indefiniteExporter{})
t.Cleanup(func() {
assert.NoError(t, bsp.Shutdown(context.Background()))
})
if got, want := bsp.ForceFlush(ctx), context.Canceled; !errors.Is(got, want) {
t.Errorf("expected %q error, got %v", want, got)
}
@@ -556,6 +558,9 @@ func TestBatchSpanProcessorForceFlushTimeout(t *testing.T) {
<-ctx.Done()
bsp := sdktrace.NewBatchSpanProcessor(indefiniteExporter{})
t.Cleanup(func() {
assert.NoError(t, bsp.Shutdown(context.Background()))
})
if got, want := bsp.ForceFlush(ctx), context.DeadlineExceeded; !errors.Is(got, want) {
t.Errorf("expected %q error, got %v", want, got)
}
@@ -569,6 +574,9 @@ func TestBatchSpanProcessorForceFlushQueuedSpans(t *testing.T) {
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exp),
)
t.Cleanup(func() {
assert.NoError(t, tp.Shutdown(context.Background()))
})
tracer := tp.Tracer("tracer")
@@ -641,6 +649,9 @@ func BenchmarkSpanProcessorOnEnd(b *testing.B) {
tracetest.NewNoopExporter(),
sdktrace.WithMaxExportBatchSize(bb.batchSize),
)
b.Cleanup(func() {
_ = bsp.Shutdown(context.Background())
})
snap := tracetest.SpanStub{}.Snapshot()
b.ResetTimer()
@@ -665,6 +676,9 @@ func BenchmarkSpanProcessorVerboseLogging(b *testing.B) {
tracetest.NewNoopExporter(),
sdktrace.WithMaxExportBatchSize(10),
))
b.Cleanup(func() {
_ = tp.Shutdown(context.Background())
})
tracer := tp.Tracer("bench")
ctx := context.Background()