Propagate context to Spring MessageListenerAdapter#2478
Merged
Conversation
d991d65 to
b98c714
Compare
b98c714 to
494d88a
Compare
tylerbenson
approved these changes
Mar 10, 2021
207ba4f to
4c56456
Compare
bantonsson
approved these changes
Mar 11, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When Spring users use RabbitMQ
MessageListenerAdapterthey get broken traces, because the scope of thebasic.deliverspan is not propagated to theMessageListenerAdapter's delegate, where any traceable activity will start a new trace. This happens because Spring AMQP (wisely) invokes user callbacks on a different thread to the MQ subscription, and the handoff is not done via an executor. Instead, RabbitMQEnvelopes are wrapped inDeliveryobjects which are enqueued byBlockingQueueConsumer, which drains said queue and wraps theDeliverys asMessageobjects, which will eventually be passed to theMessageListenerAdapterviaAbstractMessageListenerContainer.executeListener.The basic data flow here
Deliveryin construction (in the subscription thread)DeliverytoMessageinBlockingQueueConsumer.handle(on the handling thread)AbstractMessageListenerContainer.executeListenerand close the scope afterwards.Since this instrumentation depends on two libraries (spring-rabbit and spring-amqp) it is muzzled via
spring-boot-starter-amqpwhich depends on both.Since there is a circular dependency between this instrumentation and
rabbit-amqp-2.7, it needs to be tested that this instrumentation does not interfere with the other instrumentation, but this cannot be done by adding a dependency both ways. I copied the rabbitmq tests into this module and they pass here, but removed the copied test before committing. I can add it back if it's felt important enough.