Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jaeger with Spring Boot

Tags:

trace

jaeger

In a spring boot application (just one at the moment) I included jaeger by adding dependency opentracing-spring-jaeger-web-starter and the below beans

@Bean
public static JaegerTracer getTracer() {
    io.jaegertracing.Configuration.SamplerConfiguration samplerConfig =
            io.jaegertracing.Configuration.SamplerConfiguration.fromEnv().withType("const").withParam(1);
    io.jaegertracing.Configuration.ReporterConfiguration reporterConfig =
            io.jaegertracing.Configuration.ReporterConfiguration.fromEnv().withLogSpans(true);
    io.jaegertracing.Configuration config = new io.jaegertracing.Configuration("fooService").withSampler(samplerConfig).withReporter(reporterConfig);
    return config.getTracer();
}

@PostConstruct
public void setProperty() {
    System.setProperty("JAEGER_REPORTER_LOG_SPANS", "true");
}

After starting Jaeger in docker docker run -d --name jaeger -p 16686:16686 -p 6831:6831/udp jaegertracing/all-in-one:1.9 I get the traces.

I found now another dependency and read different tutorials which made me somehow unsure on what is the right way to use Jaeger with spring boot.

Which dependency would I use?

https://github.com/opentracing-contrib/java-spring-cloud

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-spring-cloud-starter</artifactId>
</dependency>

https://github.com/signalfx/tracing-examples/tree/master/jaeger-java-spring-boot-web

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-spring-jaeger-web-starter</artifactId>
</dependency>

Following the Jaeger documentation possibly

<dependency>
    <groupId>io.jaegertracing</groupId>
    <artifactId>jaeger-client</artifactId>
    <version>$jaegerVersion</version>
</dependency>

would be enough!?

Before trying Jaeger I used Zipkin which is very easy to integrate in Spring since there is a starter for sleuth. The logs contain trace and span id's in separate fields so they can be searched for e.g. in Kibana. Jaeger does not.

Can that be customized and if so - how?

Is it possibly to use Jaeger with Brave for instrumentation. The project e.g. includes spring-cloud-starter-sleuth as a dependency. There are some conflicts with already existing beans. Can Jaeger be used with brave at all?

like image 336
Kavau Avatar asked Oct 15 '22 01:10

Kavau


2 Answers

Answering to your question about dependencies it is explained here in Dependencies section (https://github.com/opentracing-contrib/java-spring-jaeger):

The opentracing-spring-jaeger-web-starter starter is convenience starter that includes both opentracing-spring-jaeger-starter and opentracing-spring-web-starter This means that by including it, simple web Spring Boot microservices include all the necessary dependencies to instrument Web requests / responses and send traces to Jaeger.

The opentracing-spring-jaeger-cloud-starter starter is convenience starter that includes both opentracing-spring-jaeger-starter and opentracing-spring-cloud-starter This means that by including it, all parts of the Spring Cloud stack supported by Opentracing will be instrumented

And by the way:

  • opentracing.jaeger.log-spans is true by default

same as:

  • opentracing.jaeger.udp-sender.host=localhost
  • opentracing.jaeger.udp-sender.port=6831
  • opentracing.jaeger.const-sampler.decision=true
  • opentracing.jaeger.enabled=true
like image 154
lefti696 Avatar answered Oct 21 '22 03:10

lefti696


This link (https://objectpartners.com/2019/04/25/distributed-tracing-with-apache-kafka-and-jaeger/) provides the details of how to enable jaeger traces.

The simplest way to enable jaeger to spring-boot application is add the dependency and the required properties.


Dependency:

<dependency>
   <groupId>io.opentracing.contrib</groupId>
   <artifactId>opentracing-spring-jaeger-web-starter</artifactId>
   <version>3.2.0</version>
</dependency>

Example Properties

opentracing.jaeger.udp-sender.host=localhost
opentracing.jaeger.udp-sender.port=6831
opentracing.jaeger.const-sampler.decision=true
opentracing.jaeger.enabled=true
opentracing.jaeger.log-spans=true
opentracing.jaeger.service-name=ms-name
like image 30
Venkata Madhu Avatar answered Oct 21 '22 05:10

Venkata Madhu