diff --git a/module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingConfigurations.java b/module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingConfigurations.java index 6dd8b6b3d3e..33e3bb7742b 100644 --- a/module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingConfigurations.java +++ b/module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingConfigurations.java @@ -46,7 +46,7 @@ final class OtlpLoggingConfigurations { static class ConnectionDetails { @Bean - @ConditionalOnMissingBean + @ConditionalOnMissingBean(OtlpLoggingConnectionDetails.class) @ConditionalOnProperty("management.opentelemetry.logging.export.otlp.endpoint") PropertiesOtlpLoggingConnectionDetails openTelemetryLoggingConnectionDetails(OtlpLoggingProperties properties) { return new PropertiesOtlpLoggingConnectionDetails(properties); diff --git a/module/spring-boot-opentelemetry/src/test/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationTests.java b/module/spring-boot-opentelemetry/src/test/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationTests.java index d05f35560db..20709e64371 100644 --- a/module/spring-boot-opentelemetry/src/test/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationTests.java +++ b/module/spring-boot-opentelemetry/src/test/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationTests.java @@ -43,6 +43,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; /** * Tests for {@link OtlpLoggingAutoConfiguration}. @@ -89,6 +91,21 @@ class OtlpLoggingAutoConfigurationTests { }); } + @Test + void customConnectionDetailsReplacePropertyBasedConnectionDetails() { + OtlpLoggingConnectionDetails details = mock(OtlpLoggingConnectionDetails.class); + given(details.getUrl(Transport.HTTP)).willReturn("http://localhost:4318/v1/logs"); + this.contextRunner + .withPropertyValues("management.opentelemetry.logging.export.otlp.endpoint=http://localhost:4319/v1/logs") + .withBean("customOtlpLoggingConnectionDetails", OtlpLoggingConnectionDetails.class, () -> details) + .run((context) -> { + assertThat(context).hasSingleBean(OtlpLoggingConnectionDetails.class); + assertThat(context).hasBean("customOtlpLoggingConnectionDetails"); + assertThat(context.getBean(OtlpLoggingConnectionDetails.class).getUrl(Transport.HTTP)) + .isEqualTo("http://localhost:4318/v1/logs"); + }); + } + @Test void whenHasNoEndpointPropertyDoesNotProvideBeans() { this.contextRunner.run((context) -> {