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

NullPointerException when no local ip in Span #224

Closed rafal-dudek closed 3 weeks ago

rafal-dudek commented 1 month ago

Describe the Bug

When localIP is missing in Server braveSpan, it causes exception:

java.lang.NullPointerException: Cannot invoke "String.length()" because "ipString" is null
    at com.google.common.net.InetAddresses.ipStringToBytes(InetAddresses.java:185)
    at com.google.common.net.InetAddresses.forString(InetAddresses.java:151)
    at zipkin2.reporter.stackdriver.brave.AttributesExtractor.extract(AttributesExtractor.java:76)
    at zipkin2.reporter.stackdriver.brave.SpanTranslator.translate(SpanTranslator.java:80)
    at zipkin2.reporter.stackdriver.brave.StackdriverV2Encoder.translate(StackdriverV2Encoder.java:59)
    at zipkin2.reporter.stackdriver.brave.StackdriverV2Encoder.sizeInBytes(StackdriverV2Encoder.java:31)
    at zipkin2.reporter.stackdriver.brave.StackdriverV2Encoder.sizeInBytes(StackdriverV2Encoder.java:15)
    at zipkin2.reporter.internal.CountBoundedQueue.doDrain(CountBoundedQueue.java:115)
    at zipkin2.reporter.internal.CountBoundedQueue.drainTo(CountBoundedQueue.java:83)
    at zipkin2.reporter.internal.AsyncReporter$BoundedAsyncReporter.flush(AsyncReporter.java:241)
    at zipkin2.reporter.internal.AsyncReporter$Flusher.run(AsyncReporter.java:352)
    at java.base/java.lang.Thread.run(Thread.java:1583)

Steps to Reproduce

Make sure that your Server Span is missing local IP address. Not sure how to reproduce it exactly - the problem occurs in our Integration tests only in Jenkins Agent on Kubernetes, locally the IP address is present. In our case it is for Spring Boot 3.3.2 MVC RestController span.

Expected Behaviour

There should be check if braveSpan.localIp()!=null before invoking InetAddresses.forString(String ipString) on it: https://github.com/openzipkin/zipkin-gcp/blob/master/encoder-stackdriver-brave/src/main/java/zipkin2/reporter/stackdriver/brave/AttributesExtractor.java#L76

If localIP is null, do not set any attribute for it.

sann3 commented 1 month ago

We are also facing this issue Spring boot - 3.3.2 com.google.cloud:spring-cloud-gcp-dependencies - 5.5.0 org.springframework.cloud:spring-cloud-dependencies - 2023.0.3

shakuzen commented 1 month ago

Anyone up for making a pull request to fix this and add tests for it? Looks like the AttributesExtractor used by the other encoder has null checks for IP: https://github.com/openzipkin/zipkin-gcp/blob/829844a2b12b17d49ffc3010d0020eb4bf3bba1d/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java#L64-L71

hjed commented 3 weeks ago

We get this problem when running spring on cloud run

shakuzen commented 3 weeks ago

Would folks affected by this be able to test with snapshots to confirm there aren't any remaining issues with the fix now merged?

hjed commented 3 weeks ago

We've tested with Os's PR and it fixes the issue for us, thanks

ccudennec-otto commented 2 weeks ago

oh, that's great to hear! 🥳 how is your release schedule? when can we expect the fix to be released?

shakuzen commented 1 week ago

Releases for this repo are ad hoc. I'll try to find time to do a release this week.

shakuzen commented 1 week ago

With #226 merged, I think we have everything ready for the release. If anyone would like to try out snapshots before the release to make sure everything is good, that'd be appreciated.

joaotab commented 5 days ago

I tried the 2.2.5-SNAPSHOT and it worked for our deployment

shakuzen commented 5 days ago

2.2.5 is released now with this fix.