diff --git a/internal/pkg/otel/manager/manager.go b/internal/pkg/otel/manager/manager.go index af5a8052ce..8d9bc64975 100644 --- a/internal/pkg/otel/manager/manager.go +++ b/internal/pkg/otel/manager/manager.go @@ -115,7 +115,7 @@ func (m *OTelManager) Run(ctx context.Context) error { // pass the error to the errCh so the coordinator, unless it's a cancel error if !errors.Is(err, context.Canceled) { select { - case m.errCh <- nil: + case m.errCh <- err: case <-ctx.Done(): } } diff --git a/internal/pkg/otel/manager/manager_test.go b/internal/pkg/otel/manager/manager_test.go index c0d8bfd430..f4f9b422dd 100644 --- a/internal/pkg/otel/manager/manager_test.go +++ b/internal/pkg/otel/manager/manager_test.go @@ -183,3 +183,44 @@ func TestOTelManager_Run(t *testing.T) { t.Errorf("otel manager returned unexpected error: %v", runErr) } } + +func TestOTelManager_ConfigError(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + l, _ := loggertest.New("otel") + m := NewOTelManager(l) + + go func() { + err := m.Run(ctx) + require.ErrorIs(t, err, context.Canceled, "otel manager should be cancelled") + }() + + // watch is synchronous, so we need to read from it to avoid blocking the manager + go func() { + for { + select { + case <-m.Watch(): + case <-ctx.Done(): + return + } + } + }() + + cfg := confmap.New() // invalid config + m.Update(cfg) + timeoutCh := time.After(time.Second * 5) + var err error +outer: + for { + select { + case e := <-m.Errors(): + if e != nil { + err = e + break outer + } + case <-timeoutCh: + break outer + } + } + assert.Error(t, err, "otel manager should have returned an error") +}