Tracing between applications on spring boot 2 and spring boot 3 – Spring-boot

by
Ali Hasan
apache-kafka micrometer-tracing spring-boot spring-cloud-sleuth

Quick Fix: Configure 2 propagation types (W3C, B3) on the Spring Boot 2.7 side, and ensure that Spring Boot 3.0 is set to use the W3C propagation. Additionally, set spring.sleuth.traceId128=true and spring.sleuth.supportsJoin=false in your Sleuth configuration to match the settings in Spring Boot 3.0.

The Problem:

Integrating tracing across applications using Spring Boot 2 and Spring Boot 3 with Spring Cloud Sleuth and Micrometer-tracing. Specifically, acquiring the trace ID generated by Sleuth in an application using Micrometer Tracing and vice versa.

The Solutions:

Solution 1: Configuring Trace Propagation Types and Bit Size

To integrate Spring Cloud Sleuth with Micrometer tracing in applications using Spring Boot 2 and Spring Boot 3, configure the following:

Spring Boot 2.7 Application:

  • Enable support for W3C and B3 propagation types:
spring.sleuth.propagation.keys=traceId,x-request-id

Spring Boot 3.0 Application:

  • Set traceId128 to true:
spring.sleuth.traceId128=true
  • Disable join support:
spring.sleuth.supportsJoin=false

These configurations ensure that the Spring Cloud Sleuth application using Boot 2.7 generates a trace ID that can be propagated to the Spring Boot 3.0 application, and the Boot 3.0 application can pick up the trace ID using the W3C propagation type.

Solution 2: Use a consistent propagation format

Both Sleuth and Micrometer Tracing support B3 and W3C propagation formats. By default, Sleuth uses B3 while Micrometer Tracing in Boot 3 uses W3C. To ensure consistent tracing, you need to configure both applications to use the same propagation format. This can be done by setting the following properties:

For Spring Boot 2.x with Sleuth:

spring.sleuth.propagation.type=W3C

For Spring Boot 3.x with Micrometer Tracing:

management.tracing.propagation.type=B3

Q&A

When using a spring boot 3 project and spring boot 2 projects, how do I integrate tracing via Spring Cloud Sleuth on one application and Micrometer-tracing on another application?

Both Sleuth & Micrometer Tracing support B3 & W3C propagation formats.Change config to use same format for both.

How can I retrieve the trace ID generated by Sleuth in an application that uses Micrometer Tracing, and vice versa?

Use the W3C propagation for both applications, and the trace ID will be automatically propagated.

Video Explanation:

The following video, titled "Spring Boot 3 Observability with Grafana Stack - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Spring Boot 3 Observability with Grafana Stack In this course, you will learn how to implement Observability in our Spring Boot Applications ...