Browse Source

Make OTLP logging connection details back off

Previously, the connection details would only back off if another
PropertiesOtlpLoggingConnectionDetails was defined. This commit
corrects this so that they will back of if any
OtlpLoggingConnectionDetails implementation is defined as a bean.

Closes gh-48536
pull/48552/head
Andy Wilkinson 1 month ago
parent
commit
495467dca6
  1. 2
      module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingConfigurations.java
  2. 17
      module/spring-boot-opentelemetry/src/test/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationTests.java

2
module/spring-boot-opentelemetry/src/main/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingConfigurations.java

@ -46,7 +46,7 @@ final class OtlpLoggingConfigurations { @@ -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);

17
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; @@ -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 { @@ -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) -> {

Loading…
Cancel
Save