diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index 5477ff84bc..c5f7832186 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -209,7 +209,8 @@ public class IntegrationAutoConfiguration { @Configuration(proxyBeanMethods = false) @EnableIntegrationManagement( - defaultLoggingEnabled = "${spring.integration.management.default-logging-enabled:true}") + defaultLoggingEnabled = "${spring.integration.management.default-logging-enabled:true}", + observationPatterns = "${spring.integration.management.observation-patterns:}") protected static class EnableIntegrationManagementConfiguration { } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java index 65ace115b1..464142b043 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationProperties.java @@ -416,6 +416,12 @@ public class IntegrationProperties { */ private boolean defaultLoggingEnabled = true; + /** + * Comma-separated simple patterns to match integration components for observation + * instrumentation. + */ + private List observationPatterns = new ArrayList<>(); + public boolean isDefaultLoggingEnabled() { return this.defaultLoggingEnabled; } @@ -424,6 +430,14 @@ public class IntegrationProperties { this.defaultLoggingEnabled = defaultLoggingEnabled; } + public List getObservationPatterns() { + return this.observationPatterns; + } + + public void setObservationPatterns(List observationPatterns) { + this.observationPatterns = observationPatterns; + } + } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index 10eacb6ac6..125c2de84d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import javax.management.MBeanServer; import javax.sql.DataSource; +import io.micrometer.observation.ObservationRegistry; import io.rsocket.transport.ClientTransport; import io.rsocket.transport.netty.client.TcpClientTransport; import org.assertj.core.api.InstanceOfAssertFactories; @@ -62,6 +63,8 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.MessageSource; import org.springframework.integration.endpoint.MessageProcessorMessageSource; import org.springframework.integration.gateway.RequestReplyExchanger; +import org.springframework.integration.handler.BridgeHandler; +import org.springframework.integration.handler.LoggingHandler; import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.rsocket.ClientRSocketConnector; import org.springframework.integration.rsocket.IntegrationRSocketEndpoint; @@ -491,6 +494,17 @@ class IntegrationAutoConfigurationTests { } + @Test + void integrationManagementInstrumentedWithObservation() { + this.contextRunner.withPropertyValues("spring.integration.management.observation-patterns=testHandler") + .withBean("testHandler", LoggingHandler.class, () -> new LoggingHandler("warn")) + .withBean(ObservationRegistry.class, ObservationRegistry::create) + .withBean(BridgeHandler.class, BridgeHandler::new).run((context) -> { + assertThat(context).getBean("testHandler").extracting("observationRegistry").isNotNull(); + assertThat(context).getBean(BridgeHandler.class).extracting("observationRegistry").isNull(); + }); + } + @Configuration(proxyBeanMethods = false) static class CustomMBeanExporter {