Skip to content

Commit

Permalink
Make serviceName check null-safe (#149)
Browse files Browse the repository at this point in the history
Span object stores `localEndpoint.serviceName` empty string as null so `.isEmpty()` throws NullPointerException.
  • Loading branch information
z-oo authored and adriancole committed Sep 16, 2019
1 parent 4688ae7 commit c6dadd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit c6dadd6

Please sign in to comment.