I would like to configure Jaeger in my Spring application. Somehow I cannot find a proper way to do this. Almost all Spring-Jaeger-related documentation is for Spring Boot where most of the properties are auto configured. Here's my approach. Maven dependency:
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
<version>1.0.3</version>
</dependency>
Spring config for Jaeger:
@Configuration
public class JagerConfiguration {
@Bean
public io.opentracing.Tracer jaegerTracer() {
Map<String, String> tags = new HashMap<>();
tags.put(Constants.TRACER_HOSTNAME_TAG_KEY, "localhost");
CompositeReporter reporter = new CompositeReporter(new LoggingReporter(), remoteReporter());
return new Builder("myTestSpringApp")
.withSampler(new ConstSampler(true))
.withMetricsFactory(new InMemoryMetricsFactory())
.withReporter(remoteReporter())
.withTags(tags)
.build();
}
@Bean
public RemoteReporter remoteReporter() {
return new RemoteReporter.Builder().withSender(new UdpSender("localhost", 6831, 0)).build();
}
}
Jaeger is running locally in docker on port 6831.
docker run -d -p6831:6831/udp -p16686:16686 jaegertracing/all-in-one:latest
Once my application starts, I noticed that application slows down considerably, I assume that is because of metrics logged heavily to console by LoggingReporter.
However, My Spring app does not show up in Jaeger UI. In the beginning I would like to trace my REST endpoints. Can someone point me in the right direction why my app is missing from UI and how I configure Jaeger properly? Is there perhaps a sample project with Spring+Jaeger that does not rely on outdated Jaeger?
If anyone else would like to set up Jaeger in spring project, here's what I did:
Add dependencies to pom:
Set up you web.xml to register new tracing filter tracingFilter to intercept REST API:
Register jaeger tracer in spring mvc:
Set up the tracingFilter bean we described in web.xml:
Finally define jaeger tracer spring configuration:
I have got following gradle dependencies working,
Following tracer bean configuration,
And then the spans can be recorded as
Here is the working example you can refer https://github.com/krushnatkhawale/jaeger-with-spring-boot-web-app