From 495467dca6f1bed9932cf6d3796a44b034ccc164 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 16 Dec 2025 08:39:05 +0000 Subject: [PATCH] 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 --- .../logging/otlp/OtlpLoggingConfigurations.java | 2 +- .../otlp/OtlpLoggingAutoConfigurationTests.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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) -> {