Skip to content

Commit

Permalink
Appending spans should store a copy of the span
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling committed Jul 30, 2020
1 parent ec1c50a commit a1e5229
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions processor/groupbytraceprocessor/storage_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions processor/groupbytraceprocessor/storage_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}))

Expand All @@ -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)
}

Expand Down

0 comments on commit a1e5229

Please sign in to comment.