diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfiguration.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfiguration.java index dbb245584d..7c1d8405e7 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfiguration.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.cloud.sleuth.autoconfig.zipkin2; +import java.net.URI; + import zipkin2.reporter.Sender; import org.springframework.beans.factory.annotation.Autowired; @@ -82,9 +84,11 @@ ZipkinUrlExtractor defaultZipkinUrlExtractor(final ZipkinLoadBalancer zipkinLoad static class ZipkinReactiveConfiguration { @Bean(ZipkinAutoConfiguration.SENDER_BEAN_NAME) - Sender webClientSender(ZipkinProperties zipkin, ZipkinWebClientBuilderProvider zipkinWebClientBuilderProvider) { + Sender webClientSender(ZipkinProperties zipkin, ZipkinWebClientBuilderProvider zipkinWebClientBuilderProvider, + ZipkinUrlExtractor zipkinUrlExtractor) { WebClient.Builder webClientBuilder = zipkinWebClientBuilderProvider.zipkinWebClientBuilder(); - return new WebClientSender(webClientBuilder.build(), zipkin.getBaseUrl(), zipkin.getApiPath(), + URI uri = zipkinUrlExtractor.zipkinUrl(zipkin); + return new WebClientSender(webClientBuilder.build(), uri.toString(), zipkin.getApiPath(), zipkin.getEncoder(), zipkin.getCheckTimeout()); } @@ -94,6 +98,11 @@ ZipkinWebClientBuilderProvider defaultZipkinWebClientProvider() { return WebClient::builder; } + @Bean + ZipkinUrlExtractor defaultZipkinUrlExtractor(final ZipkinLoadBalancer zipkinLoadBalancer) { + return new CachingZipkinUrlExtractor(zipkinLoadBalancer); + } + } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationReactiveTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationReactiveTests.java index a98885fda8..3f973deac3 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationReactiveTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/zipkin2/ZipkinHttpSenderConfigurationReactiveTests.java @@ -49,7 +49,7 @@ void should_work_when_using_web_client_without_the_web_environment() { springApplication.setWebApplicationType(WebApplicationType.REACTIVE); try (ConfigurableApplicationContext context = springApplication.run("--spring.sleuth.noop.enabled=true", - "--server.port=0")) { + "--server.port=0", "--spring.zipkin.base-url=http://cloudUrl")) { then(context.getBean(Sender.class)).isInstanceOf(WebClientSender.class); } }