1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-20 03:30:02 +02:00

Shut down all processors even on error (#3091)

This commit is contained in:
Mikhail Mazurskiy 2022-09-03 02:50:44 +10:00 committed by GitHub
parent 399ffe1888
commit 13ddf7d31e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -248,10 +248,7 @@ func (p *TracerProvider) Shutdown(ctx context.Context) error {
if !ok {
return fmt.Errorf("failed to load span processors")
}
if len(spss) == 0 {
return nil
}
var retErr error
for _, sps := range spss {
select {
case <-ctx.Done():
@ -264,10 +261,15 @@ func (p *TracerProvider) Shutdown(ctx context.Context) error {
err = sps.sp.Shutdown(ctx)
})
if err != nil {
return err
if retErr == nil {
retErr = err
} else {
// Poor man's list of errors
retErr = fmt.Errorf("%v; %v", retErr, err)
}
}
}
return nil
return retErr
}
// TracerProviderOption configures a TracerProvider.

View File

@ -72,6 +72,28 @@ func TestFailedProcessorShutdown(t *testing.T) {
assert.Equal(t, err, spErr)
}
func TestFailedProcessorsShutdown(t *testing.T) {
stp := NewTracerProvider()
spErr1 := errors.New("basic span processor shutdown failure1")
spErr2 := errors.New("basic span processor shutdown failure2")
sp1 := &basicSpanProcesor{
running: true,
injectShutdownError: spErr1,
}
sp2 := &basicSpanProcesor{
running: true,
injectShutdownError: spErr2,
}
stp.RegisterSpanProcessor(sp1)
stp.RegisterSpanProcessor(sp2)
err := stp.Shutdown(context.Background())
assert.Error(t, err)
assert.EqualError(t, err, "basic span processor shutdown failure1; basic span processor shutdown failure2")
assert.False(t, sp1.running)
assert.False(t, sp2.running)
}
func TestFailedProcessorShutdownInUnregister(t *testing.T) {
handler.Reset()
stp := NewTracerProvider()