Spring Cloud Sleuth
How to use it
For simple use-case all we need to do is to have Sleuth as dependency in Spring boot project
Since we only output the log to the console then default Spring boot log format and configuration is good enough.
With Sleuth the log looks like bellow
[jpa.demo,0000001234567879,0000000123456789,true] part is added by Sleuth, the format is
- spanId - the id of a specific operation that took place
- appname - the name of the application that logged the span
- traceId - the id of the latency graph that contains the span
- exportable - whether the log should be exported to Zipkin or not. When would you like the span not to be exportable? In the case in which you want to wrap some operation in a Span and have it written to the logs only.
Within Spring Boot projects, adding the Spring Cloud Sleuth library to the classpath will automatically add 2 HTTP headers to all calls:
- X-B3-Traceid Shared by all HTTP calls of a single transaction i.e. the wished-for transaction identifier
- X-B3-Spanid Identifies the work of a single microservice during a transaction
Non-Spring Boot app may need to handle these 2 headers itself.