Skip to content

Commit

Permalink
Fix logging exporter to not mutate the data (#6516)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan <[email protected]>
  • Loading branch information
bogdandrutu authored Nov 10, 2022
1 parent 226dc13 commit 3d21bc8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .chloggen/fixlogging.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion exporter/loggingexporter/internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
3 changes: 3 additions & 0 deletions pdata/pcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3d21bc8

Please sign in to comment.