On certain errors we don't get traces/spans in log statements. This happens when using latest Spring Boot 3.3.4 with ObservationAutoConfiguration and the following dependencies (example repo here):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
And the following correlation pattern is configured in application.properties:
logging.pattern.correlation=[${spring.application.name:},%X{traceId:-},%X{spanId:-}]
When starting up the application and running this (invalid) request
curl -X PUT http://localhost:8080/test -H "Content-Type: application/x-www-form-urlencoded" --data " %@ "
...we see the following log entry without trace/span:
2024-10-08T13:08:15.510+02:00 ERROR 7602 --- [nio-8080-exec-4] [demo3,,] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
Note: logging the happy path works fine.
Comment From: bclozel
Thanks for the sample.
This logging happens in Tomcat, in the org.apache.catalina.core
package - this means this is logged outside of the tracing scope, after the observation Servlet filter.
If you're looking for a more comprehensive tracing solution that only applies to Tomcat, you can use a Tomcat Valve to instrument your application - see https://github.com/micrometer-metrics/micrometer/issues/3777 for more details on Micrometer support for this.