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 2 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 @@ -462,7 +462,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 @@ -897,6 +897,36 @@ void addLink_InvalidArgs() {
.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);
ExtendedSpan 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