Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Specify sampler probability using annotations or programmatically using Spring Cloud Sleuth?

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Questions:

  1. Is it possible to specify the sample rate probability of a method when using annotations from the Spring Sleuth (or related) projects?
  2. If not, is it possible to specify the sample rate probability of a method programmatically (without annotations)?
  3. If not, is it possible to configure different sample rates in the spring property file / yaml file?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading