Skip to content

Commit 230c98d

Browse files
fix: re-introduce beats receivers log the same metadata as beats processes (#8717)
1 parent 4344a11 commit 230c98d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

internal/pkg/otel/manager/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (m *OTelManager) Run(ctx context.Context) error {
141141

142142
newRetries := m.recoveryRetries.Add(1)
143143
m.logger.Infof("collector recovery restarting, total retries: %d", newRetries)
144-
proc, err = m.execution.startCollector(ctx, m.logger, m.cfg, collectorRunErr, m.statusCh)
144+
proc, err = m.execution.startCollector(ctx, m.baseLogger, m.cfg, collectorRunErr, m.statusCh)
145145
if err != nil {
146146
reportErr(ctx, m.errCh, err)
147147
// reset the restart timer to the next backoff
@@ -174,7 +174,7 @@ func (m *OTelManager) Run(ctx context.Context) error {
174174

175175
// in this rare case the collector stopped running but a configuration was
176176
// provided and the collector stopped with a clean exit
177-
proc, err = m.execution.startCollector(ctx, m.logger, m.cfg, collectorRunErr, m.statusCh)
177+
proc, err = m.execution.startCollector(ctx, m.baseLogger, m.cfg, collectorRunErr, m.statusCh)
178178
if err != nil {
179179
// failed to create the collector (this is different then
180180
// it's failing to run). we do not retry creation on failure
@@ -239,7 +239,7 @@ func (m *OTelManager) Run(ctx context.Context) error {
239239
} else {
240240
// either a new configuration or the first configuration
241241
// that results in the collector being started
242-
proc, err = m.execution.startCollector(ctx, m.logger, m.cfg, collectorRunErr, m.statusCh)
242+
proc, err = m.execution.startCollector(ctx, m.baseLogger, m.cfg, collectorRunErr, m.statusCh)
243243
if err != nil {
244244
// failed to create the collector (this is different then
245245
// it's failing to run). we do not retry creation on failure

internal/pkg/otel/manager/manager_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,42 @@ func TestOTelManager_Run(t *testing.T) {
516516
}
517517
}
518518

519+
func TestOTelManager_Logging(t *testing.T) {
520+
ctx, cancel := context.WithCancel(context.Background())
521+
defer cancel()
522+
base, obs := loggertest.New("otel")
523+
l, _ := loggertest.New("otel-manager")
524+
m, err := NewOTelManager(l, logp.DebugLevel, base, EmbeddedExecutionMode)
525+
require.NoError(t, err, "could not create otel manager")
526+
527+
go func() {
528+
err := m.Run(ctx)
529+
assert.ErrorIs(t, err, context.Canceled, "otel manager should be cancelled")
530+
}()
531+
532+
// watch is synchronous, so we need to read from it to avoid blocking the manager
533+
go func() {
534+
for {
535+
select {
536+
case <-m.Watch():
537+
case <-ctx.Done():
538+
return
539+
}
540+
}
541+
}()
542+
543+
cfg := confmap.NewFromStringMap(testConfig)
544+
m.Update(cfg)
545+
546+
// the collector should log to the base logger
547+
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
548+
logs := obs.All()
549+
require.NotEmpty(collect, logs, "Logs should not be empty")
550+
firstMessage := logs[0].Message
551+
assert.Equal(collect, firstMessage, "Setting up own telemetry...")
552+
}, time.Second*10, time.Second)
553+
}
554+
519555
// statusToYaml converts the status.AggregateStatus to a YAML string representation.
520556
func statusToYaml(s *status.AggregateStatus) string {
521557
printable := toSerializableStatus(s)

0 commit comments

Comments
 (0)