From 45cedd0867277126c5f816c9045019b51d925341 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2026 00:10:40 +0000 Subject: [PATCH] test: add InitProvider coverage for all-exporters-fail path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add TestInitProvider_AllExportersFail to cover the code path in InitProvider where every OTLP exporter fails to initialize. A pre-cancelled context causes otlptracehttp.New to return an error immediately, which exercises the 'len(exporters) == 0' guard that returns an error (provider.go:177-179). Coverage: internal/tracing 96.5% → 97.8% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/tracing/provider_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/tracing/provider_test.go b/internal/tracing/provider_test.go index 25058f05c..a140dd64e 100644 --- a/internal/tracing/provider_test.go +++ b/internal/tracing/provider_test.go @@ -185,6 +185,27 @@ func TestInitProvider_NoEndpoint_ReturnsNoopProvider(t *testing.T) { assert.IsType(t, noop.NewTracerProvider(), tp) } +// TestInitProvider_AllExportersFail verifies that InitProvider returns an error when +// every OTLP exporter fails to initialize (e.g. cancelled context). +func TestInitProvider_AllExportersFail(t *testing.T) { + // A pre-cancelled context causes otlptracehttp.New to return an error + // immediately, exercising the "len(exporters) == 0" error path. + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + t.Setenv("GH_AW_OTLP_ENDPOINTS", "") + + cfg := &config.TracingConfig{ + Endpoint: "http://localhost:14318", + ServiceName: "test-service", + } + + provider, err := tracing.InitProvider(ctx, cfg) + require.Error(t, err, "InitProvider should return an error when all exporters fail") + assert.Nil(t, provider) + assert.Contains(t, err.Error(), "failed to create any OTLP trace exporters") +} + func TestInitProvider_EmptyEndpoint_ReturnsNoopProvider(t *testing.T) { ctx := context.Background() t.Setenv("GH_AW_OTLP_ENDPOINTS", "") // prevent ambient CI env from overriding noop path