diff --git a/libbeat/otelbeat/oteltest/oteltest.go b/libbeat/otelbeat/oteltest/oteltest.go index 75f048b16d8b..5e5d095d0a1a 100644 --- a/libbeat/otelbeat/oteltest/oteltest.go +++ b/libbeat/otelbeat/oteltest/oteltest.go @@ -39,8 +39,13 @@ import ( ) type ReceiverConfig struct { - Name string - Config component.Config + // Name is the unique identifier for the component + Name string + // Beat is the name of the Beat that is running as a receiver + Beat string + // Config is the configuration for the receiver component + Config component.Config + // Factory is the factory to instantiate the receiver Factory receiver.Factory } @@ -73,6 +78,9 @@ func CheckReceivers(params CheckReceiversParams) { createReceiver := func(t *testing.T, rc ReceiverConfig) receiver.Logs { t.Helper() + require.NotEmpty(t, rc.Name, "receiver name must not be empty") + require.NotEmpty(t, rc.Beat, "receiver beat must not be empty") + var receiverSettings receiver.Settings // Replicate the behavior of the collector logger @@ -127,15 +135,31 @@ func CheckReceivers(params CheckReceiversParams) { } }) + beatForCompID := func(compID string) string { + for _, rec := range params.Receivers { + if rec.Name == compID { + return rec.Beat + } + } + + return "" + } + require.EventuallyWithT(t, func(ct *assert.CollectT) { logsMu.Lock() defer logsMu.Unlock() - // Ensure the logger fields from the otel collector are present in the logs. + // Ensure the logger fields from the otel collector are present for _, zl := range zapLogs.All() { + require.Contains(t, zl.ContextMap(), "otelcol.component.kind") + require.Equal(t, "receiver", zl.ContextMap()["otelcol.component.kind"]) + require.Contains(t, zl.ContextMap(), "otelcol.signal") + require.Equal(t, "logs", zl.ContextMap()["otelcol.signal"]) require.Contains(t, zl.ContextMap(), "otelcol.component.id") - require.Equal(t, zl.ContextMap()["otelcol.component.kind"], "receiver") - require.Equal(t, zl.ContextMap()["otelcol.signal"], "logs") + compID, ok := zl.ContextMap()["otelcol.component.id"].(string) + require.True(t, ok, "otelcol.component.id should be a string") + require.Contains(t, zl.ContextMap(), "service.name") + require.Equal(t, beatForCompID(compID), zl.ContextMap()["service.name"]) break } diff --git a/x-pack/filebeat/fbreceiver/receiver_test.go b/x-pack/filebeat/fbreceiver/receiver_test.go index e01435879546..8691b4c32de6 100644 --- a/x-pack/filebeat/fbreceiver/receiver_test.go +++ b/x-pack/filebeat/fbreceiver/receiver_test.go @@ -79,6 +79,7 @@ func TestNewReceiver(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "filebeat", Config: &config, Factory: NewFactory(), }, @@ -210,11 +211,13 @@ func TestMultipleReceivers(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "filebeat", Config: config(monitorSocket1), Factory: factory, }, { Name: "r2", + Beat: "filebeat", Config: config(monitorSocket2), Factory: factory, }, diff --git a/x-pack/libbeat/cmd/instance/beat.go b/x-pack/libbeat/cmd/instance/beat.go index 5f9410c4cab5..c45bc251c4cd 100644 --- a/x-pack/libbeat/cmd/instance/beat.go +++ b/x-pack/libbeat/cmd/instance/beat.go @@ -110,7 +110,7 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an logpConfig := logp.Config{} logpConfig.AddCaller = true - logpConfig.Beat = b.Info.Name + logpConfig.Beat = b.Info.Beat logpConfig.Files.MaxSize = 1 if b.Config.Logging == nil { diff --git a/x-pack/metricbeat/mbreceiver/receiver_test.go b/x-pack/metricbeat/mbreceiver/receiver_test.go index a80d0176a74d..f55c93c819e3 100644 --- a/x-pack/metricbeat/mbreceiver/receiver_test.go +++ b/x-pack/metricbeat/mbreceiver/receiver_test.go @@ -75,6 +75,7 @@ func TestNewReceiver(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "metricbeat", Config: &config, Factory: NewFactory(), }, @@ -183,11 +184,13 @@ func TestMultipleReceivers(t *testing.T) { Receivers: []oteltest.ReceiverConfig{ { Name: "r1", + Beat: "metricbeat", Config: &config1, Factory: factory, }, { Name: "r2", + Beat: "metricbeat", Config: &config2, Factory: factory, },