We're using Spring Boot 2.7.0, Spring cloud 2021.0.3 in GCP and have added these dependencies:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-trace</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>
We have specified the generic sample probability in our properties file like this:
spring.sleuth.sampler.probability=0.1
spring.sleuth.web.skipPattern=(^/admin/.*|. favicon.*|^/ping$)
But for some methods we'd like to use a different sampler probability (e.g. we always want to generate a trace for some methods).
Questions:
- Is it possible to specify the sample rate probability of a method when using annotations from the Spring Sleuth (or related) projects?
- If not, is it possible to specify the sample rate probability of a method programmatically (without annotations)?
- If not, is it possible to configure different sample rates in the spring property file / yaml file?
CodePudding user response:
You can create a bean of type org.springframework.cloud.sleuth.exporter.SpanFilter
. There you have access to FinishedSpan
basing on which you can return true
if you want to export the span or not.