diff --git a/receiver/datadogreceiver/factory_test.go b/receiver/datadogreceiver/factory_test.go index d95d9c164bdf..592003a1b7b7 100644 --- a/receiver/datadogreceiver/factory_test.go +++ b/receiver/datadogreceiver/factory_test.go @@ -15,6 +15,7 @@ import ( func TestCreateReceiver(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() + cfg.(*Config).Endpoint = "http://localhost:0" tReceiver, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop()) assert.NoError(t, err) diff --git a/receiver/datadogreceiver/receiver.go b/receiver/datadogreceiver/receiver.go index 81caa1debbee..902809fbdd9e 100644 --- a/receiver/datadogreceiver/receiver.go +++ b/receiver/datadogreceiver/receiver.go @@ -17,6 +17,7 @@ import ( ) type datadogReceiver struct { + address string config *Config params receiver.CreateSettings nextConsumer consumer.Traces @@ -66,6 +67,8 @@ func (ddr *datadogReceiver) Start(_ context.Context, host component.Host) error return fmt.Errorf("failed to create datadog listener: %w", err) } + ddr.address = hln.Addr().String() + go func() { if err := ddr.server.Serve(hln); err != nil && !errors.Is(err, http.ErrServerClosed) { host.ReportFatalError(fmt.Errorf("error starting datadog receiver: %w", err)) diff --git a/receiver/datadogreceiver/receiver_test.go b/receiver/datadogreceiver/receiver_test.go index 5c7d4c6f6552..906073866a36 100644 --- a/receiver/datadogreceiver/receiver_test.go +++ b/receiver/datadogreceiver/receiver_test.go @@ -22,7 +22,9 @@ import ( func TestDatadogReceiver_Lifecycle(t *testing.T) { factory := NewFactory() - ddr, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), factory.CreateDefaultConfig(), consumertest.NewNop()) + cfg := factory.CreateDefaultConfig() + cfg.(*Config).Endpoint = "localhost:0" + ddr, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop()) assert.NoError(t, err, "Receiver should be created") err = ddr.Start(context.Background(), componenttest.NewNopHost()) @@ -34,6 +36,7 @@ func TestDatadogReceiver_Lifecycle(t *testing.T) { func TestDatadogServer(t *testing.T) { cfg := createDefaultConfig().(*Config) + cfg.Endpoint = "localhost:0" // Using a randomly assigned address dd, err := newDataDogReceiver( cfg, consumertest.NewNop(), @@ -69,7 +72,7 @@ func TestDatadogServer(t *testing.T) { req, err := http.NewRequest( http.MethodPost, - fmt.Sprintf("http://%s/v0.7/traces", cfg.Endpoint), + fmt.Sprintf("http://%s/v0.7/traces", dd.(*datadogReceiver).address), tc.op, ) require.NoError(t, err, "Must not error when creating request")