Sleuth is not working with Spring Boot 3.0.0 Version
Asked Answered
P

3

5

I am using Sleuth and Zipkin for distributed tracing and facing an issue.

Issue: TraceID and SpanID is not getting printed in the microservice logs (and passed to Zipkin) with 3.0.0 version of Spring Boot.

Following are the versions I am using:

  • Spring Boot version: 3.0.0
  • Spring cloud version: 2021.0.4
  • Zipkin Server version: zipkin-server-2.23.19-exec

application.properties:

spring.application.name=sleuthpoc2
spring.zipkin.base-url=http://localhost:9411/
spring.sleuth.sampler.probability=1.0
spring.zipkin.sender.type=WEB
Purdy answered 29/11, 2022 at 13:47 Comment(1)
Does this answer your question? Zipkin not working in Docker - conncection refusedBlount
O
14

As we describe it in https://github.com/spring-cloud/spring-cloud-sleuth/tree/main

Spring Cloud Sleuth’s last minor version is 3.1. You can check the 3.1.x branch for the latest commits.

The core of this project got moved to Micrometer Tracing project and the instrumentations will be moved to Micrometer and all respective projects (no longer all instrumentations will be done in a single repository.

You can check the migration guide here https://github.com/micrometer-metrics/tracing/wiki/Spring-Cloud-Sleuth-3.1-Migration-Guide on how to migrate away from Sleuth to Micrometer Tracing.

Orlene answered 29/11, 2022 at 13:53 Comment(5)
Hi Marcin, are you talking about the Sleuth version? If I got it right then I need to use 3.1 version of sleuth with Spring boot 3.0.0 version. Please confirmPurdy
As I wrote in the answer, Sleuth 3.1.x is the last version that we release. It's Boot 2.x compatible. There's no version of Sleuth that is Boot 3.x compatible. You would need to migrate to Micrometer Tracing in order to use Boot 3.0Orlene
@Marcin Grzejszczak does Micrometer support openFeign (for brave & zipkin)Hangover
Micrometer Observation was added to Feign 12.1 github.com/OpenFeign/feign/commit/…Orlene
I tried this successfully. but how we can change the zipkin.sender.type in new way. because I was unable to find that in the doc.Leatherneck
M
5

UPDATE Feb 02, 2024

From Spring Boot 3.2, it will automatically add application name, trace id, and span id to log. The only thing you need to do is add micrometer dependency then setup zipkin:

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

If you want to work your program which is using Spring Boot 3.0.0 Version. You can follow this way:

1) Please add the following dependencies from your pom.xml:

    <dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-observation</artifactId>
    </dependency>  

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-tracing-bridge-brave</artifactId>
    </dependency> 

    <dependency>
        <groupId>io.zipkin.reporter2</groupId>
        <artifactId>zipkin-reporter-brave</artifactId>
    </dependency>  

    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-micrometer</artifactId>
    </dependency>

2) Please configure your application.properties (if you use application.properties):

management.tracing.sampling.probability=0.1

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

3) The last step is running the zipkin from docker (be sure docker must be running before the running this command):

 docker run --rm -it --name zipkin -p 9411:9411 openzipkin/zipkin
Milkfish answered 7/10, 2023 at 19:58 Comment(0)
A
2

Had the same issue with spring boot 3. Removed sleuth dependency and added micrometer dependecy. Able to get trace and span ID in the logs. Below are the sample codes:

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-tracing-bridge-brave</artifactId>
        <version>1.1.1</version>
    </dependency>

      <appender class="ch.qos.logback.core.ConsoleAppender" name="stdout">
       <encoder>
         <pattern>
            %d{yyyy-MM-dd} | %d{HH:mm:ss.SSS} | %thread | %5p | %logger{25} | %12(ID: %8mdc{id}) | %X{traceId:-} | "%X{spanId:-}" | appName | %m%n 
        </pattern>
    </encoder>
    </appender>
     <appender class="ch.qos.logback.core.ConsoleAppender" name="jsonstdout">
       <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
        <providers>
            <timestamp>
                <timeZone>EST</timeZone>
                 <timestampPattern>yyyy-MM-dd'T'HH:mm:ss.SSS</timestampPattern>
            </timestamp>
                <pattern>
                <pattern>
                    {
                        "service" : "appName",
                        "level": "%p",
                        "thread": "%thread",
                        "trace": "%X{traceId:-}",
                        "span": "%X{spanId:-}",
                        "class": "%logger{40}",
                        "message": "%m"
                    }
                </pattern>
            </pattern>
            <stackTrace>
                <throwableConverter 
           class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                    <maxDepthPerThrowable>30</maxDepthPerThrowable>
                    <maxLength>2048</maxLength>
                    <shortenedClassNameLength>20</shortenedClassNameLength>
                    <rootCauseFirst>true</rootCauseFirst>
                </throwableConverter>
            </stackTrace>
        </providers>
    </encoder>
</appender>
Adolpho answered 31/5, 2023 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.