Skip to content

Commit

Permalink
GH-936 - Make sure ModuleTracingBeanPostProcessor is executed early.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odrotbohm committed Nov 19, 2024
1 parent 4218dff commit 85c5206
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spring-modulith-observability/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.Ordered;
import org.springframework.modulith.runtime.ApplicationModulesRuntime;
import org.springframework.util.Assert;

Expand All @@ -42,7 +43,7 @@
*
* @author Oliver Drotbohm
*/
public class ModuleTracingBeanPostProcessor extends ModuleTracingSupport implements BeanPostProcessor {
public class ModuleTracingBeanPostProcessor extends ModuleTracingSupport implements BeanPostProcessor, Ordered {

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

Expand Down Expand Up @@ -70,6 +71,15 @@ public ModuleTracingBeanPostProcessor(ApplicationModulesRuntime runtime, Supplie
this.factory = factory;
}

/*
* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()
*/
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE - 50;
}

/*
* (non-Javadoc)
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import example.sample.SampleProperties;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.modulith.runtime.ApplicationModulesRuntime;
Expand Down Expand Up @@ -50,4 +51,15 @@ void doesNotProxyConfiguationProperties() {

assertThat(result).isSameAs(bean);
}

@Test // GH-936
void processorIsRegisteredBefore() {

var rabbitProcessor = new RabbitListenerAnnotationBeanPostProcessor();
var tracingProcessor = new ModuleTracingBeanPostProcessor(mock(ApplicationModulesRuntime.class), () -> null,
new DefaultListableBeanFactory());

assertThat(rabbitProcessor.getOrder()).isGreaterThan(tracingProcessor.getOrder());

}
}

0 comments on commit 85c5206

Please sign in to comment.