Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard ArrayList size rather than max number of links for initial span links allocation #6252

Merged
merged 4 commits into from May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -468,7 +468,7 @@ public Span addLink(SpanContext spanContext, Attributes attributes) {
return this;
}
if (links == null) {
links = new ArrayList<>(spanLimits.getMaxNumberOfLinks());
links = new ArrayList<>();
}
if (links.size() < spanLimits.getMaxNumberOfLinks()) {
links.add(link);
Expand Down
Expand Up @@ -15,6 +15,7 @@
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -911,6 +912,46 @@ void addLink() {
}
}

@Test
void addLink_InvalidArgs() {
SdkSpan span = createTestSpan(SpanKind.INTERNAL);
assertThatCode(() -> span.addLink(null)).doesNotThrowAnyException();
assertThatCode(() -> span.addLink(SpanContext.getInvalid())).doesNotThrowAnyException();
assertThatCode(() -> span.addLink(null, null)).doesNotThrowAnyException();
assertThatCode(() -> span.addLink(SpanContext.getInvalid(), Attributes.empty()))
.doesNotThrowAnyException();
}

@Test
void addLink_FaultIn() {
SdkSpan span =
SdkSpan.startSpan(
spanContext,
SPAN_NAME,
instrumentationScopeInfo,
SpanKind.INTERNAL,
Span.getInvalid(),
Context.root(),
SpanLimits.getDefault(),
spanProcessor,
testClock,
resource,
null,
null, // exercises the fault-in path
0,
0);
SdkSpan linkedSpan = createTestSpan(SpanKind.INTERNAL);
span.addLink(linkedSpan.getSpanContext());

SpanData spanData = span.toSpanData();
assertThat(spanData.getTotalRecordedLinks()).isEqualTo(1);
assertThat(spanData.getLinks())
.satisfiesExactly(
link -> {
assertThat(link.getSpanContext()).isEqualTo(linkedSpan.getSpanContext());
});
}

@Test
void droppingAttributes() {
int maxNumberOfAttributes = 8;
Expand Down