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:
parent
399ffe1888
commit
13ddf7d31e
@ -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.
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user