Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

traceId is not being propagated from RabbitListener through its return #510

Closed
TJackler opened this issue Jan 5, 2024 · 9 comments
Closed

Comments

@TJackler
Copy link

TJackler commented Jan 5, 2024

Hi,

I am designing a system that takes a REST call and sends a message to rabbit a queue. The RabbitListener method for that queue processes the message with its handler, but when I take the message and pass to another queue, the traceId is not propagated to the RabbitListener handler of the new queue.

For visualization purpose;

User -> Rest -> queue1 -> RabbitListner(queue1) (correct traceId) -> queue2 -> RabbitListener(queue2) (wrong traceId)t -> Back to Rest Call
@Component
public class MessageHandler {

    private static final Logger log = LoggerFactory.getLogger(MessageHandler.class);

    private final Executor executor = Executors.newCachedThreadPool();

    @RabbitListener(queuesToDeclare = @Queue(name = "task-queue", durable = "durable", autoDelete = "true"), ackMode = "MANUAL")
    public CompletableFuture<String> handleMessage(String s, @Headers Map<String, Object> headers) {
        log.info("message received: {}", s);
        return CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(1000);
                log.info("sending reply: {}", s.toUpperCase());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return s.toUpperCase();
        }, executor);
    }
}

The header (which comes from the rest through rabbitTemplate) includes traceparent but. Returned message (from this method) to desired queue does not include traceparent header.

I checked out the examples below; but It did not help to propagate traceId for this case.
https://github.com/micrometer-metrics/micrometer-samples/tree/main/rabbitmq-consumer
https://github.com/micrometer-metrics/micrometer-samples/tree/main/rabbitmq-producer

Thanks for the development @marcingrzejszczak and rest of the team members.

@marcingrzejszczak
Copy link
Contributor

Are you saying that our samples do not work well?

Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@TJackler
Copy link
Author

TJackler commented Jan 18, 2024

Your examples work fine for the case which is not changing the thread. When I use CompletableFuture.supplyAsync and supply the job taken from the queue to the another thread (due to supplyAsync), it does not propagate the trace id to that thread.

@marcingrzejszczak
Copy link
Contributor

have you passed an executor to the supplyAsync and wrapped it with context propagation?

Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@TJackler
Copy link
Author

Yes, I did wrap the custom context propagator to the supply async, but it does not make traceId propagation possible to the new thread local.

@marcingrzejszczak
Copy link
Contributor

Can you file an issue in Spring AMQP project where the actual instrumentation takes place?

Copy link

github-actions bot commented Feb 7, 2024

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@marcingrzejszczak
Copy link
Contributor

Closing in favour of spring-projects/spring-amqp#2608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants