[Solved] spring boot with sleuth not working traceId – Spring-boot

by
Ali Hasan
spring-boot spring-cloud-aws zipkin

Quick Fix: Remove spring-cloud-starter-sleuth dependency and add micrometer-tracing-bridge-brave or micrometer-tracing-bridge-otel as a dependency in your build.gradle.

The Solutions:

Solution 1: Incompatible Spring Boot version

The root cause of the issue is an incompatible Spring Boot version. Spring Boot 2021.0.x is only compatible with Spring Boot 2.6 and 2.7. For Spring Boot 3.0.x, you must use Spring Boot 2022.0.x. However, Spring Boot Sleuth does not exist in Spring Boot 2022.0.x because it is now end-of-life.

Solution 2: Using the micrometer-observation library

To resolve this issue, you can use the micrometer-observation library, which is a facade library for any observability library. For distributed tracing, there are two options: OpenTelemetry and Brave.

  1. Remove spring-cloud-starter-sleuth (and spring-cloud-dependencies if you don’t use it) from your build.gradle file.

  2. Add either micrometer-tracing-brave or micrometer-tracing-otel as a Maven/Gradle/Ivy/etc. For example for OpenTelemetry:

    implementation 'io.micrometer:micrometer-tracing-otel'    
    

Solution 2: Use an older version of Spring Boot

Spring Cloud Sleuth and the Micrometer tracing bridge are known to have issues with newer versions of Spring Boot. Downgrading to Spring Boot 2.7.1, according to the solution provided, resolves the issue and allows tracing information to be captured and displayed correctly.

Solution 3: Spring Cloud Sleuth Incompatible with Spring Boot 3.x

Spring Cloud Sleuth is no longer compatible with Spring Boot 3.x and onward. Sleuth’s support ends with Spring Boot 2.x. Refer to the official Spring Cloud Sleuth documentation for more information.

Q&A

Why traceId and spandId are not output on console?

You’re using an incompatible Spring Cloud version.

What you can do?

Remove spring-cloud-starter-sleuth (and spring-cloud-dependencies if you don’t use it) from your build.gradle and add either micrometer-tracing-bridge-brave or micrometer-tracing-bridge-otel as a dependency.

Video Explanation:

The following video, titled "Tracing Issues in Your Application - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

and now it's time to solve the mystery—what did the user do that led ... Spring Cloud Sleuth, Tanzu Observability, OpenZipkin, OpenTelemetry ...