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', version: '1.0.0.M1'
}
This starter uses Spring Cloud Sleuth and provides a SpanReporter
that sends the Sleuth’s trace information to Stackdriver Trace.
All configurations are optional. You can override a number of default configuration values in addition to the core
spring.cloud.gcp.project-id
and spring.cloud.gcp.credentials.location
.
By default, this starter will send trace asynchronously using a flushable trace consumer that auto-flushes when its buffered trace messages exceed its buffer size or have been buffered for longer than its scheduled delay.
The following properties are optional:
# Number of threads to use by the underlying gRPC channel to send the trace request to Stackdriver spring.cloud.gcp.trace.executor-threads=[NUMBER_OF_SENDER_THREADS] # Buffer size, defaults to 1% of Runtime.totalMemory(), traces will be flushed to Stackdriver when buffered trace # messages exceed this size. spring.cloud.gcp.trace.buffer-size-bytes=[BUFFER_SIZE_BYTES] # Buffered trace messages will be flushed to Stackdriver when buffered longer than scheduled delays (in seconds). # Default is 10 seconds spring.cloud.gcp.trace.scheduled-delay-seconds=[SCHEDULED_DELAY_SECONDS] # GCP project ID Trace is served from spring.cloud.gcp.trace.project-id=[TRACE_GCP_PROJECT_ID] # Credentials for the trace service spring.cloud.gcp.trace.credentials.location=[CREDENTIALS_FILESYSTEM_LOCATION] spring.cloud.gcp.trace.credentials.scope=[COMMA_DELIMITED_SCOPE_LIST]
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.percentage=1 # Send 100% of the request traces to Stackdriver. spring.sleuth.web.skipPattern=(^cleanup.*|.+favicon.*) # Ignore some URL paths
Stackdriver Trace requires the use of 128-bit Trace ID. This starter ignores spring.sleuth.traceId128
property
and it’ll always uses 128-bit Trace ID.
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.