Repository: open-telemetry/opentelemetry-go
Pull request #3091 (2022-08-13 00:38:08)

Shut down all processors even on error

codecov[bot]: # [Codecov](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/3091?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) Report
> Merging [#3091](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/3091?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) (19b2b1f) into [main](https://codecov.io/gh/open-telemetry/opentelemetry-go/commit/d96e8d2912afcb0d205a80739798b9a56a7f0e70?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) (d96e8d2) will **decrease** coverage by `0.0%`.
> The diff coverage is `100.0%`.

[![Impacted file tree graph](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/3091/graphs/tree.svg?width=650&height=150&src=pr&token=8efTmh4kvf&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/3091?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)

```diff
@@           Coverage Diff           @@
##            main   #3091     +/-   ##
=======================================
- Coverage   76.2%   76.2%   -0.1%     
=======================================
  Files        179     179             
  Lines      11939   11937      -2     
=======================================
- Hits        9103    9101      -2     
  Misses      2596    2596             
  Partials     240     240             
```


| [Impacted Files](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/3091?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | |
|---|---|---|
| [sdk/trace/provider.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/3091/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c2RrL3RyYWNlL3Byb3ZpZGVyLmdv) | `85.4% <100.0%> (-0.2%)` | :arrow_down: |

ash2k: I think this is ready to be merged.

Patch:
diff --git a/sdk/trace/provider.go b/sdk/trace/provider.go
index a4b6c0da..74980179 100644
--- a/sdk/trace/provider.go
+++ b/sdk/trace/provider.go
@@ -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.


Test patch:
diff --git a/sdk/trace/provider_test.go b/sdk/trace/provider_test.go
index 39caf5a9..6ec3df67 100644
--- a/sdk/trace/provider_test.go
+++ b/sdk/trace/provider_test.go
@@ -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()