Open-tracing integration with spring-cloud-starter-netflix-eureka-serve
mayankvaid88 opened this issue · 17 comments
I am trying to setup open-tracing with spring eureka server.
POM.xml
ApplicationRunner
@SpringBootApplication
@EnableEurekaServer
public class ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(ApplicationRunner.class);
}
@Bean
public JaegerTracer getTracer(){
Configuration.SamplerConfiguration samplerConfiguration = new Configuration.SamplerConfiguration();
samplerConfiguration.withType(ConstSampler.TYPE);
samplerConfiguration.withParam(1);
Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration();
senderConfiguration.withAgentHost("XXX.XXX.XX.X").withAgentPort(XYZ);
Configuration.ReporterConfiguration reporterConfiguration = new Configuration.ReporterConfiguration();
reporterConfiguration.withSender(senderConfiguration);
return new Configuration("ebs-eureka-server").withSampler(samplerConfiguration).withReporter(reporterConfiguration).getTracer();
}
}
Error Log
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.web.servlet.resource.ResourceHttpRequestHandler.afterPropertiesSet(ResourceHttpRequestHandler.java:378)
The following method did not exist:
'java.util.Map org.springframework.web.accept.ContentNegotiationManager.getMediaTypeMappings()'
The method's class, org.springframework.web.accept.ContentNegotiationManager, is available from the following locations:
jar:file:/Users/in-mayank.vaid/.m2/repository/org/springframework/spring-web/5.2.0.RELEASE/spring-web-5.2.0.RELEASE.jar!/org/springframework/web/accept/ContentNegotiationManager.class
It was loaded from the following location:
file:/Users/in-mayank.vaid/.m2/repository/org/springframework/spring-web/5.2.0.RELEASE/spring-web-5.2.0.RELEASE.jar
Is the error related to OpenTracing? I don't see OpenTracing libraries logged in the error.
No so this particular error seems to be because of class path messed up. However, I wanted to understand if opentracing-spring-cloud-starter supports spring cloud eureka server (spring-cloud-starter-netflix-eureka-server) and can be integrated.
The support for eureka is not listed in the readme. If the eureka is bases on the standard HTTP components that are supported by this library then it might work. You could test it and report back.
I am not sure if I can answer on whether eureka is based on the standard HTTP components. However, I can confirm that I am having class path issues like I reported above when including opentracing-spring-cloud-starter with spring-cloud-starter-netflix-eureka-server.
@geoand any idea why it is failing?
Maybe bc the ot-jaeger uses SB 2.1 and not 2.2? https://github.com/opentracing-contrib/java-spring-jaeger/blob/master/pom.xml#L68
@mayankvaid88 could you please try to remove the jaeger-cloud-starter
artifact?
hi ... I tried removing jaeger-cloud-starter but issue is still same. But when I remove opentracing-spring-cloud-starter application loads successfully...
seems like issue is with version incompatibility. Adding opentracing-spring-cloud-starter
enforces application to use ContentNegotiationManager
from org.springframework:spring-web:5.2.0.RELEASE2
. When I remove this jar, same class is being used from org.springframework:spring-webmvc:5.2.6.RELEASE2
The cloud instrumentation uses opentracing-spring-web which seems to use the right dependency spring-webmvc
https://github.com/opentracing-contrib/java-spring-web/blob/master/opentracing-spring-web/pom.xml#L39.
Try to exclude opentracing-spring-cloud-gateway-starter
It is pulling in spring-web
https://github.com/opentracing-contrib/java-spring-cloud/blob/master/instrument-starters/opentracing-spring-cloud-gateway-starter/pom.xml#L40
Thank you @pavolloffay .. excluding opentracing-spring-cloud-gateway-starter
worked !!!
@mayankvaid88 would you like to submit a PR to fix this issue? Perhaps the gateway starter could depend on the spring-webmvc
instead of spring-web
.
sure. I will raise the PR @pavolloffay
@pavolloffay pull request has been created. Please review and merge if looks okay
#298 solves the issue
The solution isn't quite as simple as adding spring-webmvc
to the cloud-gateway starter. Spring Cloud Gateway is a webflux app and will complain when DispatcherServlet
is on the classpath - and it's brought in by spring-webmvc
. Basically, Spring Coud Gateway is fundamentally incompatible with Spring Cloud Netflix Eureka Server, and they aren't likely to end up in the same app together.
This seems like a general risk: different Spring subprojects may have incompatible dependencies. Having opentracing-spring-cloud-starter
import everything is going to cause problems eventually.
I think there are two solutions - possibly both:
- Deprecate
opentracing-spring-cloud-starter
- it's distinctly unlikely that someone will need every instrumentation library. So follow the standardspring-boot-*-starter
approach - the user imports just the ones for the instrumentations they need. This needs to be carried through to e.g.opentracing-spring-cloud-jaeger-starter
to avoid pulling in the unnecessary instrumentation libs. - Go through each starter and mark the transitive dependencies as
provided
, or excluded, in the same manner asopentracing-spring-cloud-mongo-starter
(andopentracing-mongo-common
). I'd still end up with extra unnecessary opentracing libraries on my classpath, but at least I wouldn't have their dependencies causing problems with my own.
But as it stands right now I think 298 needs to be reverted, as it's breaking the instrumentation of Spring Cloud Gateway.
We were enforcing 2) however the core web packages might have been declared as compile scope. Instead of provided we have been using optional IIRC.
If you could have a look and submit a PR that would be awesome