openzipkin / zipkin-gcp

Reporters and collectors for use in Google Cloud Platform
https://cloud.google.com/trace/docs/zipkin
Apache License 2.0
91 stars 54 forks source link

Span without service name causes NullPointerException #148

Open z-oo opened 5 years ago

z-oo commented 5 years ago

Example:

curl -X POST -s localhost:9411/api/v2/spans -H'Content-Type: application/json' -d '[{"traceId":"fe1583ed5be1b96cf40538f958ca97a6","id":"96169d26c53f25ab","name":"loader::unload","timestamp":1568360755828060,"duration":124,"localEndpoint":{"ipv6":"::1"}}]'

result in

java.lang.NullPointerException: null
    at zipkin2.translation.stackdriver.AttributesExtractor.extract(AttributesExtractor.java:83) ~[zipkin-translation-stackdriver-0.14.1-SNAPSHOT.jar!/:?]
    at zipkin2.translation.stackdriver.SpanTranslator.translate(SpanTranslator.java:112) ~[zipkin-translation-stackdriver-0.14.1-SNAPSHOT.jar!/:?]
    at zipkin2.translation.stackdriver.SpanTranslator.translate(SpanTranslator.java:60) ~[zipkin-translation-stackdriver-0.14.1-SNAPSHOT.jar!/:?]
    at zipkin2.storage.stackdriver.StackdriverSpanConsumer.accept(StackdriverSpanConsumer.java:51) ~[zipkin-storage-stackdriver-0.14.1-SNAPSHOT.jar!/:?]
    at zipkin2.collector.Collector.store(Collector.java:200) ~[zipkin-collector-2.16.3-SNAPSHOT.jar!/:?]
    at zipkin2.collector.Collector$StoreSpans.run(Collector.java:229) ~[zipkin-collector-2.16.3-SNAPSHOT.jar!/:?]
    at com.linecorp.armeria.common.AbstractRequestContext.lambda$makeContextAware$1(AbstractRequestContext.java:69) ~[armeria-0.91.0.jar!/:?]
    at com.linecorp.armeria.common.AbstractRequestContext.lambda$makeContextAware$1(AbstractRequestContext.java:69) ~[armeria-0.91.0.jar!/:?]
    at io.micrometer.core.instrument.AbstractTimer.record(AbstractTimer.java:160) ~[micrometer-core-1.2.1.jar!/:1.2.1]
    at io.micrometer.core.instrument.Timer.lambda$wrap$0(Timer.java:144) ~[micrometer-core-1.2.1.jar!/:1.2.1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.39.Final.jar!/:4.1.39.Final]
    at java.lang.Thread.run(Thread.java:834) [?:?]

while

curl -X POST -s localhost:9411/api/v2/spans -H'Content-Type: application/json' -d '[{"traceId":"fe1583ed5be1b96cf40538f958ca97a6","id":"96169d26c53f25ab","name":"loader::unload","timestamp":1568360755828060,"duration":124,"localEndpoint":{"ipv6":"::1", "serviceName":"test"}}]'

works fine.

z-oo commented 5 years ago

And it is caused by isEmpty() check that is not null-safe: https://github.com/openzipkin/zipkin-gcp/blob/master/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java#L83

if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) {

codefromthecrypt commented 5 years ago

makes sense. I guess census is allowing you to create an exporter without a service name. This is a bug over there, but still, we should guard here also.