Don't back off on user-supplied SpanHandlers

Instead the auto-configuration now backs off only on ZipkinSpanHandler.

Closes gh-31273
pull/31327/head
Moritz Halbritter 2 years ago
parent 91bb5aa222
commit d1647cf68c

@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.tracing.zipkin;
import brave.handler.SpanHandler;
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
import zipkin2.Span;
import zipkin2.codec.BytesEncoder;
@ -87,8 +86,8 @@ class ZipkinConfigurations {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(Reporter.class)
SpanHandler zipkinSpanHandler(Reporter<Span> spanReporter) {
return ZipkinSpanHandler.newBuilder(spanReporter).build();
ZipkinSpanHandler zipkinSpanHandler(Reporter<Span> spanReporter) {
return (ZipkinSpanHandler) ZipkinSpanHandler.newBuilder(spanReporter).build();
}
}

@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
import zipkin2.reporter.brave.ZipkinSpanHandler;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinConfigurations.BraveConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
@ -44,28 +45,38 @@ class ZipkinConfigurationsBraveConfigurationTests {
@Test
void shouldSupplyBeans() {
this.contextRunner.withUserConfiguration(ReporterConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(SpanHandler.class));
.run((context) -> assertThat(context).hasSingleBean(ZipkinSpanHandler.class));
}
@Test
void shouldNotSupplySpanHandlerIfReporterIsMissing() {
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(SpanHandler.class));
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ZipkinSpanHandler.class));
}
@Test
void shouldNotSupplyIfZipkinReporterBraveIsNotOnClasspath() {
this.contextRunner.withClassLoader(new FilteredClassLoader("zipkin2.reporter.brave"))
.withUserConfiguration(ReporterConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(SpanHandler.class));
.run((context) -> assertThat(context).doesNotHaveBean(ZipkinSpanHandler.class));
}
@Test
void shouldBackOffOnCustomBeans() {
this.contextRunner.withUserConfiguration(CustomConfiguration.class).run((context) -> {
assertThat(context).hasBean("customSpanHandler");
assertThat(context).hasSingleBean(SpanHandler.class);
});
this.contextRunner.withUserConfiguration(ReporterConfiguration.class, CustomConfiguration.class)
.run((context) -> {
assertThat(context).hasBean("customZipkinSpanHandler");
assertThat(context).hasSingleBean(ZipkinSpanHandler.class);
});
}
@Test
void shouldSupplyZipkinSpanHandlerWithCustomSpanHandler() {
this.contextRunner.withUserConfiguration(ReporterConfiguration.class, CustomSpanHandlerConfiguration.class)
.run((context) -> {
assertThat(context).hasBean("customSpanHandler");
assertThat(context).hasSingleBean(ZipkinSpanHandler.class);
});
}
@Configuration(proxyBeanMethods = false)
@ -82,6 +93,17 @@ class ZipkinConfigurationsBraveConfigurationTests {
@Configuration(proxyBeanMethods = false)
private static class CustomConfiguration {
@Bean
@SuppressWarnings("unchecked")
ZipkinSpanHandler customZipkinSpanHandler() {
return (ZipkinSpanHandler) ZipkinSpanHandler.create(Mockito.mock(Reporter.class));
}
}
@Configuration(proxyBeanMethods = false)
private static class CustomSpanHandlerConfiguration {
@Bean
SpanHandler customSpanHandler() {
return Mockito.mock(SpanHandler.class);

Loading…
Cancel
Save