Moves responsibility to import SamplerAutoConfiguration to core
Before, spring-cloud-sleuth-zipkin had to import `SamplerAutoConfiguration` directly to unwind a sampler ordering problem caused by `TraceAutoConfiguration` defining the default `Sampler` bean. This fixes that by moving the default `Sampler` to where it belongs (`SamplerAutoConfiguration`) and having `TraceAutoConfiguration` import the sampling configuration directly as opposed to relying on auto-configuration ordering. Finally it removes the mistake of setting `SamplerAutoConfiguration` as auto-configuration in the first place. The name `SamplerAutoConfiguration` was left alone because changing it would interfere with 3rd party code that formerly imported it to correct this issue in their non-zipkin setups. Fixes #1618
This commit is contained in:
@@ -49,8 +49,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.cloud.sleuth.DefaultSpanNamer;
|
||||
import org.springframework.cloud.sleuth.SpanAdjuster;
|
||||
import org.springframework.cloud.sleuth.SpanNamer;
|
||||
import org.springframework.cloud.sleuth.sampler.SamplerAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -66,6 +68,7 @@ import org.springframework.util.StringUtils;
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.sleuth.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(SleuthProperties.class)
|
||||
@Import(SamplerAutoConfiguration.class)
|
||||
public class TraceAutoConfiguration {
|
||||
|
||||
/**
|
||||
@@ -131,12 +134,6 @@ public class TraceAutoConfiguration {
|
||||
return tracing.tracer();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
Sampler sleuthTraceSampler() {
|
||||
return Sampler.NEVER_SAMPLE;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
SpanNamer sleuthSpanNamer() {
|
||||
|
||||
@@ -20,24 +20,30 @@ import brave.sampler.Sampler;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
* Auto-configuration} to setup sampling for Spring Cloud Sleuth.
|
||||
* {@linkplain Configuration configuration} for {@link Sampler}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.sleuth.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(SamplerProperties.class)
|
||||
// This is not auto-configuration, but it was in the past. Leaving the name as
|
||||
// SamplerAutoConfiguration because those not using Zipkin formerly had to
|
||||
// import this directly. A less precise name is better than rev-locking code.
|
||||
public class SamplerAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
Sampler sleuthTraceSampler() {
|
||||
return Sampler.NEVER_SAMPLE;
|
||||
}
|
||||
|
||||
static Sampler samplerFromProps(SamplerProperties config) {
|
||||
if (config.getRate() != null) {
|
||||
return new RateLimitingSampler(config);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# Auto Configuration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.sleuth.annotation.SleuthAnnotationAutoConfiguration,\
|
||||
org.springframework.cloud.sleuth.sampler.SamplerAutoConfiguration,\
|
||||
org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration,\
|
||||
org.springframework.cloud.sleuth.log.SleuthLogAutoConfiguration,\
|
||||
org.springframework.cloud.sleuth.propagation.SleuthTagPropagationAutoConfiguration,\
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.sampler.SamplerAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.zipkin2.sender.ZipkinSenderConfigurationImportSelector;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -46,8 +45,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
* Auto-configuration} enables reporting to Zipkin via HTTP. Has a default sampler set
|
||||
* from the {@link SamplerAutoConfiguration}
|
||||
* Auto-configuration} enables reporting to Zipkin via HTTP.
|
||||
*
|
||||
* The {@link ZipkinRestTemplateCustomizer} allows you to customize the
|
||||
* {@link RestTemplate} that is used to send Spans to Zipkin. Its default implementation -
|
||||
@@ -56,7 +54,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Spencer Gibb
|
||||
* @author Tim Ysewyn
|
||||
* @since 1.0.0
|
||||
* @see SamplerAutoConfiguration
|
||||
* @see ZipkinRestTemplateCustomizer
|
||||
* @see DefaultZipkinRestTemplateCustomizer
|
||||
*/
|
||||
@@ -66,7 +63,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
"spring.zipkin.enabled" }, matchIfMissing = true)
|
||||
@AutoConfigureBefore(TraceAutoConfiguration.class)
|
||||
@AutoConfigureAfter(name = "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration")
|
||||
@Import({ ZipkinSenderConfigurationImportSelector.class, SamplerAutoConfiguration.class })
|
||||
@Import(ZipkinSenderConfigurationImportSelector.class)
|
||||
public class ZipkinAutoConfiguration {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user