This is the 24th day of my participation in Gwen Challenge
preface
As the number of services increases, the relationship between them becomes more complex: A->B; B->C; C->D; D->A+B….. There are so many services, when a service has problems, we can know that the service has problems, but the problem is in the service itself, or the next service in the service invocation, sorting out the relationship between services, locating the problem becomes very difficult, at this time, it appears in the lights dim ————Spring Cloud Sleuth
What is Spring Cloud Sleuth?
Spring Cloud Sleuth provides Spring Boot automatic configuration for distributed tracing, Sleuth configuring everything you need to get started. This includes where to report trace data (span), how much trace to keep (samples), whether to send remote fields (luggage), and which libraries to track. ———— from the official website
- Spring Cloud Sleuth provides a complete set of service tracking solutions
- Provides tracking solutions in distributed systems and supports Zipkin compatibility
What components can Spring Cloud Sleuth track?
- async
- Hystrix
- Messaging: The principle of message can be referred to
- websocket
- rxjava
- scheduling
- Web (Spring MVC Controller, Servlet)
- Webclient (Spring RestTemplate)
- Feign
- Zuul
Spring Cloud Sleuth implementation logic?
- Span: indicates the source of the call link. Generally speaking, span is a request information
- Trace: A tree-like Span collection that represents a call link and has a unique identifier
- Annotation: Used to record the presence of an event in a timely manner
- Client Sent – The Client sends a request
- Server Received – The Server receives the request and is ready to start processing it (adding the Client Sent time can calculate the network latency)
- Server Sent – annotation indicating the completion of the request processing (add Server Received time to calculate the request processing time to the Server)
Indicates a request link. A link is uniquely identified by tracing ld. A Span identifies the request information that is initiated– A link is uniquely identified by tracing ld. A Span is used to identify requests. Each Span is associated with the parent ID.
Use? To use Sleuth, you need to combine it with Zipkin Server (do not build Zipkin Server after version F), just run the corresponding version jar package directly
java -jar zipkin-server-2.129.-exec.jar
Copy the code
Implement the PROVIDER service POM to join the dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
Copy the code
Add the corresponding configuration information to the next level of Spring in the YML file
spring:
application:
name: cloud-stream-provider
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
# Sampling rate value is between 0 and 1, 1 means all collection
probability: 1
Copy the code
A Zipkin dependency was added to the Consumer service POM, and a Zipkin configuration was added to the YML file
spring:
application:
name: cloud-stream-consumer
zipkin:
base-url: http://localhost:9411
sleuth:
sampler:
# Sampling rate value is between 0 and 1, 1 means all collection
probability: 1
Copy the code
Then start the service, invoke the Consumer service ————> Provider service, and the corresponding data will appear on the Zipkin page
Zipkin page details
Today’s summary
Today the main understanding of Sleuth role, Sleuth internal principle and the simple use of Sleuth, well, today to this, goodbye!