|
9 | 9 | "github.com/spf13/cobra" |
10 | 10 | "github.com/stretchr/testify/assert" |
11 | 11 | "github.com/stretchr/testify/require" |
| 12 | + "go.opentelemetry.io/otel" |
| 13 | + "go.opentelemetry.io/otel/trace/noop" |
12 | 14 |
|
13 | 15 | "github.com/github/gh-aw-mcpg/internal/config" |
14 | 16 | "github.com/github/gh-aw-mcpg/internal/tracing" |
@@ -91,6 +93,9 @@ func TestInitTracingProviderWithFallback(t *testing.T) { |
91 | 93 | // HTTP OTLP exporters are lazily connected: otlptracehttp.New succeeds even |
92 | 94 | // for unreachable endpoints, so InitProvider does not return an error and the |
93 | 95 | // warn callback is never invoked. The provider is a real SDK (non-noop) instance. |
| 96 | + // Reset the global OTel provider to noop after the subtest to avoid leaking |
| 97 | + // background batcher goroutines and making other tests order-dependent. |
| 98 | + t.Cleanup(func() { otel.SetTracerProvider(noop.NewTracerProvider()) }) |
94 | 99 | var warnCalled bool |
95 | 100 | cfg := &config.TracingConfig{ |
96 | 101 | Endpoint: "https://127.0.0.1:1/does-not-exist", |
@@ -129,6 +134,9 @@ func TestShutdownTracingProviderWithTimeout(t *testing.T) { |
129 | 134 |
|
130 | 135 | t.Run("sdk provider shuts down cleanly", func(t *testing.T) { |
131 | 136 | // HTTP OTLP exporters are lazy; construction succeeds even for unreachable endpoints. |
| 137 | + // Reset the global OTel provider to noop after the subtest so that a shut-down |
| 138 | + // provider is not left as the global, which would make later tests order-dependent. |
| 139 | + t.Cleanup(func() { otel.SetTracerProvider(noop.NewTracerProvider()) }) |
132 | 140 | provider, err := tracing.InitProvider(context.Background(), &config.TracingConfig{ |
133 | 141 | Endpoint: "http://127.0.0.1:14318", |
134 | 142 | }) |
|
0 commit comments