All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mework.cloud.spring-cloud-sleuth-docs.3.1.7.source-code.sagan-boot.adoc Maven / Gradle / Ivy

Add Sleuth to your classpath:

Maven

```xml

    
        
            org.springframework.cloud
            spring-cloud-dependencies
            ${release.train.version}
            pom
            import
        
    


    
        org.springframework.cloud
        spring-cloud-starter-sleuth
    

```

Gradle

```groovy
buildscript {
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
    }
}

apply plugin: "io.spring.dependency-management"

dependencyManagement {
     imports {
          mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}"
     }
}
dependencies {
    compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
}
```

As long as Spring Cloud Sleuth is on the classpath any Spring Boot application will generate trace data:

```java
@SpringBootApplication
@RestController
public class Application {

  private static Logger log = LoggerFactory.getLogger(DemoController.class);

  @RequestMapping("/")
  public String home() {
    log.info("Handling home");
    return "Hello World";
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}
```

Run this app and then hit the home page.
You will see traceId and spanId populated in the logs.
If this app calls out to another one (e.g. with `RestTemplate`) it will send the trace data in headers and if the receiver is another Sleuth app you will see the trace continue there.

* Instead of logging the request in the handler explicitly, you could set `logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG`
* Sleuth defaults to a rate limited sampler.
That means that it will sample up to 1000 transactions per second.
* Set `spring.application.name=bar` (for instance) to see the service name as well as the trace and span ids.




© 2015 - 2024 Weber Informatics LLC | Privacy Policy