Auto-configure OtlpHttpSpanExporter only if property is set
- Remove the default value of 'management.otlp.tracing.endpoint' Closes gh-35596
This commit is contained in:
parent
cd018aff9c
commit
214f06083b
|
@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
|
@ -45,6 +46,7 @@ import org.springframework.context.annotation.Bean;
|
|||
* define an {@link OtlpGrpcSpanExporter} and this auto-configuration will back off.
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @author Moritz Halbritter
|
||||
* @since 3.1.0
|
||||
*/
|
||||
@AutoConfiguration
|
||||
|
@ -56,6 +58,7 @@ public class OtlpAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean(value = OtlpHttpSpanExporter.class,
|
||||
type = "io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter")
|
||||
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "endpoint")
|
||||
OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpProperties properties) {
|
||||
OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder()
|
||||
.setEndpoint(properties.getEndpoint())
|
||||
|
|
|
@ -34,7 +34,7 @@ public class OtlpProperties {
|
|||
/**
|
||||
* URL to the OTel collector's HTTP API.
|
||||
*/
|
||||
private String endpoint = "http://localhost:4318/v1/traces";
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* Call timeout for the OTel Collector to process an exported batch of data. This
|
||||
|
|
|
@ -33,16 +33,23 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link OtlpAutoConfiguration}.
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class OtlpAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(OtlpAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void shouldNotSupplyBeansIfPropertyIsNotSet() {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(OtlpHttpSpanExporter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSupplyBeans() {
|
||||
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(OtlpHttpSpanExporter.class)
|
||||
.hasSingleBean(SpanExporter.class));
|
||||
this.contextRunner.withPropertyValues("management.otlp.tracing.endpoint=http://localhost:4318/v1/traces")
|
||||
.run((context) -> assertThat(context).hasSingleBean(OtlpHttpSpanExporter.class)
|
||||
.hasSingleBean(SpanExporter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue