Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service name must not be null or empty #73

Open
ahmedbaberkhan opened this issue Jan 30, 2020 · 24 comments
Open

Service name must not be null or empty #73

ahmedbaberkhan opened this issue Jan 30, 2020 · 24 comments

Comments

@ahmedbaberkhan
Copy link

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.

@geoand
Copy link
Collaborator

geoand commented Jan 30, 2020

Makes sense. Would you like to contribute this enhancement?

@ahmedbaberkhan
Copy link
Author

ahmedbaberkhan commented Jan 31, 2020

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)

@tomicarsk6
Copy link

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

@aveiros
Copy link

aveiros commented Feb 28, 2020

Just ran into the same issue myself.

@geoand
Copy link
Collaborator

geoand commented Mar 2, 2020

Which version stills exhibits the problem?

@aveiros
Copy link

aveiros commented Mar 2, 2020

@geoand using version 2.0.3

@geoand
Copy link
Collaborator

geoand commented Mar 2, 2020

Thanks,

Do you have a small reproducer perhaps?

@aveiros
Copy link

aveiros commented Mar 2, 2020

@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

@geoand
Copy link
Collaborator

geoand commented Mar 2, 2020

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

@aveiros
Copy link

aveiros commented Mar 2, 2020

I will come back to you later in the day.

@aveiros
Copy link

aveiros commented Mar 3, 2020

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

@geoand
Copy link
Collaborator

geoand commented Mar 4, 2020

Thanks! I'll check it out soon

@geoand
Copy link
Collaborator

geoand commented Mar 4, 2020

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?

@pavolloffay
Copy link
Contributor

@geoand
Copy link
Collaborator

geoand commented Mar 4, 2020

OK thanks.

We might need to reexamine this

@olivierboudet
Copy link

olivierboudet commented Aug 18, 2020

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

@Marx2
Copy link

Marx2 commented Jan 19, 2021

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

@dreis2211
Copy link

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.

@tbeauvais-imagine
Copy link

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?

@CostaVita
Copy link

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

@ivangreene
Copy link

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
Copy link

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

@danibs
Copy link

danibs commented Jun 17, 2022

@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 #73 (comment) 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" );
	}
}

@jacsmedvedev
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests