Sets rate limiter sampler as default
fixes gh-1398
This commit is contained in:
@@ -40,9 +40,6 @@ could set `logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
|
||||
|
||||
NOTE: Set `spring.application.name=myService` (for instance) to see the service name as well as the trace and span IDs.
|
||||
|
||||
IMPORTANT: If you use Zipkin, configure the probability of spans exported by setting `spring.sleuth.sampler.probability`
|
||||
(default: 0.1, which is 10 percent). Otherwise, you might think that Sleuth is not working be cause it omits some spans.
|
||||
|
||||
include::intro.adoc[]
|
||||
|
||||
include::features.adoc[]
|
||||
|
||||
@@ -50,9 +50,6 @@ CAUTION: `spring-cloud-sleuth-stream` is deprecated and should no longer be used
|
||||
|
||||
* Spring Cloud Sleuth is https://opentracing.io/[OpenTracing] compatible.
|
||||
|
||||
IMPORTANT: If you use Zipkin, configure the probability of spans exported by setting `spring.sleuth.sampler.probability`
|
||||
(default: 0.1, which is 10 percent). Otherwise, you might think that Sleuth is not working be cause it omits some spans.
|
||||
|
||||
NOTE: The SLF4J MDC is always set and logback users immediately see the trace and span IDs in logs per the example
|
||||
shown earlier.
|
||||
Other logging systems have to configure their own formatter to get the same result.
|
||||
|
||||
@@ -69,6 +69,6 @@ Run this app and then hit the home page. You will see traceId and spanId populat
|
||||
|
||||
IMPORTANT: instead of logging the request in the handler explicitly, you could set `logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG`
|
||||
|
||||
IMPORTANT: If you use Zipkin, configure the probability of spans exported by setting (for `2.0.x`) `spring.sleuth.sampler.probability` or (up till `2.0.x`)`spring.sleuth.sampler.percentage` (default: 0.1, which is 10 percent). Otherwise, you might think that Sleuth is not working because it omits some spans.
|
||||
IMPORTANT: If you use Zipkin (up till 2.1.x), configure the probability of spans exported by setting `spring.sleuth.sampler.percentage` (default: 0.1, which is 10 percent). Otherwise, you might think that Sleuth is not working because it omits some spans. Starting from 2.2.0, Sleuth will default to rate limited sampler. That means that it will sample up to 1000 transactions per second.
|
||||
|
||||
IMPORTANT: Set `spring.application.name=bar` (for instance) to see the service name as well as the trace and span ids.
|
||||
@@ -315,11 +315,10 @@ Span nextSpan(final Request input) {
|
||||
By default Spring Cloud Sleuth sets all spans to non-exportable.
|
||||
That means that traces appear in logs but not in any remote store.
|
||||
For testing the default is often enough, and it probably is all you need if you use only the logs (for example, with an ELK aggregator).
|
||||
If you export span data to Zipkin, there is also an `Sampler.ALWAYS_SAMPLE` setting that exports everything and a `ProbabilityBasedSampler` setting that samples a fixed fraction of spans.
|
||||
If you export span data to Zipkin, there is also an `Sampler.ALWAYS_SAMPLE` setting that exports everything, `RateLimitingSampler` setting that samples X transactions per second (defaults to `1000`) or `ProbabilityBasedSampler` setting that samples a fixed fraction of spans.
|
||||
|
||||
NOTE: The `ProbabilityBasedSampler` is the default if you use `spring-cloud-sleuth-zipkin`.
|
||||
You can configure the exports by setting `spring.sleuth.sampler.probability`.
|
||||
The passed value needs to be a double from `0.0` to `1.0`.
|
||||
NOTE: The `RateLimitingSampler` is the default if you use `spring-cloud-sleuth-zipkin`.
|
||||
You can configure the rate limit by setting `spring.sleuth.sampler.rate`.
|
||||
|
||||
A sampler can be installed by creating a bean definition, as shown in the following example:
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class SamplerAutoConfiguration {
|
||||
|
||||
static Sampler samplerFromProps(SamplerProperties config) {
|
||||
if (config.getRate() != null) {
|
||||
return new RateLimitingSampler(config);
|
||||
if (config.getProbability() != null) {
|
||||
return new ProbabilityBasedSampler(config);
|
||||
}
|
||||
return new ProbabilityBasedSampler(config);
|
||||
return new RateLimitingSampler(config);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -33,7 +33,7 @@ public class SamplerProperties {
|
||||
* sampled. The precision is whole-numbers only (i.e. there's no support for 0.1% of
|
||||
* the traces).
|
||||
*/
|
||||
private float probability = 0.1f;
|
||||
private Float probability;
|
||||
|
||||
/**
|
||||
* A rate per second can be a nice choice for low-traffic endpoints as it allows you
|
||||
@@ -45,13 +45,13 @@ public class SamplerProperties {
|
||||
* (named Reservoir) for this purpose. Brave has taken the same approach via the
|
||||
* {@link brave.sampler.RateLimitingSampler}.
|
||||
*/
|
||||
private Integer rate;
|
||||
private Integer rate = 1000;
|
||||
|
||||
public float getProbability() {
|
||||
public Float getProbability() {
|
||||
return this.probability;
|
||||
}
|
||||
|
||||
public void setProbability(float probability) {
|
||||
public void setProbability(Float probability) {
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,18 @@ import org.junit.Test;
|
||||
public class SamplerAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void should_use_rate_limit_sampler_when_property_set() {
|
||||
public void should_use_probability_sampler_when_property_set() {
|
||||
SamplerProperties properties = new SamplerProperties();
|
||||
properties.setProbability(10f);
|
||||
|
||||
Sampler sampler = SamplerAutoConfiguration.samplerFromProps(properties);
|
||||
|
||||
BDDAssertions.then(sampler).isInstanceOf(ProbabilityBasedSampler.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_use_rate_limiting_sampler_when_probability_not_set() {
|
||||
SamplerProperties properties = new SamplerProperties();
|
||||
properties.setRate(10);
|
||||
|
||||
Sampler sampler = SamplerAutoConfiguration.samplerFromProps(properties);
|
||||
|
||||
@@ -37,8 +46,10 @@ public class SamplerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_use_probability_sampler_when_rate_limiting_not_set() {
|
||||
public void should_use_rate_limiting_sampler_when_both_rate_and_probability_is_set() {
|
||||
SamplerProperties properties = new SamplerProperties();
|
||||
properties.setProbability(10f);
|
||||
properties.setRate(20);
|
||||
|
||||
Sampler sampler = SamplerAutoConfiguration.samplerFromProps(properties);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user