1

Hello I'm trying to use sleuth to trace a distributed system, but I'm lost because it doesn't work.

I did it as it is in the official document, but traceId and spandId are not output on console. [${applicationName}, ${traceId}, ${spanId}]

// build.gradle
plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.6'
    id 'io.spring.dependency-management' version '1.1.0'
}

ext {
    set('springCloudVersion', "2021.0.1")
}


group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    testCompileOnly 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

@Slf4j
@RestController
public class SimpleController {

    @GetMapping("/hello")
    public void foo() {
        log.info(">>> hello");
    }
}

enter image description here

As you can see, traceId and spandId are not taken. I can't find the cause. What could be the problem?

JavaMe
  • 29
  • 5

2 Answers2

0

You're using an incompatible Spring Cloud version. According to the documentation, Spring Cloud 2021.0.x is only compatible with Spring Boot 2.6 and 2.7. For Spring Boot 3.0.x, you have to use Spring Cloud 2022.0.x.

However, you'll notice that Spring Cloud Sleuth does not exist in Spring Cloud 2022.0.x. This is because Spring Cloud Sleuth is end-of-life and this functionality has been moved over to Micrometer Tracing.

So, the solution is to use the micrometer-observation library, which is a facade library for any observability library (kind of like slf4j is a facade for log4j, logback, ...). For distributed tracing there are two bridges (Zipkin Brave vs OpenTelemetry).

What you can do is:

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

  2. Add either micrometer-tracing-bridge-brave or micrometer-tracing-bridge-otel as a dependency. For example:

    implementation 'io.micrometer:micrometer-tracing-bridge-otel'
    
g00glen00b
  • 41,995
  • 13
  • 95
  • 133
0

If I remove the spring-cloud-starter-sleuth, I lose the format [${applicationName}, ${traceId}, ${spanId}]. I'm trying to use Spring 3.1.1.

  • It technically works if I have the spring-cloud-starter-sleuth and the micrometer-tracing-bridge-otel, but Zipkin doesn't find it.

INFO [ebac-logs-sistema3, d3365d25d8999760c756c75d2f328686, 3dbbd3367c16d58d] 65466 --- [nio-8089-exec-3] d.M.ebaclogs.controller.LogsController

  • It technically works if I have the spring-cloud-starter-sleuth and the micrometer-tracing-bridge-brave, but Zipkin doesn't find it again.

INFO [ebac-logs-sistema3, 64c448f27a6186a48f20c16e14e57686, 8f20c16e14e57686] 65901 --- [nio-8089-exec-3] d.M.ebaclogs.controller.LogsController

The "solution" was changing my Spring version to 2.7.1. Still trying to make it happen on 3.1.1 though.