Skip to content

Commit

Permalink
Shut down all processors even on error
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k committed Aug 17, 2022
1 parent d96e8d2 commit e8eedf9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sdk/trace/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ var _ trace.TracerProvider = &TracerProvider{}
// NewTracerProvider returns a new and configured TracerProvider.
//
// By default the returned TracerProvider is configured with:
// - a ParentBased(AlwaysSample) Sampler
// - a random number IDGenerator
// - the resource.Default() Resource
// - the default SpanLimits.
// - a ParentBased(AlwaysSample) Sampler
// - a random number IDGenerator
// - the resource.Default() Resource
// - the default SpanLimits.
//
// The passed opts are used to override these default values and configure the
// returned TracerProvider appropriately.
Expand Down Expand Up @@ -241,10 +241,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():
Expand All @@ -257,10 +254,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.
Expand Down
22 changes: 22 additions & 0 deletions sdk/trace/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Equal(t, err, spErr1)
assert.False(t, sp1.running)
assert.False(t, sp2.running)
}

func TestFailedProcessorShutdownInUnregister(t *testing.T) {
handler.Reset()
stp := NewTracerProvider()
Expand Down

0 comments on commit e8eedf9

Please sign in to comment.