title: Problem with Jaeger, logback and Sleuth working together
body: <p>I was developing a Spring Boot application in which the loging is done by logback and Jaeger is integrated for instrumentation.</p>
  
  <p>Myservice.java</p>
  
  <pre><code>@SpringBootApplication
  public class Myservice{
  
  
  public static void main(String[] args) {
      SpringApplication.run(Myservice.class, args);
  }
  
  @Bean
  public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
      return restTemplateBuilder.build();
  }
  
   @Bean
    public io.opentracing.Tracer jaegerTracer() {
      Builder builder = new Builder("Myservice",
          new RemoteReporter(new HttpSender(http://192.168.1.20:14268/api/traces), 10,
          65000, new Metrics(new StatsFactoryImpl(new NullStatsReporter()))),
          new ConstSampler(true))
          .registerInjector(Builtin.HTTP_HEADERS, new B3TextMapCodec())
          .registerExtractor(Builtin.HTTP_HEADERS, new B3TextMapCodec());
      return builder.build();
    }
  }
  </code></pre>
  
  <p>logback.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration &gt;
   &lt;include resource="org/springframework/boot/logging/logback/defaults.xml"/&gt;
  &lt;springProperty scope="context" name="springAppName"
      source="spring.application.name" /&gt;
  &lt;appender name="consoleAppender" 
  class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;filter class="ch.qos.logback.classic.filter.ThresholdFilter"&gt;
              Minimum logging level to be presented in the console logs
              &lt;level&gt;INFO&lt;/level&gt;
          &lt;/filter&gt;
      &lt;encoder 
  class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"&gt;
          &lt;providers&gt;
              &lt;pattern&gt;
                  &lt;pattern&gt;
                      {
                      "service": "${springAppName:-}",
                      "trace": "%X{X-B3-TraceId:-}",
                      "span": "%X{X-B3-SpanId:-}"
                      }
                  &lt;/pattern&gt;
              &lt;/pattern&gt;
           &lt;/providers&gt;
      &lt;/encoder&gt;
  &lt;/appender&gt;
  
  &lt;root level="INFO"&gt;
      &lt;appender-ref ref="consoleAppender" /&gt;
  &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;2.0.4.RELEASE&lt;/version&gt;
      &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.projectreactor&lt;/groupId&gt;
          &lt;artifactId&gt;reactor-core&lt;/artifactId&gt;
          &lt;version&gt;3.1.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
          &lt;artifactId&gt;lombok&lt;/artifactId&gt;
          &lt;optional&gt;true&lt;/optional&gt;
      &lt;/dependency&gt;
  
      &lt;!-- JPA Data Dependency --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Oracle driver Dependency --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;
          &lt;version&gt;11.2.0.3&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Opentracing with Jaeger Dependency --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;io.opentracing&lt;/groupId&gt;
          &lt;artifactId&gt;opentracing-api&lt;/artifactId&gt;
          &lt;version&gt;0.31.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.opentracing.contrib&lt;/groupId&gt;
          &lt;artifactId&gt;opentracing-spring-cloud-starter&lt;/artifactId&gt;
          &lt;version&gt;0.1.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.uber.jaeger&lt;/groupId&gt;
          &lt;artifactId&gt;jaeger-core&lt;/artifactId&gt;
          &lt;version&gt;0.24.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.uber.jaeger&lt;/groupId&gt;
          &lt;artifactId&gt;jaeger-b3&lt;/artifactId&gt;
          &lt;version&gt;0.24.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Logback Dependency --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
          &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
          &lt;version&gt;1.2.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;net.logstash.logback&lt;/groupId&gt;
          &lt;artifactId&gt;logstash-logback-encoder&lt;/artifactId&gt;
          &lt;version&gt;4.10&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>The Jeager is properly connected to server and its getting the traces. The problem is with the logback logs. The traceId and spanId are not getting printed in the logs.</p>
  
  <pre><code>{"service" : "Myservice", "trace": "", "span":""}
  </code></pre>
  
  <p>But I myself found a solution for that. I added Spring Cloud Sleuth with my Spring Boot application.</p>
  
  <pre><code>    &lt;!-- spring-cloud-sleuth dependency --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
          &lt;version&gt;Camden.SR1&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
          &lt;scope&gt;import&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;spring-cloud-starter-sleuth&lt;/artifactId&gt;
          &lt;version&gt;2.0.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Now all the trace information was available in the logback log. But the problem is that Jaeger stopped registering traces to Jaeger server.</p>
  
  <p>I tried Zipkin instead of Jaeger, but the same thing happened. What's wrong with my application? Is something wrong with the dependencies?</p>