Spring Cloud Sleuth Tracing
In this tutorial, you'll learn about Fix Spring Cloud Sleuth Tracing Not Propagating. We cover key concepts, practical examples, and best practices.
The Problem
Trace IDs are not generated or not propagated across service boundaries.
Quick Fix
Add Sleuth dependency
Wrong:
// No Sleuth dependency
Output:
No tracing
Right:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
Output:
Sleuth tracing active
Configure sampler
Wrong:
// Default sampler may not sample
Output:
Some requests not traced
Right:
spring.sleuth.sampler.probability=1.0
Output:
All requests sampled
Verify header propagation
Wrong:
// Headers not passed between services
Output:
Trace broken
Right:
// Sleuth auto-propagates: x-b3-traceid, x-b3-spanid
// Ensure RestTemplate/WebClient is instrumented
Output:
Trace continues across services
Prevention
- Add spring-cloud-starter-sleuth dependency
- Configure Sampler.ALWAYS_SAMPLE for development
- Ensure headers propagate across service calls
Common Mistakes with cloud sleuth tracing
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world SPRING code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
This quick fix is part of the DodaTech Spring & JVM ecosystem series. Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro