Skip to content

Commit 495467d

Browse files
committed
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
1 parent 5e5e8d9 commit 495467d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class OtlpLoggingConfigurations {
4646
static class ConnectionDetails {
4747

4848
@Bean
49-
@ConditionalOnMissingBean
49+
@ConditionalOnMissingBean(OtlpLoggingConnectionDetails.class)
5050
@ConditionalOnProperty("management.opentelemetry.logging.export.otlp.endpoint")
5151
PropertiesOtlpLoggingConnectionDetails openTelemetryLoggingConnectionDetails(OtlpLoggingProperties properties) {
5252
return new PropertiesOtlpLoggingConnectionDetails(properties);

module/spring-boot-opentelemetry/src/test/java/org/springframework/boot/opentelemetry/autoconfigure/logging/otlp/OtlpLoggingAutoConfigurationTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.springframework.context.annotation.Configuration;
4444

4545
import static org.assertj.core.api.Assertions.assertThat;
46+
import static org.mockito.BDDMockito.given;
47+
import static org.mockito.Mockito.mock;
4648

4749
/**
4850
* Tests for {@link OtlpLoggingAutoConfiguration}.
@@ -89,6 +91,21 @@ void whenHasEndpointPropertyProvidesBeans() {
8991
});
9092
}
9193

94+
@Test
95+
void customConnectionDetailsReplacePropertyBasedConnectionDetails() {
96+
OtlpLoggingConnectionDetails details = mock(OtlpLoggingConnectionDetails.class);
97+
given(details.getUrl(Transport.HTTP)).willReturn("http://localhost:4318/v1/logs");
98+
this.contextRunner
99+
.withPropertyValues("management.opentelemetry.logging.export.otlp.endpoint=http://localhost:4319/v1/logs")
100+
.withBean("customOtlpLoggingConnectionDetails", OtlpLoggingConnectionDetails.class, () -> details)
101+
.run((context) -> {
102+
assertThat(context).hasSingleBean(OtlpLoggingConnectionDetails.class);
103+
assertThat(context).hasBean("customOtlpLoggingConnectionDetails");
104+
assertThat(context.getBean(OtlpLoggingConnectionDetails.class).getUrl(Transport.HTTP))
105+
.isEqualTo("http://localhost:4318/v1/logs");
106+
});
107+
}
108+
92109
@Test
93110
void whenHasNoEndpointPropertyDoesNotProvideBeans() {
94111
this.contextRunner.run((context) -> {

0 commit comments

Comments
 (0)