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

Make serviceName check null-safe #149

Merged
merged 2 commits into from
Sep 16, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ Attributes extract(Span zipkinSpan) {
}
}

if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) {
if (zipkinSpan.localEndpoint() != null &&
zipkinSpan.localEndpoint().serviceName() != null &&
!zipkinSpan.localEndpoint().serviceName().isEmpty()) {
attributes.putAttributeMap(
kComponentLabelKey, toAttributeValue(zipkinSpan.localEndpoint().serviceName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ public void testEndpointIsSetIpv6() {
assertThat(clientLabels).doesNotContainKeys("endpoint.ipv4", "endpoint.ipv6");
}

@Test
public void testEndpointWithNullServiceName() {
Endpoint.Builder serverEndpointBuilder = Endpoint.newBuilder().port(80);
Endpoint serverEndpoint = serverEndpointBuilder.build();
Span serverSpan =
Span.newBuilder()
.kind(Kind.SERVER)
.traceId("4")
.name("test-span")
.id("5")
.localEndpoint(serverEndpoint)
.build();

AttributesExtractor extractor = new AttributesExtractor(Collections.emptyMap());
Map<String, AttributeValue> serverLabels = extractor.extract(serverSpan).getAttributeMapMap();
assertThat(serverLabels).doesNotContainKey("endpoint.serviceName");
}

@Test
public void testComponentLabelIsSet() {
AttributesExtractor extractor = new AttributesExtractor(Collections.emptyMap());
Expand Down