1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-06-25 00:16:49 +02:00

Shutdown underlying span exporter while shutting down BatchSpanProcessor (#1443)

* Fix BatchSpanProcessor does not shutdown underlying span exporter

* Update CHANGELOG

* Fix tests

* Update CHANGELOG.md
This commit is contained in:
Sam Xie
2021-01-14 09:14:03 +08:00
committed by GitHub
parent dfece3d2b9
commit c29c6fd1ad
3 changed files with 24 additions and 6 deletions

View File

@ -21,6 +21,8 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/trace"
export "go.opentelemetry.io/otel/sdk/export/trace"
@ -28,10 +30,11 @@ import (
)
type testBatchExporter struct {
mu sync.Mutex
spans []*export.SpanSnapshot
sizes []int
batchCount int
mu sync.Mutex
spans []*export.SpanSnapshot
sizes []int
batchCount int
shutdownCount int
}
func (t *testBatchExporter) ExportSpans(ctx context.Context, ss []*export.SpanSnapshot) error {
@ -44,7 +47,10 @@ func (t *testBatchExporter) ExportSpans(ctx context.Context, ss []*export.SpanSn
return nil
}
func (t *testBatchExporter) Shutdown(context.Context) error { return nil }
func (t *testBatchExporter) Shutdown(context.Context) error {
t.shutdownCount++
return nil
}
func (t *testBatchExporter) len() int {
t.mu.Lock()
@ -231,16 +237,19 @@ func getSpanContext() trace.SpanContext {
}
func TestBatchSpanProcessorShutdown(t *testing.T) {
bsp := sdktrace.NewBatchSpanProcessor(&testBatchExporter{})
var bp testBatchExporter
bsp := sdktrace.NewBatchSpanProcessor(&bp)
err := bsp.Shutdown(context.Background())
if err != nil {
t.Error("Error shutting the BatchSpanProcessor down\n")
}
assert.Equal(t, 1, bp.shutdownCount, "shutdown from span exporter not called")
// Multiple call to Shutdown() should not panic.
err = bsp.Shutdown(context.Background())
if err != nil {
t.Error("Error shutting the BatchSpanProcessor down\n")
}
assert.Equal(t, 1, bp.shutdownCount)
}