Home » Java » Enterprise Java » Tracing a reactive flow – Using Spring Cloud Sleuth with Boot 2

About Biju Kunjummen

Biju Kunjummen

Tracing a reactive flow – Using Spring Cloud Sleuth with Boot 2

Spring Cloud Sleuth which adds Spring instrumentation support on top of OpenZipkin Brave makes distributed tracing trivially simple for Spring Boot applications. This is a quick write up on what it takes to add support for distributed tracing using this excellent library.

Consider two applications – a client application which uses an upstream service application, both using Spring WebFlux, the reactive web stack for Spring:

Spring Cloud Sleuth sample flow

My objective is to ensure that flows from user to the client application to the service application can be traced and latencies cleanly recorded for requests.

The final topology that Spring Cloud Sleuth enables is the following:

Spring Cloud Sleuth flow zipkin

The sampled trace information from the client and the service app is exported to Zipkin via a queuing mechanism like RabbitMQ.

So what are the changes required to the client and the service app – like I said it is trivially simple! The following libraries need to be pulled in – in my case via gradle:


The versions are not specified as they are expected to be pulled in via Spring Cloud BOM and thanks to Spring Gradle Dependency Management plugin:

ext {
    springCloudVersion = 'Finchley.RELEASE'

apply plugin: 'io.spring.dependency-management'

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

And that is actually it, any logs from the application should now start recording the trace and the spans, see how he traceid carried forward in the following logs spanning two different services:

2018-06-22 04:06:28.579  INFO [sample-client-app,c3d507df405b8aaf,c3d507df405b8aaf,true] 9 --- [server-epoll-13] sample.load.PassThroughHandler           : handling message: Message(id=null, payload=Test, delay=1000)
2018-06-22 04:06:28.586  INFO [sample-service-app,c3d507df405b8aaf,829fde759da15e63,true] 8 --- [server-epoll-11] sample.load.MessageHandler               : Handling message: Message(id=5e7ba240-f97d-405a-9633-5540bbfe0df1, payload=Test, delay=1000)

Further the Zipkin UI records the exported information and can visually show a sample trace the following way:

Spring Cloud Sleuth zipkin

This sample is available in my github repository here – https://github.com/bijukunjummen/sleuth-webflux-sample and can be started up easily using docker-compose with all the dependencies wired in.

Published on Java Code Geeks with permission by Biju Kunjummen, partner at our JCG program. See the original article here: Tracing a reactive flow – Using Spring Cloud Sleuth with Boot 2

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of