Require micrometer-tracing-bridge-brave to auto-configure Brave

Closes gh-32502
pull/32525/head
Andy Wilkinson 2 years ago
parent fcafd2abdb
commit 6cc3619675

@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.tracing;
import java.util.List;
import brave.Tracer;
import brave.Tracing;
import brave.Tracing.Builder;
import brave.TracingCustomizer;
@ -48,7 +49,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
/**
@ -58,7 +58,7 @@ import org.springframework.core.env.Environment;
* @since 3.0.0
*/
@AutoConfiguration(before = MicrometerTracingAutoConfiguration.class)
@ConditionalOnClass(brave.Tracer.class)
@ConditionalOnClass({ Tracer.class, BraveTracer.class })
@EnableConfigurationProperties(TracingProperties.class)
@ConditionalOnEnabledTracing
public class BraveAutoConfiguration {
@ -135,10 +135,6 @@ public class BraveAutoConfiguration {
return HttpClientHandler.create(httpTracing);
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(BraveTracer.class)
static class BraveMicrometer {
@Bean
@ConditionalOnMissingBean
BraveTracer braveTracerBridge(brave.Tracer tracer, CurrentTraceContext currentTraceContext,
@ -167,5 +163,3 @@ public class BraveAutoConfiguration {
}
}
}

@ -55,7 +55,7 @@ class BraveAutoConfigurationTests {
.withConfiguration(AutoConfigurations.of(BraveAutoConfiguration.class));
@Test
void shouldSupplyBraveBeans() {
void shouldSupplyDefaultBeans() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(Tracing.class);
assertThat(context).hasSingleBean(Tracer.class);
@ -65,12 +65,16 @@ class BraveAutoConfigurationTests {
assertThat(context).hasSingleBean(HttpTracing.class);
assertThat(context).hasSingleBean(HttpServerHandler.class);
assertThat(context).hasSingleBean(HttpClientHandler.class);
assertThat(context).hasSingleBean(BraveTracer.class);
assertThat(context).hasSingleBean(BraveBaggageManager.class);
assertThat(context).hasSingleBean(BraveHttpServerHandler.class);
assertThat(context).hasSingleBean(BraveHttpClientHandler.class);
});
}
@Test
void shouldBackOffOnCustomBraveBeans() {
this.contextRunner.withUserConfiguration(CustomBraveConfiguration.class).run((context) -> {
void shouldBackOffOnCustomBeans() {
this.contextRunner.withUserConfiguration(CustomConfiguration.class).run((context) -> {
assertThat(context).hasBean("customTracing");
assertThat(context).hasSingleBean(Tracing.class);
assertThat(context).hasBean("customTracer");
@ -87,22 +91,6 @@ class BraveAutoConfigurationTests {
assertThat(context).hasSingleBean(HttpServerHandler.class);
assertThat(context).hasBean("customHttpClientHandler");
assertThat(context).hasSingleBean(HttpClientHandler.class);
});
}
@Test
void shouldSupplyMicrometerBeans() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(BraveTracer.class);
assertThat(context).hasSingleBean(BraveBaggageManager.class);
assertThat(context).hasSingleBean(BraveHttpServerHandler.class);
assertThat(context).hasSingleBean(BraveHttpClientHandler.class);
});
}
@Test
void shouldBackOffOnCustomMicrometerBraveBeans() {
this.contextRunner.withUserConfiguration(CustomMicrometerBraveConfiguration.class).run((context) -> {
assertThat(context).hasBean("customBraveTracer");
assertThat(context).hasSingleBean(BraveTracer.class);
assertThat(context).hasBean("customBraveBaggageManager");
@ -115,45 +103,25 @@ class BraveAutoConfigurationTests {
}
@Test
void shouldNotSupplyBraveBeansIfBraveIsMissing() {
this.contextRunner.withClassLoader(new FilteredClassLoader("brave")).run((context) -> {
assertThat(context).doesNotHaveBean(Tracing.class);
assertThat(context).doesNotHaveBean(Tracer.class);
assertThat(context).doesNotHaveBean(CurrentTraceContext.class);
assertThat(context).doesNotHaveBean(Factory.class);
assertThat(context).doesNotHaveBean(Sampler.class);
assertThat(context).doesNotHaveBean(HttpTracing.class);
assertThat(context).doesNotHaveBean(HttpServerHandler.class);
assertThat(context).doesNotHaveBean(HttpClientHandler.class);
});
void shouldNotSupplyBeansIfBraveIsMissing() {
this.contextRunner.withClassLoader(new FilteredClassLoader("brave"))
.run((context) -> assertThat(context).doesNotHaveBean(BraveAutoConfiguration.class));
}
@Test
void shouldNotSupplyMicrometerBeansIfMicrometerIsMissing() {
this.contextRunner.withClassLoader(new FilteredClassLoader("io.micrometer")).run((context) -> {
assertThat(context).doesNotHaveBean(BraveTracer.class);
assertThat(context).doesNotHaveBean(BraveBaggageManager.class);
assertThat(context).doesNotHaveBean(BraveHttpServerHandler.class);
assertThat(context).doesNotHaveBean(BraveHttpClientHandler.class);
});
void shouldNotSupplyBeansIfMicrometerIsMissing() {
this.contextRunner.withClassLoader(new FilteredClassLoader("brave"))
.run((context) -> assertThat(context).doesNotHaveBean(BraveAutoConfiguration.class));
}
@Test
void shouldNotSupplyBraveBeansIfTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false").run((context) -> {
assertThat(context).doesNotHaveBean(Tracing.class);
assertThat(context).doesNotHaveBean(Tracer.class);
assertThat(context).doesNotHaveBean(CurrentTraceContext.class);
assertThat(context).doesNotHaveBean(Factory.class);
assertThat(context).doesNotHaveBean(Sampler.class);
assertThat(context).doesNotHaveBean(HttpTracing.class);
assertThat(context).doesNotHaveBean(HttpServerHandler.class);
assertThat(context).doesNotHaveBean(HttpClientHandler.class);
});
void shouldNotSupplyBeansIfTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(BraveAutoConfiguration.class));
}
@Configuration(proxyBeanMethods = false)
private static class CustomBraveConfiguration {
private static class CustomConfiguration {
@Bean
Tracing customTracing() {
@ -197,11 +165,6 @@ class BraveAutoConfigurationTests {
return HttpClientHandler.create(httpTracing);
}
}
@Configuration(proxyBeanMethods = false)
private static class CustomMicrometerBraveConfiguration {
@Bean
BraveTracer customBraveTracer() {
return mock(BraveTracer.class);

Loading…
Cancel
Save