Search code examples
spring-bootspring-cloudspring-cloud-sleuth

SpanID and TraceID missing in Spring Boot logs


For example, before including Spring Cloud Sleuth, people get something like this in their logs

2016-02-11 17:12:45.404  INFO [my-service-id,,] 85184 --- [nio-8080-exec-1] com.example.MySimpleComponentMakingARequest 

with the 2 commas (which is where the traceID and spanID would show up) near the application name. But my logs initially looked like this

2016-02-11 17:12:45.404  INFO 85184 --- [nio-8080-exec-1] com.example.MySimpleComponentMakingARequest 

In order to get the application name on my logs, I wrote the following code in application.properties

logging.pattern.level= %5p [${spring.application.name}] 

and now my logs look like this (if you observe, it does not have the 2 commas next to the application name)

2016-02-11 17:12:45.404  INFO [my-service-id] 85184 --- [nio-8080-exec-1] com.example.MySimpleComponentMakingARequest

and even after including Sleuth, my logs look this way and the SpanID and TraceID aren't present. I am new to Spring Boot, please help me out by telling me what I am doing wrong.


Solution

  • Sleuth uses logging.pattern.level to inject these details. Since you overwrite it, the details that Sleuth would put in there are not there.

    If you don't set the property you should see this without Sleuth:

    2016-02-11 17:12:45.404  INFO 85184 --- [nio-8080-exec-1] ...
    

    And if you include Sleuth:

    2016-02-11 17:12:45.404  INFO [my-service-id,,] 85184 --- [nio-8080-exec-1] ...
    

    If this is not the behavior you experience, check your classpath, and make sure Sleuth is there/not there and you are using the right version.

    See this answer for what is going on in the background: How spring cloud sleuth adds tracing information to logback log lines