java-spring-jaeger icon indicating copy to clipboard operation
java-spring-jaeger copied to clipboard

Service name must not be null or empty

Open ahmedbaberkhan opened this issue 5 years ago • 24 comments

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.

ahmedbaberkhan avatar Jan 30 '20 11:01 ahmedbaberkhan

Makes sense. Would you like to contribute this enhancement?

geoand avatar Jan 30 '20 11:01 geoand

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)

ahmedbaberkhan avatar Jan 31 '20 10:01 ahmedbaberkhan

So this is still not fixed, because I'm still having the same error.

tomicarsk6 avatar Feb 28 '20 16:02 tomicarsk6

Just ran into the same issue myself.

aveiros avatar Feb 28 '20 17:02 aveiros

Which version stills exhibits the problem?

geoand avatar Mar 02 '20 07:03 geoand

@geoand using version 2.0.3

aveiros avatar Mar 02 '20 07:03 aveiros

Thanks,

Do you have a small reproducer perhaps?

geoand avatar Mar 02 '20 07:03 geoand

@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 avatar Mar 02 '20 13:03 aveiros

@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?

geoand avatar Mar 02 '20 13:03 geoand

I will come back to you later in the day.

aveiros avatar Mar 02 '20 13:03 aveiros

sorry for the delay https://github.com/aveiros/jaeger-sample

aveiros avatar Mar 03 '20 21:03 aveiros

Thanks! I'll check it out soon

geoand avatar Mar 04 '20 06:03 geoand

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?

geoand avatar Mar 04 '20 11:03 geoand

IIRC it provides a tracer resolution mechanism https://github.com/opentracing-contrib/java-spring-tracer-configuration#opentracing-spring-tracer-configuration

pavolloffay avatar Mar 04 '20 11:03 pavolloffay

OK thanks.

We might need to reexamine this

geoand avatar Mar 04 '20 12:03 geoand

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

olivierboudet avatar Aug 18 '20 14:08 olivierboudet

Fix is described on main page: https://github.com/opentracing-contrib/java-spring-jaeger in the section "Completely disable tracing"

Marx2 avatar Jan 19 '21 10:01 Marx2

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.

dreis2211 avatar Feb 20 '21 12:02 dreis2211

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?

tbeauvais-imagine avatar Mar 09 '22 12:03 tbeauvais-imagine

So this is still not fixed, I'm still having the same error with service-name

CostaVita avatar Mar 16 '22 09:03 CostaVita

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");
}

ivangreene avatar May 24 '22 15:05 ivangreene

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();
    }
}

ivangreene avatar May 24 '22 21:05 ivangreene

@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" );
	}
}

danibs avatar Jun 17 '22 13:06 danibs

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.

jacsmedvedev avatar Oct 30 '22 17:10 jacsmedvedev