Search code examples
tracejaeger

Jaeger with Spring Boot


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?


Solution

  • 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