java-spring-jaeger
java-spring-jaeger copied to clipboard
Service name must not be null or empty
I want to disable jaeger span using opentracing-jaeger-enabled: false and no jaeger service name is defined. However I'm getting following error java.lang.IllegalArgumentException: Service name must not be null or empty.
The service name should be check if and only if the enabled flag is set to true.
Makes sense. Would you like to contribute this enhancement?
This issue seems to be fixed in https://github.com/opentracing-contrib/java-spring-tracer-configuration/blob/master/opentracing-spring-tracer-configuration-starter/src/main/java/io/opentracing/contrib/spring/tracer/configuration/TracerAutoConfiguration.java
@ConditionalOnProperty(value = "opentracing.jaeger.enabled", havingValue = "true", matchIfMissing = true)
As we don't need any Tracer if Jaeger tracing is disabled
The JaegerAutoConfiguration files have following annotation
@ConditionalOnProperty(value = "opentracing.jaeger.enabled", havingValue = "true", matchIfMissing = true) This will not create any bean of this class when opentracing.jaeger.enabled is set to false, and below annotation will create a bean of Tracer which will cause above issue
@AutoConfigureBefore(io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration.class)
So this is still not fixed, because I'm still having the same error.
Just ran into the same issue myself.
Which version stills exhibits the problem?
@geoand using version 2.0.3
Thanks,
Do you have a small reproducer perhaps?
@geoand so there's no misunderstanding, i'm not using the Custom Configuration Class.
Just using properties
opentracing:
jaeger:
enabled: false
udp-sender:
host: localhost
port: 6831
@aveiros thanks for the info. Do you have a complete sample application I can look at that has the properties you mention and shows the erroneous behavior?
I will come back to you later in the day.
sorry for the delay https://github.com/aveiros/jaeger-sample
Thanks! I'll check it out soon
The problem comes from the io.opentracing.contrib:opentracing-spring-tracer-configuration-starter module:
java.lang.IllegalArgumentException: Service name must not be null or empty
at io.jaegertracing.internal.JaegerTracer$Builder.checkValidServiceName(JaegerTracer.java:662) ~[jaeger-core-0.35.1.jar:0.35.1]
at io.jaegertracing.Configuration.<init>(Configuration.java:188) ~[jaeger-core-0.35.1.jar:0.35.1]
at io.jaegertracing.Configuration.fromEnv(Configuration.java:200) ~[jaeger-core-0.35.1.jar:0.35.1]
at io.jaegertracing.Configuration.fromEnv(Configuration.java:196) ~[jaeger-core-0.35.1.jar:0.35.1]
at io.jaegertracing.tracerresolver.internal.JaegerTracerFactory.getTracer(JaegerTracerFactory.java:24) ~[jaeger-tracerresolver-0.35.1.jar:0.35.1]
at io.jaegertracing.tracerresolver.internal.JaegerTracerFactory.getTracer(JaegerTracerFactory.java:21) ~[jaeger-tracerresolver-0.35.1.jar:0.35.1]
at io.opentracing.contrib.tracerresolver.TracerResolver.getFromFactory(TracerResolver.java:153) [opentracing-tracerresolver-0.1.6.jar:na]
at io.opentracing.contrib.tracerresolver.TracerResolver.resolveTracer(TracerResolver.java:88) [opentracing-tracerresolver-0.1.6.jar:na]
at io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration.getTracer(TracerAutoConfiguration.java:53) [opentracing-spring-tracer-configuration-starter-0.2.0.jar:na]
at io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration$$EnhancerBySpringCGLIB$$c17c324e.CGLIB$getTracer$0(<generated>) [opentracing-spring-tracer-configuration-starter-0.2.0.jar:na]
at io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration$$EnhancerBySpringCGLIB$$c17c324e$$FastClassBySpringCGLIB$$6f1a0274.invoke(<generated>) [opentracing-spring-tracer-configuration-starter-0.2.0.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) [spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) [spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration$$EnhancerBySpringCGLIB$$c17c324e.getTracer(<generated>) [opentracing-spring-tracer-configuration-starter-0.2.0.jar:na]
@pavolloffay remind me again please why we need that module?
IIRC it provides a tracer resolution mechanism https://github.com/opentracing-contrib/java-spring-tracer-configuration#opentracing-spring-tracer-configuration
OK thanks.
We might need to reexamine this
This error appears even if the service name is defined. I encounter it with the following configuration
opentracing:
jaeger:
enabled: false
enable-b3-propagation: true
http-sender:
url: http://127.0.0.1:14268/api/traces
log-spans: false
probabilistic-sampler:
sampling-rate: 0.1
service-name: myapp
Fix is described on main page: https://github.com/opentracing-contrib/java-spring-jaeger in the section "Completely disable tracing"
I noticed that for us this is caused by ReactorTracingAutoConfiguration in the opentracing-spring-cloud-reactor-starter.
The mentioned auto-configuration registers hooks for some of the reactor parts. Unfortunately, under certain circumstances the hooks there get triggered before the Tracer bean or any of its dependencies like JaegerConfigurationProperties are available. While the implementation wants to account for that by catching any BeansException, this leaves the JaegerConfigurationProperties unpropagated but already registered in the BeanFactory. Ultimately, this causes errors when JaegerAutoConfiguration tries to initialize the Tracer instance again. This also explains why neither opentracing.jaeger.service.name nor spring.application.name nor any of the other fallbacks work.
Personally, I just disabled the particular auto-configuration by specifying opentracing.spring.cloud.reactor.enabled=false. Maybe this helps some of you.
Fix is described on main page: https://github.com/opentracing-contrib/java-spring-jaeger in the section "Completely disable tracing"
This doesn't work and results in the error described above. How are we able to simply diable Jaeger locally?
So this is still not fixed, I'm still having the same error with service-name
Since this factory is trying to pull the service name from a system property, as an immediate workaround until this bug is resolved, this exception can be suppressed by setting the system property JAEGER_SERVICE_NAME to a non empty string, e.g -DJAEGER_SERVICE_NAME=a-service-name on the command line, or:
static {
System.setProperty(io.jaegertracing.Configuration.JAEGER_SERVICE_NAME, "a-service-name");
}
Another solution which may be better since it uses an actual no-op tracer instead of attempting to report traces using the default config values:
import io.opentracing.Tracer;
import io.opentracing.noop.NoopTracerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class NoOpTracerBean {
@Bean
@ConditionalOnProperty(value = "opentracing.jaeger.enabled", havingValue = "false")
public Tracer getTracer() {
return NoopTracerFactory.create();
}
}
@Configuration public class NoOpTracerBean { @Bean @ConditionalOnProperty(value = "opentracing.jaeger.enabled", havingValue = "false") public Tracer getTracer() { return NoopTracerFactory.create(); } }
Nope! Your solution is the same in the homepage (https://github.com/opentracing-contrib/java-spring-jaeger#completely-disable-tracing) but it doesn't work.
The bean 'getTracer', defined in class path resource [com/.../DisableJaegerConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [io/opentracing/contrib/spring/tracer/configuration/TracerAutoConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
We then renamed method from getTracer to jaegerTracer and then:
Parameter 0 of method tracingFilter in io.opentracing.contrib.spring.web.starter.ServerTracingAutoConfiguration required a single bean, but 2 were found:
- getTracer: defined by method 'getTracer' in class path resource [io/opentracing/contrib/spring/tracer/configuration/TracerAutoConfiguration.class]
- jaegerTracer: defined by method 'jaegerTracer' in class path resource [com/.../DisableJaegerConfiguration.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
We finally added @Primarybut we obtained the exception already described:
java.lang.IllegalArgumentException: Service name must not be null or empty
at io.jaegertracing.internal.JaegerTracer$Builder.checkValidServiceName(JaegerTracer.java:712)
The workaround https://github.com/opentracing-contrib/java-spring-jaeger/issues/73#issuecomment-1136057110 posted by @ivangreene works. This is our class:
@Configuration
@ConditionalOnProperty( value = "opentracing.jaeger.enabled", havingValue = "false", matchIfMissing = false )
@Slf4j
public class DisableJaegerConfiguration {
static {
log.info( "Init NoopTracer" );
System.setProperty( io.jaegertracing.Configuration.JAEGER_SERVICE_NAME, "a-service-name" );
}
}
The simplest way for me (local app run) was to add env var JAEGER_SERVICE_NAME=myApp to IDE Run/Debug Configurations to Spring Boot app. After that exceptions during app startup gone.