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

Modify ForceFlush to abort after timeout/cancellation (#1757)

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
humivo
2021-04-01 10:42:19 -07:00
committed by GitHub
parent 3947cab4be
commit 928e3c38e6
3 changed files with 87 additions and 1 deletions

View File

@ -148,7 +148,23 @@ func (bsp *batchSpanProcessor) Shutdown(ctx context.Context) error {
// ForceFlush exports all ended spans that have not yet been exported.
func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error {
return bsp.exportSpans(ctx)
var err error
if bsp.e != nil {
wait := make(chan struct{})
go func() {
if err := bsp.exportSpans(ctx); err != nil {
otel.Handle(err)
}
close(wait)
}()
// Wait until the export is finished or the context is cancelled/timed out
select {
case <-wait:
case <-ctx.Done():
err = ctx.Err()
}
}
return err
}
func WithMaxQueueSize(size int) BatchSpanProcessorOption {