Skip to content

Commit

Permalink
Don't copy events toSpanData if ended. (#2979)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuraag Agrawal authored Mar 4, 2021
1 parent 5e27917 commit 64ed041
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ private List<EventData> getImmutableTimedEvents() {
return Collections.emptyList();
}

// if the span has ended, then the events are unmodifiable
// so we can return them directly and save copying all the data.
if (hasEnded) {
return Collections.unmodifiableList(events);
}

return Collections.unmodifiableList(new ArrayList<>(events));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ void toSpanData_immutableEvents() {
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
void toSpanData_immutableEvents_ended() {
RecordEventsReadableSpan span = createTestSpan(SpanKind.INTERNAL);
span.end();
SpanData spanData = span.toSpanData();

assertThatThrownBy(
() -> spanData.getEvents().add(EventData.create(1000, "test", Attributes.empty())))
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
void toSpanData_RootSpan() {
RecordEventsReadableSpan span = createTestRootSpan();
Expand Down

0 comments on commit 64ed041

Please sign in to comment.