Spring Cloud Sleuth is an instrumentation framework for Spring Boot applications. It captures trace informations and can forward traces to services like Zipkin for storage and analysis.
Google Cloud Platform provides its own managed distributed tracing service called Stackdriver Trace. Instead of running and maintaining your own Zipkin instance and storage, you can use Stackdriver Trace to store traces, view trace details, generate latency distributions graphs, and generate performance regression reports.
This Spring Cloud GCP starter can forward Spring Cloud Sleuth traces to Stackdriver Trace without an intermediary Zipkin server.
Maven coordinates, using Spring Cloud GCP BOM:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-starter-trace</artifactId> </dependency>
Gradle coordinates:
dependencies { compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-trace' }
You must enable Stackdriver Trace API from the Google Cloud Console in order to capture traces. Navigate to the Stackdriver Trace API for your project and make sure it’s enabled.
![]() | Note |
---|---|
If you are already using a Zipkin server capturing trace information from multiple platform/frameworks, you also use a Stackdriver Zipkin proxy to forward those traces to Stackdriver Trace without modifying existing applications. |
Spring Boot Starter for Stackdriver Trace uses Spring Cloud Sleuth and auto-configures a Reporter that sends the Sleuth’s trace information to Stackdriver Trace.
This starter will send traces asynchronously using a buffered trace consumer that auto-flushes when its buffered trace messages exceed its buffer size or have been buffered for longer than its scheduled delay.
There are several parameters you can use to tune the Stackdriver Trace adapter. All configurations are optional:
Name | Description | Optional | Default value |
| Auto-configure Spring Cloud Sleuth to send traces to Stackdriver Trace. | Yes |
|
| Number of threads to use by the underlying gRPC channel to send the trace request to Stackdriver. | Yes |
|
| Buffer size in bytes. Traces will be flushed to Stackdriver when buffered trace messages exceed this size. | Yes | 1% of Runtime.totalMemory() |
| Buffered trace messages will be flushed to Stackdriver when buffered longer than scheduled delays (in seconds) even if the buffered message size didn’t exceed the buffer size. | Yes |
|
| Overrides the project ID from the Spring Cloud GCP Module | Yes | |
| Overrides the credentials location from the Spring Cloud GCP Module | Yes | |
| Overrides the credentials scopes from the Spring Cloud GCP Module | Yes |
You can use core Spring Cloud Sleuth properties to control Sleuth’s sampling rate, etc. Read Sleuth documentation for more information on Sleuth configurations.
For example, when you are testing to see the traces are going through, you can set the sampling rate to 100%.
spring.sleuth.sampler.probability=1 # Send 100% of the request traces to Stackdriver. spring.sleuth.web.skipPattern=(^cleanup.*|.+favicon.*) # Ignore some URL paths.
Spring Cloud GCP Trace does override some Sleuth configurations:
StackdriverHttpClientParser
and StackdriverHttpServerParser
by default to populate Stackdriver
related fields.Logs can also be associated with traces. See Stackdriver Logging Support for how to configure logging such that it carries Trace ID metadata.