Skip to content

Commit 85c5206

Browse files
committed
GH-936 - Make sure ModuleTracingBeanPostProcessor is executed early.
We now explicitly declare an order for the MTBPP so that it gets registered for execution before the ones that create infrastructure for message listeners so that those already see the potentially proxied instance and invocations actually invoke the advice creating the traces.
1 parent 4218dff commit 85c5206

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

spring-modulith-observability/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
<scope>test</scope>
100100
</dependency>
101101

102+
<dependency>
103+
<groupId>org.springframework.amqp</groupId>
104+
<artifactId>spring-rabbit</artifactId>
105+
<scope>test</scope>
106+
</dependency>
107+
102108
</dependencies>
103109

104110
</project>

spring-modulith-observability/src/main/java/org/springframework/modulith/observability/ModuleTracingBeanPostProcessor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.beans.factory.config.BeanPostProcessor;
3434
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3535
import org.springframework.boot.context.properties.ConfigurationProperties;
36+
import org.springframework.core.Ordered;
3637
import org.springframework.modulith.runtime.ApplicationModulesRuntime;
3738
import org.springframework.util.Assert;
3839

@@ -42,7 +43,7 @@
4243
*
4344
* @author Oliver Drotbohm
4445
*/
45-
public class ModuleTracingBeanPostProcessor extends ModuleTracingSupport implements BeanPostProcessor {
46+
public class ModuleTracingBeanPostProcessor extends ModuleTracingSupport implements BeanPostProcessor, Ordered {
4647

4748
public static final String MODULE_BAGGAGE_KEY = "org.springframework.modulith.module";
4849

@@ -70,6 +71,15 @@ public ModuleTracingBeanPostProcessor(ApplicationModulesRuntime runtime, Supplie
7071
this.factory = factory;
7172
}
7273

74+
/*
75+
* (non-Javadoc)
76+
* @see org.springframework.core.Ordered#getOrder()
77+
*/
78+
@Override
79+
public int getOrder() {
80+
return Ordered.LOWEST_PRECEDENCE - 50;
81+
}
82+
7383
/*
7484
* (non-Javadoc)
7585
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)

spring-modulith-observability/src/test/java/org/springframework/modulith/observability/ModuleTracingBeanPostProcessorUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import example.sample.SampleProperties;
2323

2424
import org.junit.jupiter.api.Test;
25+
import org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor;
2526
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
2627
import org.springframework.beans.factory.support.RootBeanDefinition;
2728
import org.springframework.modulith.runtime.ApplicationModulesRuntime;
@@ -50,4 +51,15 @@ void doesNotProxyConfiguationProperties() {
5051

5152
assertThat(result).isSameAs(bean);
5253
}
54+
55+
@Test // GH-936
56+
void processorIsRegisteredBefore() {
57+
58+
var rabbitProcessor = new RabbitListenerAnnotationBeanPostProcessor();
59+
var tracingProcessor = new ModuleTracingBeanPostProcessor(mock(ApplicationModulesRuntime.class), () -> null,
60+
new DefaultListableBeanFactory());
61+
62+
assertThat(rabbitProcessor.getOrder()).isGreaterThan(tracingProcessor.getOrder());
63+
64+
}
5365
}

0 commit comments

Comments
 (0)