Migrate from Sleuth to Micrometer Tracing in Spring
Short introduction
Spring Cloud Sleuth is not being maintained anymore after version 3.x, which was the latest minor version. This also means that from Spring Boot 3.x and up, you cannot use Sleuth anymore in your applications. So what is the alternative?
What does Spring Cloud Sleuth offer?
Sleuth offers you the opportunity to see how your applications act between microservices, using either the traceId or spanId.
I have created a simple application that shows how Sleuth is used in practice, so you can get a better understanding of it. In the video I use slf4j, spring-cloud-starter-sleuth & spring-boot-starter-web. The link to the video is here.
What is Micrometer Tracing?
Micrometer Tracing is conceptually similar to Spring Sleuth. It generates a traceId and spanId for the user's request across your services and makes it possible to track the users behavior and also more easily detect errors in said services. The key difference is that tracing is built directly into Micrometer, eliminating the need for an additional library to maintain in your application. Here you only need to be sure to be up-to-date with the newest Micrometer version.
Tip: If you use Maven, regularly check for new Micrometer versions to stay ahead of potential vulnerabilities. You can find all available versions on Maven's repository site.
How to migrate your application to Micrometer Tracing
You might find yourself in the same situation I did when updating my application to Spring Boot 3. Sleuth was no longer maintained and I therefore needed to find a replacement. Luckily it wasn't so hard to find and Micrometer Tracing is very simple to implement, just like Sleuth was.
To migrate your application from Sleuth to Micrometer, start by updating your pom.xml file to include the Micrometer dependency. Additionally, update your Spring Boot version to at least 3 or higher.
Depending on which Spring Boot version you are on, there is a different Micrometer version you need to use. I would recommend to check out the Spring documentation, in order for you to use the correct version, so you avoid annoying errors that can happen doing run-time. You can check the Spring Boot release notes, in here you can see which other projects that were updated in the release. It's an easy way to keep track of which spring dependencies that must be upgraded.
After upgrading to Spring Boot 3, you might notice that your application no longer generates trace IDs or span IDs if you're still using Sleuth. To restore tracing, you'll need to migrate to Micrometer Tracing. Start by removing the spring-cloud-starter-sleuth dependency and adding the micrometer-tracing-bridge-brave dependency (micrometer-tracing-bridge-brave). You can find the latest version on the Maven repository website — just be sure to match the Micrometer version with your Spring Boot version for compatibility.
Additionally, add the spring-boot-starter-actuator dependency to your pom.xml file to enable tracing features (see here).
TIP: Create a property for your Spring Boot version in the <properties> section of your pom.xml file. This allows you to update the Spring Boot version in one place, and all related dependencies will automatically align using the ${spring.boot.version} placeholder.
For testing purposes, I also added the org.slf4j dependency so I could use MDC.get("traceId") in my REST controller. This allowed me to verify that a trace ID was being generated and returned in the response. (Check out our YouTube channel for a video demonstration).
Once you've added all the necessary dependencies, run your application with the following command:
mvn spring-boot:run
Then, test your endpoint by opening a browser and navigating to your localhost, typically:
https://localhost:8080/<name of you endpoint>
If everything is set up correctly, you should see the trace ID in the response, confirming that tracing works as expected!

