diff --git a/collector/factory.go b/collector/factory.go index c98ec28ab..4883f9dda 100644 --- a/collector/factory.go +++ b/collector/factory.go @@ -69,7 +69,10 @@ func BuildProfilesReceiver(options ...option) xreceiver.CreateProfilesFunc { ExecutableReporter: controllerOption.executableReporter, OnShutdown: controllerOption.onShutdown, } - + err := controlerCfg.Validate() + if err != nil { + return nil, err + } return internal.NewController(controlerCfg, rs, nextConsumer) } } diff --git a/collector/factory_test.go b/collector/factory_test.go index d4ef2cc8b..55f7e2879 100644 --- a/collector/factory_test.go +++ b/collector/factory_test.go @@ -4,6 +4,7 @@ package collector import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -12,6 +13,8 @@ import ( "go.opentelemetry.io/collector/receiver/receivertest" ) +const invalidSamplesPerSecond = 0 + func TestNewFactory(t *testing.T) { f := NewFactory() require.NotNil(t, f) @@ -32,6 +35,11 @@ func TestCreateProfilesReceiver(t *testing.T) { name: "Nil config", wantError: errInvalidConfig, }, + { + name: "Invalid config", + config: Config{SamplesPerSecond: invalidSamplesPerSecond}, + wantError: fmt.Errorf("invalid sampling frequency: %d", invalidSamplesPerSecond), + }, } { t.Run(tt.name, func(t *testing.T) { t.Parallel() @@ -43,7 +51,11 @@ func TestCreateProfilesReceiver(t *testing.T) { tt.config, consumertest.NewNop(), ) - require.ErrorIs(t, err, tt.wantError) + + // Handle nil errors + if err != nil || tt.wantError != nil { + require.ErrorAs(t, err, &tt.wantError) + } }) } }