[pdata] Map Remove
and RemoveIf
implementations have unforeseen side-effects
#13073
Labels
bug
Something isn't working
Uh oh!
There was an error while loading. Please reload this page.
Component(s)
pdata
What happened?
Describe the bug
The way the
Remove
andRemoveIf
functions are implemented forpcommon.Map
, they lead to unexpected side-effects that could have impact on the integrity of the data if not aware.A
pcommon.Value
that first is retrieved from a map, then gets removed from said map, will have its value changed. So then re-using the value can lead to bad consequences.The following minimal test shows the issue:
By the time the value for
attr.to.move
gets inserted into the second Resource attributes, due to theRemove
called before, the value is no longermover
butdash0
.I understand why the
Remove
andRemoveIf
are implemented that way, as not to have to move every key-value pair in the slice. But I don't think such side-effects are acceptable.Steps to reproduce
See the above test case for a reproducer
What did you expect to see?
The internal value of the
pcommon.Value
object not getting updated whenever that entry is removed from a map.What did you see instead?
The internal value getting changed from
mover
todash0
(which is the value belonging to theservice.namespace
attribute).Collector version
v1.32.0
Environment information
not applicable
OpenTelemetry Collector configuration
not applicable
Log output
Additional context
One option would be copying the value:
But also for this, users need to be aware and its easily forgotten / overlooked.
The text was updated successfully, but these errors were encountered: