We noticed that the thread name was missing as a field in our logs logged by the rabbit listener after activating VirtualThreads.
We use Loki in Grafana where we have multiple fields, where the thread name is one of them. To be able to see which thread logs what is useful to identify issues.
We noticed that in the class org.springframework.boot.autoconfigure.amqp.RabbitAnnotationDrivenConfiguration, Spring Boot does not set a thread prefix to the VirtualThreadTaskExecutor class when VirtualThreads is configured. In fact, when not set, it defaults to null. Perhaps that is by design, but It seems Spring Boot sets a thread name prefix in some AutoConfigurations and some not.
May I suggest names something like:
@Bean(name = "directRabbitListenerContainerFactoryConfigurer")
@ConditionalOnMissingBean
@ConditionalOnThreading(Threading.VIRTUAL)
DirectRabbitListenerContainerFactoryConfigurer directRabbitListenerContainerFactoryConfigurerVirtualThreads() {
DirectRabbitListenerContainerFactoryConfigurer configurer = directListenerConfigurer();
configurer.setTaskExecutor(new VirtualThreadTaskExecutor("direct-rabbit-listener-"));
return configurer;
}
@Bean(name = "simpleRabbitListenerContainerFactoryConfigurer")
@ConditionalOnMissingBean
@ConditionalOnThreading(Threading.VIRTUAL)
SimpleRabbitListenerContainerFactoryConfigurer simpleRabbitListenerContainerFactoryConfigurerVirtualThreads() {
SimpleRabbitListenerContainerFactoryConfigurer configurer = simpleListenerConfigurer();
configurer.setTaskExecutor(new VirtualThreadTaskExecutor("simple-rabbit-listener-"));
return configurer;
}
Thank you
Comment From: mhalbritter
We set the names for Redis, Kafka and Undertow. We don't set them for Rabbit and for Pulsar. We should make that consistent. IMHO we should name threads in all cases.
Comment From: MazizEsa
Can I help out with this @mhalbritter ?
Comment From: mhalbritter
Sure. I'll assign the issue to you. This is targeted for the 3.2.x branch, so please create your PR based on that. If you need help, please chime back in.
Comment From: MazizEsa
@mhalbritter . When is the 3.2.x going to be released. I will do this outside of my working time.
Comment From: mhalbritter
Don't worry about timelines. We release 3.2.x every month (see https://calendar.spring.io/). Please take your time, it's done when it's done :)
Comment From: MazizEsa
Thanks. :)
Comment From: somayaj
Hello, is this open to work on?
Comment From: wilkinsona
Thanks for the offer, @somayaj, but @MazizEsa is already assigned and working on this issue.
Comment From: MazizEsa
Sorry, can anyone reassign me back. Accidentally click unassign. Sorry again @mhalbritter .
Comment From: mhalbritter
Superseded by #39958.