From 3d21bc8c984ef53ad01ca31b676bf2bb26e73018 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Thu, 10 Nov 2022 09:40:02 -0800 Subject: [PATCH] Fix logging exporter to not mutate the data (#6516) Signed-off-by: Bogdan --- .chloggen/fixlogging.yaml | 11 +++++++++++ .../loggingexporter/internal/otlptext/databuffer.go | 2 +- pdata/pcommon/common.go | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100755 .chloggen/fixlogging.yaml diff --git a/.chloggen/fixlogging.yaml b/.chloggen/fixlogging.yaml new file mode 100755 index 00000000000..bcc1fff2c9d --- /dev/null +++ b/.chloggen/fixlogging.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: loggingexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix logging exporter to not mutate the data + +# One or more tracking issues or pull requests related to the change +issues: [6420] diff --git a/exporter/loggingexporter/internal/otlptext/databuffer.go b/exporter/loggingexporter/internal/otlptext/databuffer.go index 7f53d81d619..03bbbdfacaf 100644 --- a/exporter/loggingexporter/internal/otlptext/databuffer.go +++ b/exporter/loggingexporter/internal/otlptext/databuffer.go @@ -52,7 +52,7 @@ func (b *dataBuffer) logAttributes(header string, m pcommon.Map) { attrPrefix = headerParts[0] + attrPrefix } - m.Sort().Range(func(k string, v pcommon.Value) bool { + m.Range(func(k string, v pcommon.Value) bool { b.logEntry("%s %s: %s", attrPrefix, k, valueToString(v)) return true }) diff --git a/pdata/pcommon/common.go b/pdata/pcommon/common.go index 35451dcac42..3661e7401db 100644 --- a/pdata/pcommon/common.go +++ b/pdata/pcommon/common.go @@ -717,6 +717,9 @@ func (m Map) PutEmptySlice(k string) Slice { // Returns the same instance to allow nicer code like: // // assert.EqualValues(t, expected.Sort(), actual.Sort()) +// +// IMPORTANT: Sort mutates the data, if you call this function in a consumer, +// the consumer must be configured that it mutates data. func (m Map) Sort() Map { // Intention is to move the nil values at the end. sort.SliceStable(*m.getOrig(), func(i, j int) bool {