diff --git a/processor/groupbytraceprocessor/storage_memory.go b/processor/groupbytraceprocessor/storage_memory.go index 6660e0a0d84..24ac9c0e838 100644 --- a/processor/groupbytraceprocessor/storage_memory.go +++ b/processor/groupbytraceprocessor/storage_memory.go @@ -48,8 +48,10 @@ func (st *memoryStorage) createOrAppend(traceID pdata.TraceID, trace pdata.Resou if ok { // we have a trace already, append the spans for i := 0; i < trace.InstrumentationLibrarySpans().Len(); i++ { - spans := trace.InstrumentationLibrarySpans().At(i) - existing.InstrumentationLibrarySpans().Append(&spans) + newSpans := pdata.NewInstrumentationLibrarySpans() + orig := trace.InstrumentationLibrarySpans().At(i) + orig.CopyTo(newSpans) + existing.InstrumentationLibrarySpans().Append(&newSpans) } } else { newTrace := pdata.NewResourceSpans() diff --git a/processor/groupbytraceprocessor/storage_memory_test.go b/processor/groupbytraceprocessor/storage_memory_test.go index 09eca32a313..de00c7f331b 100644 --- a/processor/groupbytraceprocessor/storage_memory_test.go +++ b/processor/groupbytraceprocessor/storage_memory_test.go @@ -116,6 +116,7 @@ func TestMemoryAppendSpans(t *testing.T) { secondSpan := pdata.NewSpan() secondSpan.InitEmpty() + secondSpan.SetName("second-name") secondSpan.SetTraceID(traceID) secondSpan.SetSpanID(pdata.NewSpanID([]byte{5, 6, 7, 8})) @@ -140,9 +141,17 @@ func TestMemoryAppendSpans(t *testing.T) { err := st.createOrAppend(traceID, secondBatch) require.NoError(t, err) + // override something in the second span, to make sure we are storing a copy + secondSpan.SetName("changed-second-name") + // verify retrieved, err := st.get(traceID) require.NoError(t, err) + assert.Equal(t, "second-name", retrieved.InstrumentationLibrarySpans().At(1).Spans().At(0).Name()) + + // now that we checked that the secondSpan change here didn't have an effect, revert + // so that we can compare the that everything else has the same value + secondSpan.SetName("second-name") assert.Equal(t, expected, retrieved) }