Skip to content

Spring Cloud Sleuth Tracing

DodaTech 1 min read

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

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' 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

### Why are trace IDs not visible in logs?

Sleuth adds trace IDs to MDC. Ensure %X{traceId} is in the log pattern.

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