diff --git a/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java b/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java index e7a795b9..5edbbd0d 100644 --- a/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java +++ b/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java @@ -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())); } diff --git a/translation-stackdriver/src/test/java/zipkin2/translation/stackdriver/AttributesExtractorTest.java b/translation-stackdriver/src/test/java/zipkin2/translation/stackdriver/AttributesExtractorTest.java index 66aa9fa7..49844c3b 100644 --- a/translation-stackdriver/src/test/java/zipkin2/translation/stackdriver/AttributesExtractorTest.java +++ b/translation-stackdriver/src/test/java/zipkin2/translation/stackdriver/AttributesExtractorTest.java @@ -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 serverLabels = extractor.extract(serverSpan).getAttributeMapMap(); + assertThat(serverLabels).doesNotContainKey("endpoint.serviceName"); + } + @Test public void testComponentLabelIsSet() { AttributesExtractor extractor = new AttributesExtractor(Collections.emptyMap());