diff --git a/NOTICE.txt b/NOTICE.txt index 1549d89c2703..d1600a494186 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -12488,11 +12488,11 @@ SOFTWARE -------------------------------------------------------------------------------- Dependency : github.com/elastic/elastic-agent-libs -Version: v0.18.1 +Version: v0.18.7 Licence type (autodetected): Apache-2.0 -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.1/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.18.7/LICENSE: Apache License Version 2.0, January 2004 diff --git a/go.mod b/go.mod index 94ccb907e5dd..71f66b3e793d 100644 --- a/go.mod +++ b/go.mod @@ -176,7 +176,7 @@ require ( github.com/elastic/bayeux v1.0.5 github.com/elastic/ebpfevents v0.6.0 github.com/elastic/elastic-agent-autodiscover v0.9.0 - github.com/elastic/elastic-agent-libs v0.18.1 + github.com/elastic/elastic-agent-libs v0.18.7 github.com/elastic/elastic-agent-system-metrics v0.11.7 github.com/elastic/go-elasticsearch/v8 v8.17.0 github.com/elastic/go-quark v0.3.0 diff --git a/go.sum b/go.sum index 87da6b686820..952612a1bf32 100644 --- a/go.sum +++ b/go.sum @@ -350,8 +350,8 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0 github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4= github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE= github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI= -github.com/elastic/elastic-agent-libs v0.18.1 h1:dE6jf/D9bP8eRMQsV7KKpKV/G8zQzwMFBTj1w4e716c= -github.com/elastic/elastic-agent-libs v0.18.1/go.mod h1:rWdyrrAFzZwgNNi41Tsqhlt2c2GdXWhCEwcsnqISJ2U= +github.com/elastic/elastic-agent-libs v0.18.7 h1:C/63JieRiRIKBCOHnusIQ6yGBBmTU9rqcxneOw3zVX4= +github.com/elastic/elastic-agent-libs v0.18.7/go.mod h1:Repx7BMzE1v/gTipPogNIQeEnSGwOWGBC63h7h9c5aM= github.com/elastic/elastic-agent-system-metrics v0.11.7 h1:1xm2okCM0eQZ4jivZgUFSlt6HAn/nPgKB/Fj8eLG6mY= github.com/elastic/elastic-agent-system-metrics v0.11.7/go.mod h1:nzkrGajQA29YNcfP62gfzhxX9an3/xdQ3RmfQNw9YTI= github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA= diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 876e5aa45bd7..c09e32730638 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -348,6 +348,14 @@ func NewBeatReceiver(settings Settings, receiverConfig map[string]interface{}, u return nil, fmt.Errorf("error unpacking beats logging config: %w\n%v", err, b.Config.Logging) } + if logpConfig.WithFields != nil { + var fields = []zapcore.Field{} + for key, value := range logpConfig.WithFields { + fields = append(fields, zap.Any(key, value)) + } + core = core.With(fields) + } + if err := logp.ConfigureWithCore(logpConfig, core); err != nil { return nil, fmt.Errorf("error configuring beats logp: %w", err) } diff --git a/x-pack/filebeat/tests/integration/otel_test.go b/x-pack/filebeat/tests/integration/otel_test.go index 7a147add0dbe..cf7bb4d5932b 100644 --- a/x-pack/filebeat/tests/integration/otel_test.go +++ b/x-pack/filebeat/tests/integration/otel_test.go @@ -7,12 +7,14 @@ package integration import ( + "bufio" "context" "crypto/tls" "fmt" "net/http" "os" "path/filepath" + "strings" "testing" "time" @@ -40,8 +42,8 @@ output: hosts: - localhost:9200 protocol: http + password: testing username: admin - password: testing index: %s queue.mem.flush.timeout: 0s processors: @@ -170,3 +172,59 @@ func assertMapsEqual(t *testing.T, m1, m2 mapstr.M, ignoredFields []string, msg } require.Equal(t, "", cmp.Diff(flatM1, flatM2), "expected maps to be equal") } + +// This test ensures the functionality of `logging.with_fields` on beatreceivers +func TestBeatReceiverLoggingWithFields(t *testing.T) { + var filebeatBasicConfig = ` +filebeat.inputs: + - type: filestream + id: filestream-input-id + enabled: true + paths: + - /tmp/flog.log +output: + elasticsearch: + hosts: + - localhost:9200 + protocol: http + username: admin + password: testing +logging.with_fields: + component: filebeat-otel-test +path.home: %s + +` + // start filebeat in otel mode + filebeatOTel := integration.NewBeat( + t, + "filebeat-otel", + "../../filebeat.test", + "otel", + ) + + tempDir := filebeatOTel.TempDir() + s := fmt.Sprintf(filebeatBasicConfig, tempDir) + filebeatOTel.WriteConfigFile(s) + filebeatOTel.Start() + + require.Eventually(t, func() bool { + // we must open it each time in case no logs have arrived yet + f, err := os.Open(filepath.Join(tempDir, "stderr")) + if err != nil { + return false + } + defer f.Close() + + r := bufio.NewScanner(f) + + for r.Scan() { + line := r.Text() + if strings.Contains(line, `"name": "filebeatreceiver"`) { + fmt.Println(line) + return assert.True(t, strings.Contains(line, `"component": "filebeat-otel-test"`)) + } + } + return false + }, 10*time.Second, 100*time.Millisecond, "additional logging context was not added") + +}