Trace
Last updated
Was this helpful?
Last updated
Was this helpful?
Cloud Trace is a managed distributed tracing system that collects latency data from your applications and displays it in the Google Cloud Console. You can track how requests propagate through your application and receive detailed near real-time performance insights.
uses behind the scenes to instrument and trace your application. In addition, it'll also enhance the log messages to include the current trace context (Trace ID, Span ID) for trace to log correlation.
Add the Spring Cloud GCP Trace starter:
By default, Spring Cloud Sleuth samples only 10% of the requests. I.e., 1 in 10 requests may have traces propagated to the trace server (Cloud Trace). In a non-production environment, you may want to see all of the trace. You can adjust the sampling rate using Spring Cloud Sleuth's properties:
Spring Cloud Sleuth will automatically trace incoming requests from WebMVC, or WebFlux as-is.
Spring Cloud Sleuth will automatically trace incoming messages and handlers when using Spring Integration
Simply create a RestTemplate
or WebClient
bean and Spring Cloud Sleuth will automatically add filters to propagate the trace context via HTTP headers.
Spring Cloud Sleuth automatically adds trace instrumentation to commonly used components, such as , and incoming . See for more details.
If there is a piece of code/method that you want to break out into it's own span, you can use Spring Cloud Sleuth's @NewSpan
annotation. See .
You can associate additional data to a Span (a tag) via annotation. See .
Spring Cloud Sleuth automatically propagates the trace context to a remote system (e.g., via HTTP request, or messaging) when using RestTemplate
, WebClient
, Spring Integration, and more. See for more details.
When using Spring Integration, Spring Cloud Sleuth will automatically propagate trace context via message headers. For example, send a will automatically add trace headers to the Pub/Sub message.
Spring Cloud Sleuth uses , and uses . Over HTTP, it will automatically propagate B3 headers to HTTP headers.
When running your application in Istio, you may need to propagate , such as x-request-id
and x-ot-span-context
.
Spring Cloud Sleuth automatically associate each log message with the trace context (Trace ID, Span ID). When the log message is sent to Cloud Logging, you can then be able to see the log messages alongside the trace itself. See to achieve this.
If you use Istio service mesh, Istio can automatically capture service to service traces. You can use Spring Cloud Sleuth to , without any trace senders:
For in-application trace, you can use .