Skip to content

Commit

Permalink
Fixes lack of load balanced URL extraction for Zipkin and Reactor
Browse files Browse the repository at this point in the history
fixes gh-2339
  • Loading branch information
marcingrzejszczak committed Feb 9, 2024
1 parent c5b82d4 commit f8d88bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand All @@ -94,6 +98,11 @@ ZipkinWebClientBuilderProvider defaultZipkinWebClientProvider() {
return WebClient::builder;
}

@Bean
ZipkinUrlExtractor defaultZipkinUrlExtractor(final ZipkinLoadBalancer zipkinLoadBalancer) {
return new CachingZipkinUrlExtractor(zipkinLoadBalancer);
}

}

@Configuration(proxyBeanMethods = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f8d88bb

Please sign in to comment.