Spring Boot 3 Request Tracing

Traditional Spring Cloud Sleuth[1] tracing is no longer applicable to Spring Boot 3. This article will introduce how to configure Micrometer to trace requests in Spring Boot 3.

After Spring Boot 3 is updated, Spring Cloud Sleuth indicates that it is no longer supported[1], it is need to be migrated to Micrometer.

Add Dependency

In order to trace requests in Spring Boot 3, we need to add the following dependency in build.gradle:

1
2
3
4
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
1
implementation "io.micrometer:micrometer-tracing-bridge-brave"

Configure Log Pattern

After Spring Boot 3.2, Spring Boot will automatically configure the log format. If the version is lower than 3.2, manual configuration is required.

Refer to the Spring Cloud Sleuth 3.1 Migration Guide, add the following configuration in application.properties:

1
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]

参考文献

  1. Spring Cloud Sleuth. spring-cloud. [2023-12-24]. (原始内容存档于2023-12-24)
  2. Spring Cloud Sleuth 3.1 Migration Guide. micrometer-metrics. 2023-09-07 [2023-12-24]. (原始内容存档于2023-12-24)

Spring Boot 3 Request Tracing
https://blog.zhanganzhi.com/en/2023/12/2e66e27724a7/
Author
Andy Zhang
Posted on
December 24, 2023
Licensed under