spring-cloud-sleuth: Misaligned spans exception when used with spring-data-mongodb-reactive and spring-cloud-stream

Versions used

Java: 1.8 Spring Boot: 2.4.0-M3 Spring Cloud: 2020.0.0-M4 Spring Cloud Sleuth: 3.0.0-M4

Description of the error

When Spring Cloud Sleuth is used together with Spring Data MongoDB Reactive and Spring Cloud Stream it throws Misaligned spans exceptions. This is demonstrated by the GitHub project: git@github.com:magnus-larsson/ml-service-sleuth-issue.git

This project contains three tests:

  1. createProductDirect - creates a document in MongoDB using Spring Data MongoDB Reactive
  2. usingStreamWithoutMongoDb - tests Spring Cloud Stream without using MongoDB
  3. createProductUsingStream - combines usage of Spring Cloud Stream and Spring Data MongoDB Reactive

Test 1 and 2 are ok, while test 3 throws an exception:

Misalignment: scoped span NoopSpan(57d50a0ff0504383/82431158846274f5) !=  current span LazySpan(57d50a0ff0504383/62a7279d555f7b0e)
java.lang.AssertionError: Misalignment: scoped span NoopSpan(57d50a0ff0504383/82431158846274f5) !=  current span LazySpan(57d50a0ff0504383/62a7279d555f7b0e)

Instructions to reproduce the error

git clone git@github.com:magnus-larsson/ml-service-sleuth-issue.git
cd ml-service-sleuth-issue
./gradlew test --info

The build will fail and in the log output you can find:

> Task :test FAILED

se.magnus.microservices.core.product.MLTests > createProductUsingStream() FAILED
    java.lang.AssertionError: Misalignment: scoped span NoopSpan(1f60cb80f1401bd6/f134e48ecd166acd) !=  current span LazySpan(1f60cb80f1401bd6/4f33d06bb34e1043)

To make the failing test run ok, one of the following changes can be made to build.gradle:

  1. Remove spring-cloud-starter-sleuth from the dependencies
  2. Change the Spring Boot version to 2.3.2.RELEASE and Spring Cloud version to Hoxton.SR6

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Of course it does cause it doesn’t instrument mongo. You can remain with spring-cloud-starter-sleuth and just set spring.sleuth.mongodb.enabled=false and you’ll disable it.