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:
Dave Syer
2016-02-01 17:00:00 +00:00
parent 065338118b
commit 70b18054e1
16 changed files with 73 additions and 97 deletions

View File

@@ -20,13 +20,17 @@ 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;
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.Span;
import org.springframework.cloud.sleuth.metric.SpanReporterService;
import org.springframework.cloud.sleuth.sampler.PercentageBasedSampler;
import org.springframework.cloud.sleuth.sampler.SamplerConfiguration;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.config.ChannelBindingAutoConfiguration;
import org.springframework.context.annotation.Bean;
@@ -48,12 +52,18 @@ import org.springframework.messaging.support.ChannelInterceptorAdapter;
* @author Dave Syer
*/
@Configuration
@EnableConfigurationProperties(SleuthStreamProperties.class)
@EnableConfigurationProperties({SleuthStreamProperties.class, SamplerConfiguration.class})
@AutoConfigureBefore(ChannelBindingAutoConfiguration.class)
@EnableBinding(SleuthSource.class)
@ConditionalOnProperty(value = "spring.sleuth.stream.enabled", matchIfMissing = true)
public class SleuthStreamAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Sampler defaultTraceSampler(SamplerConfiguration config) {
return new PercentageBasedSampler(config);
}
@Bean
@GlobalChannelInterceptor(patterns = SleuthSource.OUTPUT, order = Ordered.HIGHEST_PRECEDENCE)
public ChannelInterceptor zipkinChannelInterceptor(final SpanReporterService spanReporterService) {