Skip to content

Commit c29c6fd

Browse files
authored
Shutdown underlying span exporter while shutting down BatchSpanProcessor (open-telemetry#1443)
* Fix BatchSpanProcessor does not shutdown underlying span exporter * Update CHANGELOG * Fix tests * Update CHANGELOG.md
1 parent dfece3d commit c29c6fd

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
4747
- Remove Metric export functionality related to quantiles and summary data points: this is not specified (#1412)
4848
- Remove DDSketch metric aggregator; our intention is to re-introduce this as an option of the histogram aggregator after [new OTLP histogram data types](https://github.com/open-telemetry/opentelemetry-proto/pull/226) are released (#1412)
4949

50+
### Fixed
51+
52+
- `BatchSpanProcessor.Shutdown()` will now shutdown underlying `export.SpanExporter`. (#1443)
53+
5054
## [0.15.0] - 2020-12-10
5155

5256
### Added

sdk/trace/batch_span_processor.go

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ func (bsp *BatchSpanProcessor) Shutdown(ctx context.Context) error {
132132
go func() {
133133
close(bsp.stopCh)
134134
bsp.stopWait.Wait()
135+
if bsp.e != nil {
136+
if err := bsp.e.Shutdown(ctx); err != nil {
137+
otel.Handle(err)
138+
}
139+
}
135140
close(wait)
136141
}()
137142
// Wait until the wait group is done or the context is cancelled

sdk/trace/batch_span_processor_test.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/stretchr/testify/assert"
25+
2426
"go.opentelemetry.io/otel/trace"
2527

2628
export "go.opentelemetry.io/otel/sdk/export/trace"
2729
sdktrace "go.opentelemetry.io/otel/sdk/trace"
2830
)
2931

3032
type testBatchExporter struct {
31-
mu sync.Mutex
32-
spans []*export.SpanSnapshot
33-
sizes []int
34-
batchCount int
33+
mu sync.Mutex
34+
spans []*export.SpanSnapshot
35+
sizes []int
36+
batchCount int
37+
shutdownCount int
3538
}
3639

3740
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
4447
return nil
4548
}
4649

47-
func (t *testBatchExporter) Shutdown(context.Context) error { return nil }
50+
func (t *testBatchExporter) Shutdown(context.Context) error {
51+
t.shutdownCount++
52+
return nil
53+
}
4854

4955
func (t *testBatchExporter) len() int {
5056
t.mu.Lock()
@@ -231,16 +237,19 @@ func getSpanContext() trace.SpanContext {
231237
}
232238

233239
func TestBatchSpanProcessorShutdown(t *testing.T) {
234-
bsp := sdktrace.NewBatchSpanProcessor(&testBatchExporter{})
240+
var bp testBatchExporter
241+
bsp := sdktrace.NewBatchSpanProcessor(&bp)
235242

236243
err := bsp.Shutdown(context.Background())
237244
if err != nil {
238245
t.Error("Error shutting the BatchSpanProcessor down\n")
239246
}
247+
assert.Equal(t, 1, bp.shutdownCount, "shutdown from span exporter not called")
240248

241249
// Multiple call to Shutdown() should not panic.
242250
err = bsp.Shutdown(context.Background())
243251
if err != nil {
244252
t.Error("Error shutting the BatchSpanProcessor down\n")
245253
}
254+
assert.Equal(t, 1, bp.shutdownCount)
246255
}

0 commit comments

Comments
 (0)