In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to select Dubbo log link tracking TraceId". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. purpose
The most frequently used means for developers to troubleshoot system problems is to check system logs, but it is still troublesome to use log location in a distributed environment, and it is necessary to connect the context with the help of full-link tracking ID. This paper mainly shares the idea of implementation scheme selection of log link tracking ID based on Spring Boot + Dubbo framework.
The core idea of full link tracing:
A unique traceId is assigned to each request to identify a request link, and the traceId runs through all services throughout the request processing process
Each service / thread has its own spanId identity, which represents one of the processing steps of the request
A request contains a traceId and one or more spanId
Log full link tracing is to add and display traceId and spanId information in each system log.
Second, scheme selection 2.1. Option 1 (apm-toolkit)
This is a log plug-in for SkyWalking, through which you can output traceId in the log
2.1.1. Mode of use
To configure dependencies, add the following to the pom file
Org.apache.skywalking apm-toolkit-logback-1.x 8.1.0
Configure the log template to modify the encoder of the Appender element in the logback-spring.xml file to the following
% d {yyyy-MM-dd HH:mm:ss.SSS} [% tid] [% thread]%-5level% logger {35} -% msg%n
Ps: the content in pattern is modified as needed, where% tid is equivalent to traceId. By default, TID:N/An is generated and displayed when a request is called.
2.1.2. Summary
Advantages: no coding, no business intrusion, and can quickly locate the calling relationship of various interfaces with the ID in the graphical interface of SkyWalking.
Disadvantages: strong coupling SkyWalking will take effect.
You must add a javaagent for sk
The SkyWalking server must be deployed
2.2. Option 2 (sleuth)
Sleuth is one of the components of Spring Cloud. It implements a distributed tracking solution for Spring Cloud, which is compatible with Zipkin,HTrace and other log tracking systems.
2.2.1. Mode of use
To configure the parent dependency, add the following content management version number to the pom file
Org.springframework.cloud spring-cloud-sleuth 2.2.4.RELEASE pom import
To configure dependencies, add the following to the pom file
Org.springframework.cloud spring-cloud-starter-sleuth
To adapt to dubbo, to make sleuth support dubbo framework, you need to add the following two steps:
First add plug-in dependencies for dubbo
Io.zipkin.brave brave-instrumentation-dubbo-rpc 5.12.6
Configure dubbo filter
Dubbo: provider: filter: tracing consumer: filter: tracing
Configure the log template to modify the encoder of the Appender element in the logback-spring.xml file to the following
% d {yyyy-MM-dd HH:mm:ss.SSS} [% X {X-B3-TraceId},% X {X-B3-SpanId}] [% thread]%-5level% logger {35} -% msg%n utf-8
Ps: content in pattern is modified on demand, where% X {X-B3-TraceId} is traceId,%X {X-B3-SpanId} is spanId
2.2.2. Summary
Advantages: no business intrusion, rich plug-ins for expansion, including scheduled tasks, MQ and so on.
Cons: brave-instrumentation-dubbo-rpc does not support dubbo 2.7.x requires self-developed plug-ins.
2.3. Plan 3 (self-research) 2.3.1. No intrusion increases traceId
Using Logback's MDC mechanism, add the traceId identity to the log template with a value of% X {traceId}
System entry (api gateway) creates the value of traceId
Use MDC to save traceId
Modify logback profile template format to add identity X {traceId}
MDC (Mapped Diagnostic Context, mapping debug context) is a function provided by log4j and logback to facilitate logging under multithreaded conditions.
2.3.2. Transfer across threads
Solve the problem of traceId cross-thread loss
Because ThreadLocal is used internally in MDC, only this thread is valid, and the values in child threads and downstream service MDC will be lost.
You need to solve the problem of passing between the various thread pools of Spring and the parent and child threads of asynchronous methods.
Solution: rewrite a MDCAdapter to replace the original ThreadLocal object with Ali's TransmittableThreadLocal to solve the problem of passing values between parent and child processes of various thread pools (ExecutorService / ForkJoinPool / TimerTask).
You need to use TtlRunnable and TtlCallable to modify the Runnable and Callable of the incoming thread pool
2.3.3. Cross-process delivery
Resolve the problem of traceId cross-process loss
The dubbo service uses org.apache.dubbo.rpc.Filter to create a filter for traceId delivery
Service consumer: responsible for delivering link tracking ID
Service provider: responsible for receiving ID and saving it to MDC
2.3.4. Summary
Advantages: no intrusion, minimum dependence, flexible expansion and strong adaptability.
Disadvantages: need to implement on their own, there is a lot of development workload.
Third, summarize the scheme development workload, maintainability, intrusive performance, apm-toolkit, no low business, no intrusion, sleuth, medium business, no intrusion, high business, high business, no invasion, high "Dubbo log link tracking TraceId how to choose", thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.