Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud Sleuth + log4j2

Some of my microservices use log4j2 as logger. Spring cloud Sleuth has support for logback. How can I use Sleuth to get distributed tracing in this scenario. I understand to use sleuth with log4j2, I have to implement certain class. I tried this but no luck. Please help

like image 396
barun Avatar asked Feb 13 '18 19:02

barun


People also ask

What is Spring Cloud sleuth and how does it work?

Underneath, Spring Cloud Sleuth is a layer over a Tracer library named Brave. Sleuth configures everything you need to get started. This includes where trace data (spans) are reported to, how many traces to keep (sampling), if remote fields (baggage) are sent, and which libraries are traced.

How to use Spring Cloud sleuth and Zipkin to trace logs?

To resolve these issues we make use of Spring Cloud Sleuth and Zipkin Spring Cloud Sleuth is used to generate and attach the trace id, span id to the logs so that these can then be used by tools like Zipkin and ELK for storage and analysis Zipkin is a distributed tracing system.

How does Log4j work with Spring Cloud config?

If the monitor interval is zero then Log4j will listen for notifications from Spring Cloud Config and will check for configuration changes each time an event is generated. If the monitor interval is less than zero Log4j will not check for changes to the logging configuration.

How does Spring Cloud sleuth use brave for tracing?

Starting with version 2.0.0, Spring Cloud Sleuth uses Brave as the tracing library that adds unique ids to each web request that enters our application. Furthermore, the Spring team has added support for sharing these ids across thread boundaries. Traces can be thought of like a single request or job that is triggered in an application.


1 Answers

Sleuth puts the traceId and spanId in the MDC(Mapped Diagnostic Context).

You can use %X to check the MDC key value pairs, and Sleuth related keys are traceId, spanId, parentId, spanExportable.

To simulate the logback default style, just maunally add below snippet into your PatternLayout:

[${APP_NAME},%X{traceId},%X{spanId},%X{spanExportable}]

${APP_NAME} is just your spring:application:name.

like image 148
xuanzhui Avatar answered Sep 16 '22 11:09

xuanzhui