Don't copy events toSpanData if ended. (#2979)
This commit is contained in:
parent
5e2791703f
commit
64ed0415d2
|
|
@ -483,6 +483,12 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
||||||
return Collections.emptyList();
|
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));
|
return Collections.unmodifiableList(new ArrayList<>(events));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,17 @@ class RecordEventsReadableSpanTest {
|
||||||
.isInstanceOf(UnsupportedOperationException.class);
|
.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
|
@Test
|
||||||
void toSpanData_RootSpan() {
|
void toSpanData_RootSpan() {
|
||||||
RecordEventsReadableSpan span = createTestRootSpan();
|
RecordEventsReadableSpan span = createTestRootSpan();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue