From 48dd7d9aa3261575539563934b902bafd0bf0325 Mon Sep 17 00:00:00 2001 From: Caleb Hurshman Date: Wed, 31 May 2023 16:31:43 -0400 Subject: [PATCH] check error on FromRaw return --- receiver/kafkareceiver/README.md | 1 - receiver/kafkareceiver/json_unmarshaler.go | 5 +++-- receiver/kafkareceiver/testdata/config.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/receiver/kafkareceiver/README.md b/receiver/kafkareceiver/README.md index d97babddc18b..4f5db28170b9 100644 --- a/receiver/kafkareceiver/README.md +++ b/receiver/kafkareceiver/README.md @@ -12,7 +12,6 @@ [observiq]: https://github.com/observIQ/observiq-otel-collector [splunk]: https://github.com/signalfx/splunk-otel-collector [sumo]: https://github.com/SumoLogic/sumologic-otel-collector - Kafka receiver receives traces, metrics, and logs from Kafka. Message payload encoding is configurable. diff --git a/receiver/kafkareceiver/json_unmarshaler.go b/receiver/kafkareceiver/json_unmarshaler.go index 836b41962bd1..80d42214c269 100644 --- a/receiver/kafkareceiver/json_unmarshaler.go +++ b/receiver/kafkareceiver/json_unmarshaler.go @@ -32,8 +32,9 @@ func (r *jsonLogsUnmarshaler) Unmarshal(buf []byte) (plog.Logs, error) { logRecords.SetObservedTimestamp(pcommon.NewTimestampFromTime(time.Now())) // Set the unmarshaled jsonVal as the body of the log record - logRecords.Body().SetEmptyMap().FromRaw(jsonVal) - + if err := logRecords.Body().SetEmptyMap().FromRaw(jsonVal); err != nil { + return p, err + } return p, nil } diff --git a/receiver/kafkareceiver/testdata/config.yaml b/receiver/kafkareceiver/testdata/config.yaml index af6e5abf3e2f..f4b99b780391 100644 --- a/receiver/kafkareceiver/testdata/config.yaml +++ b/receiver/kafkareceiver/testdata/config.yaml @@ -16,7 +16,7 @@ kafka: backoff: 5s kafka/logs: topic: logs - encoding: text + encoding: direct brokers: - "coffee:123" - "foobar:456"