1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-06-27 00:21:15 +02:00

Fix panic, deadlock and race in BatchSpanProcessor (#4353)

This commit is contained in:
Robert Pająk
2023-07-25 10:13:45 +02:00
committed by GitHub
parent e26d8bd8f8
commit 088ac8e179
3 changed files with 67 additions and 40 deletions

View File

@ -594,6 +594,49 @@ func TestBatchSpanProcessorForceFlushQueuedSpans(t *testing.T) {
}
}
func TestBatchSpanProcessorConcurrentSafe(t *testing.T) {
ctx := context.Background()
var bp testBatchExporter
bsp := sdktrace.NewBatchSpanProcessor(&bp)
tp := basicTracerProvider(t)
tp.RegisterSpanProcessor(bsp)
tr := tp.Tracer(t.Name())
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
generateSpan(t, tr, testOption{genNumSpans: 1})
}()
wg.Add(1)
go func() {
defer wg.Done()
_ = bsp.ForceFlush(ctx)
}()
wg.Add(1)
go func() {
defer wg.Done()
_ = bsp.Shutdown(ctx)
}()
wg.Add(1)
go func() {
defer wg.Done()
_ = tp.ForceFlush(ctx)
}()
wg.Add(1)
go func() {
defer wg.Done()
_ = tp.Shutdown(ctx)
}()
wg.Wait()
}
func BenchmarkSpanProcessor(b *testing.B) {
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(