You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-27 22:49:15 +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:
@@ -47,6 +47,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- Remove Metric export functionality related to quantiles and summary data points: this is not specified (#1412)
|
- Remove Metric export functionality related to quantiles and summary data points: this is not specified (#1412)
|
||||||
- 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)
|
- 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)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- `BatchSpanProcessor.Shutdown()` will now shutdown underlying `export.SpanExporter`. (#1443)
|
||||||
|
|
||||||
## [0.15.0] - 2020-12-10
|
## [0.15.0] - 2020-12-10
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -132,6 +132,11 @@ func (bsp *BatchSpanProcessor) Shutdown(ctx context.Context) error {
|
|||||||
go func() {
|
go func() {
|
||||||
close(bsp.stopCh)
|
close(bsp.stopCh)
|
||||||
bsp.stopWait.Wait()
|
bsp.stopWait.Wait()
|
||||||
|
if bsp.e != nil {
|
||||||
|
if err := bsp.e.Shutdown(ctx); err != nil {
|
||||||
|
otel.Handle(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
close(wait)
|
close(wait)
|
||||||
}()
|
}()
|
||||||
// Wait until the wait group is done or the context is cancelled
|
// Wait until the wait group is done or the context is cancelled
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
export "go.opentelemetry.io/otel/sdk/export/trace"
|
export "go.opentelemetry.io/otel/sdk/export/trace"
|
||||||
@@ -28,10 +30,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type testBatchExporter struct {
|
type testBatchExporter struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
spans []*export.SpanSnapshot
|
spans []*export.SpanSnapshot
|
||||||
sizes []int
|
sizes []int
|
||||||
batchCount int
|
batchCount int
|
||||||
|
shutdownCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testBatchExporter) ExportSpans(ctx context.Context, ss []*export.SpanSnapshot) error {
|
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
|
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 {
|
func (t *testBatchExporter) len() int {
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
@@ -231,16 +237,19 @@ func getSpanContext() trace.SpanContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBatchSpanProcessorShutdown(t *testing.T) {
|
func TestBatchSpanProcessorShutdown(t *testing.T) {
|
||||||
bsp := sdktrace.NewBatchSpanProcessor(&testBatchExporter{})
|
var bp testBatchExporter
|
||||||
|
bsp := sdktrace.NewBatchSpanProcessor(&bp)
|
||||||
|
|
||||||
err := bsp.Shutdown(context.Background())
|
err := bsp.Shutdown(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error shutting the BatchSpanProcessor down\n")
|
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.
|
// Multiple call to Shutdown() should not panic.
|
||||||
err = bsp.Shutdown(context.Background())
|
err = bsp.Shutdown(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error shutting the BatchSpanProcessor down\n")
|
t.Error("Error shutting the BatchSpanProcessor down\n")
|
||||||
}
|
}
|
||||||
|
assert.Equal(t, 1, bp.shutdownCount)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user