Add Span to Sampler method params
Also allows us to actually create a PercentageBasedSampler (I don't think anyone tried it before) without resorting to lazy beans and proxies. Another freature added here is a default percentage sampler if we know that spans need to be exported (zipkin or stream is present). Fixes gh-138
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
@@ -25,7 +26,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.metric.SpanReporterService;
|
||||
import org.springframework.cloud.sleuth.sampler.PercentageBasedSampler;
|
||||
import org.springframework.cloud.sleuth.sampler.SamplerConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -34,21 +39,22 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@EnableConfigurationProperties({ZipkinProperties.class, SamplerConfiguration.class})
|
||||
@ConditionalOnProperty(value = "spring.zipkin.enabled", matchIfMissing = true)
|
||||
@AutoConfigureBefore(TraceAutoConfiguration.class)
|
||||
public class ZipkinAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ZipkinSpanReporter.class)
|
||||
public ZipkinSpanReporter reporter(SpanReporterService spanReporterService) {
|
||||
ZipkinProperties zipkin = zipkinProperties();
|
||||
public ZipkinSpanReporter reporter(SpanReporterService spanReporterService, ZipkinProperties zipkin) {
|
||||
return new HttpZipkinSpanReporter(zipkin.getBaseUrl(), zipkin.getFlushInterval(),
|
||||
spanReporterService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ZipkinProperties zipkinProperties() {
|
||||
return new ZipkinProperties();
|
||||
@ConditionalOnMissingBean
|
||||
public Sampler defaultTraceSampler(SamplerConfiguration config) {
|
||||
return new PercentageBasedSampler(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -26,8 +26,6 @@ import lombok.Data;
|
||||
@ConfigurationProperties("spring.zipkin")
|
||||
@Data
|
||||
public class ZipkinProperties {
|
||||
// Sample rate = 1.0 means 100% of requests will get traced.
|
||||
private float fixedSampleRate = 1.0f;
|
||||
/** URL of the zipkin query server instance. */
|
||||
private String baseUrl = "http://localhost:9411/";
|
||||
private boolean enabled = true;
|
||||
|
||||
Reference in New Issue
Block a user