Skip to content

Misaligned spans with Mongodb (includes sample) #1873

@jiraguha

Description

@jiraguha

Describe the bug

Using Spring Sleuth with Mongodb integration causes issues. We use project-reactor and the issue apprears when a service call another service using flatmap. Both services use mongo:

java.lang.AssertionError: Misalignment: scoped span NoopSpan(3a27c90bb910c469/eef6aa97485a9d38) !=  current span null
	at brave.propagation.ThreadLocalSpan.remove(ThreadLocalSpan.java:164) ~[brave-5.13.2.jar:na]
	at brave.mongodb.TraceMongoCommandListener.commandSucceeded(TraceMongoCommandListener.java:103) ~[brave-instrumentation-mongodb-5.13.2.jar:na]

Maybe the issue is somewhere deeper in the relation between the reactive context and mongo... Please, find a sample below.

Sample

see mongo-misaligned-colors-example
It contains:

  • Unit tests that isolate the problem: NextSpan && service calling service and ColorControllerTest.find
  • 2 branches; the main branch is buggy & with_sleuth_mongodb_disable branch where all unit tests pass
  • The issue can be check quickly by run the app via GET localhost:8080/... You will need mongo running locally docker run -it -v mongodata:/data/db -p 27017:27017 --name mongodb -d mong

On the buggy branch, once the Misalignment occurs some other tests fail!

Note

It seems to be similar to #1349 or #1510

Spec


springCloud : 2020.0.1
springBoot: 2.4.3 with project-reactor
kotlin: 1.4.30
java: 15
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions