opentracing-contrib / java-spring-jaeger

Apache License 2.0
256 stars 95 forks source link

When I configure a host that cannot be resolved, the whole application will fail. #68

Closed LeBW closed 4 years ago

LeBW commented 4 years ago

I develop an application with K8s and I want to add Jaeger to it. I set the opentracing.jaeger.udp-sender.host to jaeger because I created a backend service named jaeger, and the application works normally. But I want to leave the backend service to users rather than start it by default. And then I found that when there is no backend service, the application will fail because it can't resolve the address jaeger. The error is like this:

Caused by: java.lang.RuntimeException: TUDPTransport cannot connect:
        at io.jaegertracing.thrift.internal.reporters.protocols.ThriftUdpTransport.newThriftUdpClient(ThriftUdpTransport.java:50) ~[jaeger-thrift-0.30.6.jar!/:na]
        at io.jaegertracing.thrift.internal.senders.UdpSender.<init>(UdpSender.java:57) ~[jaeger-thrift-0.30.6.jar!/:na]
        at io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration.getUdpReporter(JaegerAutoConfiguration.java:113) ~[opentracing-spring-jaeger-starter-0.2.2.jar!/:na]
        at io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration.reporter(JaegerAutoConfiguration.java:93) ~[opentracing-spring-jaeger-starter-0.2.2.jar!/:na]
        at io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration$$EnhancerBySpringCGLIB$$f8d9da63.CGLIB$reporter$4(<generated>) ~[opentracing-spring-jaeger-starter-0.2.2.jar!/:na]
        at io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration$$EnhancerBySpringCGLIB$$f8d9da63$$FastClassBySpringCGLIB$$7aaf2db8.invoke(<generated>) ~[opentracing-spring-jaeger-starter-0.2.2.jar!/:na]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.25.RELEASE.jar!/:4.3.25.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.25.RELEASE.jar!/:4.3.25.RELEASE]
        at io.opentracing.contrib.java.spring.jaeger.starter.JaegerAutoConfiguration$$EnhancerBySpringCGLIB$$f8d9da63.reporter(<generated>) ~[opentracing-spring-jaeger-starter-0.2.2.jar!/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.25.RELEASE.jar!/:4.3.25.RELEASE]
        ... 54 common frames omitted
Caused by: java.net.SocketException: Unresolved address
        at java.net.DatagramSocket.connect(DatagramSocket.java:493) ~[na:1.8.0_111]
        at io.jaegertracing.thrift.internal.reporters.protocols.ThriftUdpTransport.newThriftUdpClient(ThriftUdpTransport.java:48) ~[jaeger-thrift-0.30.6.jar!/:na]
        ... 67 common frames omitted

My goal is that the application can run normally whether there is a backend service or not. How can I reach that? Thank you.

geoand commented 4 years ago

Hi,

I would suggest using opentracing.jaeger.enabled=false when you know backend won't be available

LeBW commented 4 years ago

Hi,

I would suggest using opentracing.jaeger.enabled=false when you know backend won't be available

Yes but the code needs to be modified in this way and it’s not friendly to users. And we need to do it for every microservice( we have more than 40 microservices in the application) and it’s a little inconvenient.

In fact I noticed that under the default configuration( the host is ‘localhost’), it works well whether there is a backend or not. Is it possible to behave like this when the host is not ‘localhost’?

geoand commented 4 years ago

I might be missing something, but with what I proposed above you don't need to change anything in the code. You can just set the property in any way Spring Boot allows without making any code changes

LeBW commented 4 years ago

I might be missing something, but with what I proposed above you don't need to change anything in the code. You can just set the property in any way Spring Boot allows without making any code changes

Thank you. I finally noticed that I can set environment variable to set the host. And I use ConfigMap to achieve the goal finally.

geoand commented 4 years ago

Cool