Skip to content

Thread name prefix is not always set when using virtual threads #39748

Closed as not planned
@OathMeadow

Description

@OathMeadow

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

Metadata

Metadata

Assignees

Labels

status: supersededAn issue that has been superseded by another

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions