Require micrometer-tracing-bridge-brave to auto-configure Brave
Closes gh-32502
This commit is contained in:
parent
fcafd2abdb
commit
6cc3619675
|
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.tracing;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import brave.Tracer;
|
||||||
import brave.Tracing;
|
import brave.Tracing;
|
||||||
import brave.Tracing.Builder;
|
import brave.Tracing.Builder;
|
||||||
import brave.TracingCustomizer;
|
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.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,7 +58,7 @@ import org.springframework.core.env.Environment;
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration(before = MicrometerTracingAutoConfiguration.class)
|
@AutoConfiguration(before = MicrometerTracingAutoConfiguration.class)
|
||||||
@ConditionalOnClass(brave.Tracer.class)
|
@ConditionalOnClass({ Tracer.class, BraveTracer.class })
|
||||||
@EnableConfigurationProperties(TracingProperties.class)
|
@EnableConfigurationProperties(TracingProperties.class)
|
||||||
@ConditionalOnEnabledTracing
|
@ConditionalOnEnabledTracing
|
||||||
public class BraveAutoConfiguration {
|
public class BraveAutoConfiguration {
|
||||||
|
|
@ -135,10 +135,6 @@ public class BraveAutoConfiguration {
|
||||||
return HttpClientHandler.create(httpTracing);
|
return HttpClientHandler.create(httpTracing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
@ConditionalOnClass(BraveTracer.class)
|
|
||||||
static class BraveMicrometer {
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
BraveTracer braveTracerBridge(brave.Tracer tracer, CurrentTraceContext currentTraceContext,
|
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));
|
.withConfiguration(AutoConfigurations.of(BraveAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldSupplyBraveBeans() {
|
void shouldSupplyDefaultBeans() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(context).hasSingleBean(Tracing.class);
|
assertThat(context).hasSingleBean(Tracing.class);
|
||||||
assertThat(context).hasSingleBean(Tracer.class);
|
assertThat(context).hasSingleBean(Tracer.class);
|
||||||
|
|
@ -65,12 +65,16 @@ class BraveAutoConfigurationTests {
|
||||||
assertThat(context).hasSingleBean(HttpTracing.class);
|
assertThat(context).hasSingleBean(HttpTracing.class);
|
||||||
assertThat(context).hasSingleBean(HttpServerHandler.class);
|
assertThat(context).hasSingleBean(HttpServerHandler.class);
|
||||||
assertThat(context).hasSingleBean(HttpClientHandler.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
|
@Test
|
||||||
void shouldBackOffOnCustomBraveBeans() {
|
void shouldBackOffOnCustomBeans() {
|
||||||
this.contextRunner.withUserConfiguration(CustomBraveConfiguration.class).run((context) -> {
|
this.contextRunner.withUserConfiguration(CustomConfiguration.class).run((context) -> {
|
||||||
assertThat(context).hasBean("customTracing");
|
assertThat(context).hasBean("customTracing");
|
||||||
assertThat(context).hasSingleBean(Tracing.class);
|
assertThat(context).hasSingleBean(Tracing.class);
|
||||||
assertThat(context).hasBean("customTracer");
|
assertThat(context).hasBean("customTracer");
|
||||||
|
|
@ -87,22 +91,6 @@ class BraveAutoConfigurationTests {
|
||||||
assertThat(context).hasSingleBean(HttpServerHandler.class);
|
assertThat(context).hasSingleBean(HttpServerHandler.class);
|
||||||
assertThat(context).hasBean("customHttpClientHandler");
|
assertThat(context).hasBean("customHttpClientHandler");
|
||||||
assertThat(context).hasSingleBean(HttpClientHandler.class);
|
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).hasBean("customBraveTracer");
|
||||||
assertThat(context).hasSingleBean(BraveTracer.class);
|
assertThat(context).hasSingleBean(BraveTracer.class);
|
||||||
assertThat(context).hasBean("customBraveBaggageManager");
|
assertThat(context).hasBean("customBraveBaggageManager");
|
||||||
|
|
@ -115,45 +103,25 @@ class BraveAutoConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldNotSupplyBraveBeansIfBraveIsMissing() {
|
void shouldNotSupplyBeansIfBraveIsMissing() {
|
||||||
this.contextRunner.withClassLoader(new FilteredClassLoader("brave")).run((context) -> {
|
this.contextRunner.withClassLoader(new FilteredClassLoader("brave"))
|
||||||
assertThat(context).doesNotHaveBean(Tracing.class);
|
.run((context) -> assertThat(context).doesNotHaveBean(BraveAutoConfiguration.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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldNotSupplyMicrometerBeansIfMicrometerIsMissing() {
|
void shouldNotSupplyBeansIfMicrometerIsMissing() {
|
||||||
this.contextRunner.withClassLoader(new FilteredClassLoader("io.micrometer")).run((context) -> {
|
this.contextRunner.withClassLoader(new FilteredClassLoader("brave"))
|
||||||
assertThat(context).doesNotHaveBean(BraveTracer.class);
|
.run((context) -> assertThat(context).doesNotHaveBean(BraveAutoConfiguration.class));
|
||||||
assertThat(context).doesNotHaveBean(BraveBaggageManager.class);
|
|
||||||
assertThat(context).doesNotHaveBean(BraveHttpServerHandler.class);
|
|
||||||
assertThat(context).doesNotHaveBean(BraveHttpClientHandler.class);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldNotSupplyBraveBeansIfTracingIsDisabled() {
|
void shouldNotSupplyBeansIfTracingIsDisabled() {
|
||||||
this.contextRunner.withPropertyValues("management.tracing.enabled=false").run((context) -> {
|
this.contextRunner.withPropertyValues("management.tracing.enabled=false")
|
||||||
assertThat(context).doesNotHaveBean(Tracing.class);
|
.run((context) -> assertThat(context).doesNotHaveBean(BraveAutoConfiguration.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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
private static class CustomBraveConfiguration {
|
private static class CustomConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
Tracing customTracing() {
|
Tracing customTracing() {
|
||||||
|
|
@ -197,11 +165,6 @@ class BraveAutoConfigurationTests {
|
||||||
return HttpClientHandler.create(httpTracing);
|
return HttpClientHandler.create(httpTracing);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
private static class CustomMicrometerBraveConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
BraveTracer customBraveTracer() {
|
BraveTracer customBraveTracer() {
|
||||||
return mock(BraveTracer.class);
|
return mock(BraveTracer.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue