Distributed link tracking method and system based on micro service

By generating and passing Span information in a distributed system, link tracking is implemented, the problem of call relationships and performance analysis in complex systems is solved, and the stability and performance of the system are improved.

CN119011377APending Publication Date: 2024-11-22SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411118498.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-15
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

In complex distributed systems, the call relationship between services is complicated, which leads to difficulty in problem positioning and performance analysis, and it is difficult to improve system stability and performance.

Method used

By generating and passing Span information on the client and server side, using the HTTP requested header to carry traceId, spanId, and parentSpanId, combined with SLF4J MDC and Elasticsearch for centralized storage and analysis of link tracking data, and realizing distributed link tracking.

Benefits of technology

Help users to clearly understand the call relationship between services, locate problems and optimize performance bottlenecks, and improve the stability and performance of distributed systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119011377A_ABST
    Figure CN119011377A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of distributed systems, in particular to a distributed link tracking method and system based on micro-service, and the method comprises the following steps: generating Span information in the calling process of a client; checking whether the attributes of X-B3-TraceId, X-B3-SpanId and X-B3-ParentSpanId exist in the Header of the HTTP request or not, and if so, checking whether the attributes of X-B3-TraceId, X-B3-SpanId, the method comprises the following steps: recording attributes of a Span object, including but not limited to traceId, spanId and parent Span Id, so as to facilitate subsequent transmission and log recording; a log framework, such as SLF4JMDC, is called, and traceId, parentitId and spanId of the current Span are injected into the MDC, so that link information can be tracked and printed in a log; the distributed link tracking method and system based on the micro service have the advantages that link tracking of distributed service calling is achieved, a user is helped to clearly know the calling relation between services, and positioning and solving of problems are facilitated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed systems, and in particular to a distributed link tracing method and system based on microservices. Background Art

[0002] With the widespread application of microservice architecture, the complexity of distributed systems is increasing.

[0003] In a complex distributed system, the calling relationships between services are intricate and complex. Once a problem occurs, it is extremely difficult to locate and solve it. At the same time, the performance bottlenecks and calling time of the service are also difficult to accurately analyze and optimize.

[0004] Therefore, an effective distributed link tracing method is needed to improve the stability and performance of distributed systems. Summary of the invention

[0005] The purpose of the present invention is to provide a distributed link tracking method and system based on microservices to solve the problems raised in the above background technology.

[0006] To achieve the above object, the present invention provides the following technical solution: a distributed link tracing method based on microservices, the method comprising the following steps:

[0007] a) During the client call process, Span information is generated; check whether the X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes exist in the HTTP request header;

[0008] If it exists, create a Span object using the Span data in the Header;

[0009] If it does not exist, create a new Span object and generate the corresponding traceId, spanId and parentSpanId;

[0010] b) Record the properties of the Span object, including but not limited to traceId, spanId, and parentSpanId, for subsequent transmission and logging;

[0011] c) Call the logging framework, such as SLF4J MDC, and inject the traceId, parentId, and spanId of the current Span into the MDC to facilitate tracking and printing of link information in the log.

[0012] Preferably, the method further comprises the following steps:

[0013] When the client sends a request to the server, the current Span information is injected into the Header of the HTTP request so that the server can obtain and use the Span information for link tracking; at the same time, the client's request completion timestamp cr is recorded, and the Span information is reported to the monitoring system.

[0014] Preferably, the processing steps on the server side include:

[0015] Extract Span information from the received HTTP request Header, including traceId, spanId, and parentSpanId;

[0016] Create or update the server-side Span object based on the extracted Span information, and record relevant information, such as the client request start timestamp cs;

[0017] Inject the updated Span information into the HTTP Header of the response so that the subsequent call chain can continue to pass the Span information.

[0018] Preferably, it also includes: the client and the server send the Span information generated by each of them to Elasticsearch or other log management systems through HTTP requests to achieve centralized storage and analysis of distributed link tracking data.

[0019] Preferably, the method further includes: creating a TraceFilter, which can intercept all network requests and automatically perform the following operations:

[0020] Check whether the request header contains Span information;

[0021] Create or update the Span object based on the information in the Header;

[0022] Inject Span information into the request header or MDC to record link tracking information in the log;

[0023] When the request is completed, the Span information is reported to the monitoring system or log management system.

[0024] A distributed link tracking system based on microservices, the system includes the following components:

[0025] Span generation module: used to generate Span information when the user calls the microservice client. If the X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes exist in the HTTP request Header, these attributes are directly used to generate the Span object; if they do not exist, a new Span object is created and the corresponding Span ID and Trace ID are generated;

[0026] Span information integration module: Integrates the traceId, parentId, and spanId key information of the generated Span object into the log system, and ensures that the log contains complete link tracking information through the SLF4J MDC mechanism.

[0027] Preferably, it also includes: Span transfer module: when the microservice client initiates a request to the server, the current Span information, including traceId and spanId, is injected into the Header of the HTTP request so that the server can receive the Span information and continue link tracking.

[0028] Preferably, it also includes: a server-side Span processing module: when the server receives a request from a client, it parses the Span information from the Header of the HTTP request, and creates or updates the server-side Span object based on the information, recording key information such as client startTimestamp cs.

[0029] Preferably, it also includes: Span reporting module: both the client and the server include this module, which is used to report the generated Span information to a specified storage system, such as Elasticsearch, and send the Span information to the storage system via the HTTP protocol for centralized storage and management for subsequent analysis and tracking.

[0030] Compared with the prior art, the present invention has the following beneficial effects:

[0031] The microservice-based distributed link tracing method and system proposed in the present invention realize link tracing of distributed service calls, help users clearly understand the calling relationship between services, and facilitate problem location and resolution; through time consumption analysis of sampling requests, help users find performance bottlenecks and optimization points, and improve the performance of distributed systems; based on the data of link tracing and time consumption analysis, link optimization measures are proposed, which further improve the stability and performance of distributed systems. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 It is a timing diagram of the principle of implementation of the present invention;

[0033] Figure 2 This is a system block diagram of the present invention. DETAILED DESCRIPTION

[0034] In order to make the purpose and technical solution of the present invention clearly and completely described, and the advantages more clearly understood, the embodiments of the present invention are further described in detail with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to explain the embodiments of the present invention, and are not used to limit the embodiments of the present invention. All other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0035] In the first embodiment, the present invention provides a technical solution: a distributed link tracing method based on microservices, the method comprising the following steps:

[0036] a) During the client call process, Span information is generated; check whether the X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes exist in the HTTP request header;

[0037] If it exists, create a Span object using the Span data in the Header;

[0038] If it does not exist, create a new Span object and generate the corresponding traceId, spanId and parentSpanId;

[0039] b) Record the properties of the Span object, including but not limited to traceId, spanId, and parentSpanId, for subsequent transmission and logging;

[0040] c) Call the logging framework, such as SLF4J MDC, and inject the traceId, parentId, and spanId of the current span into the MDC to facilitate tracking and printing link information in the log;

[0041] d) further comprising the following steps:

[0042] When the client sends a request to the server, the current Span information is injected into the HTTP request header so that the server can obtain and use the Span information for link tracking; at the same time, the client's request completion timestamp cr is recorded, and the Span information is reported to the monitoring system;

[0043] The server-side processing steps include:

[0044] Extract Span information from the received HTTP request Header, including traceId, spanId, and parentSpanId;

[0045] Create or update the server-side Span object based on the extracted Span information, and record relevant information, such as the client request start timestamp cs;

[0046] Inject the updated Span information into the HTTP Header of the response so that the subsequent call chain can continue to pass the Span information.

[0047] e) also includes: the client and the server send the Span information generated by each of them to Elasticsearch or other log management systems through HTTP requests to achieve centralized storage and analysis of distributed link tracking data.

[0048] f) Also includes: Creating a TraceFilter, which can intercept all network requests and automatically perform the following operations:

[0049] Check whether the request header contains Span information;

[0050] Create or update the Span object based on the information in the Header;

[0051] Inject Span information into the request header or MDC to record link tracking information in the log;

[0052] When the request is completed, the Span information is reported to the monitoring system or log management system.

[0053] Embodiment 2, based on embodiment 1, proposes a distributed link tracking system based on microservices, the system includes the following components:

[0054] Span generation module: used to generate Span information when the user calls the microservice client. If the X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes exist in the HTTP request Header, these attributes are directly used to generate the Span object; if they do not exist, a new Span object is created and the corresponding Span ID and Trace ID are generated;

[0055] Span information integration module: Integrates the traceId, parentId, and spanId key information of the generated Span object into the log system, and ensures that the log contains complete link tracking information through the SLF4J MDC mechanism;

[0056] It also includes: Span transfer module: when the microservice client initiates a request to the server, the current Span information, including traceId and spanId, is injected into the HTTP request header so that the server can receive the Span information and continue link tracking;

[0057] It also includes: Server-side Span processing module: When the server receives a request from a client, it parses the Span information from the HTTP request Header, and creates or updates the server-side Span object based on the information, recording key information such as clientstartTimestamp cs;

[0058] It also includes: Span reporting module: Both the client and the server include this module, which is used to report the generated Span information to the specified storage system, such as Elasticsearch, and send the Span information to the storage system through the HTTP protocol for centralized storage and management for subsequent analysis and tracking.

[0059] Example 3, based on Example 2, proposes a distributed link tracking method based on microservices (see Figure 1 , Figure 2 ):

[0060] 1. When the user calls the client, the client generates Span information and obtains Span data from the Header of the Http Request. If the Header contains X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes, it means that the previous node in the call chain has generated a Span and passed it down. At this time, these Span data can be used directly. Otherwise, create a new Span. Record some Span attributes to save the current Span information, which is needed when the application passes Span information downward. Slf4JMDC will be called here, which will obtain the traceId, parentId, and spanId in the Span and place them in the MDC for log printing.

[0061] 2. When the client calls the server, it sends the Span to the server, injects the Span information into the Http request, sends the Span request, records the client finishTimestamp(cr), and reports the span

[0062] 3. The server receives the Span information from the client and obtains the current Span information. It injects traceId, parentId, and spanId into the Http Header and records Span related information, such as client startTimestamp(cs).

[0063] 4. The client and server send the Span to elasticsearch, which is then reported to elasticsearch via HTTP.

[0064] In summary, a distributed link tracing method based on microservices creates TraceFilter to intercept all network requests. If there is no span information in the request header, a Span object is created, and the span id, trace id and other trace information of the current call chain are generated and recorded in the Http Headers. If there is a span in the header, the Span object is directly created using the data in the header, and then the span id and trace id are set to the MDC of SL4J. In this way, we can see the span information in the log.

[0065] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A distributed link tracking method based on microservices, Features: The method comprises the following steps: a) During the client call process, Span information is generated; check whether the X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes exist in the HTTP request header; If it exists, create a Span object using the Span data in the Header; If it does not exist, create a new Span object and generate the corresponding traceId, spanId and parentSpanId; b) Record the properties of the Span object, including but not limited to traceId, spanId, and parentSpanId, for subsequent transmission and logging; c) Call the logging framework, such as SLF4J MDC, and inject the traceId, parentId, and spanId of the current Span into the MDC to facilitate tracking and printing of link information in the log.

2. According to the microservice-based distributed link tracing method of claim 1, Features: The following steps are also included: When the client sends a request to the server, the current Span information is injected into the Header of the HTTP request so that the server can obtain and use the Span information for link tracking; at the same time, the client's request completion timestamp cr is recorded, and the Span information is reported to the monitoring system.

3. According to the microservice-based distributed link tracing method of claim 2, Features: The server-side processing steps include: Extract Span information from the received HTTP request Header, including traceId, spanId, and parentSpanId; Create or update the server-side Span object based on the extracted Span information, and record relevant information, such as the client request start timestamp cs; Inject the updated Span information into the HTTP Header of the response so that the subsequent call chain can continue to pass the Span information.

4. According to the microservice-based distributed link tracing method of claim 1, Features: Also includes: The client and server send the span information they generate to Elasticsearch or other log management systems through HTTP requests to achieve centralized storage and analysis of distributed link tracking data.

5. According to the microservice-based distributed link tracing method of claim 1, Features: Also includes: Create a TraceFilter, which can intercept all network requests and automatically perform the following operations: Check whether the request header contains Span information; Create or update the Span object based on the information in the Header; Inject Span information into the request header or MDC to record link tracking information in the log; When the request is completed, the Span information is reported to the monitoring system or log management system.

6. A distributed link tracing system based on microservices according to the distributed link tracing method based on microservices according to any one of claims 1 to 5, Features: The system includes the following components: Span generation module: used to generate Span information when the user calls the microservice client. If the X-B3-TraceId, X-B3-SpanId, and X-B3-ParentSpanId attributes exist in the HTTP request Header, these attributes are directly used to generate the Span object; if they do not exist, a new Span object is created and the corresponding Span ID and Trace ID are generated; Span information integration module: Integrates the traceId, parentId, and spanId key information of the generated Span object into the log system, and ensures that the log contains complete link tracking information through the SLF4J MDC mechanism.

7. A distributed link tracking system based on microservices according to claim 6, Features: Also includes: Span transfer module: When the microservice client initiates a request to the server, the current Span information, including traceId and spanId, is injected into the Header of the HTTP request so that the server can receive the Span information and continue link tracking.

8. The microservice-based distributed link tracking system according to claim 6, Features: Also includes: Server-side Span processing module: When the server receives a request from a client, it parses the Span information from the HTTP request Header, and creates or updates the server-side Span object based on the information, recording key information such as client startTimestampcs.

9. The microservice-based distributed link tracking system according to claim 6, Features: Also includes: Span reporting module: Both the client and the server include this module, which is used to report the generated Span information to the specified storage system, such as Elasticsearch, and send the Span information to the storage system through the HTTP protocol for centralized storage and management for subsequent analysis and tracking.

Citation Information

Patent Citations

  • Micro-service full-link tracking method and micro-service architecture

    CN110069354A

  • Micro-service link tracking method and system

    CN112286776A

  • Distributed big data log link tracking method and system under micro-service architecture

    CN112612675A

  • Fault detection method and device and electronic equipment

    CN118042081A

  • Method and system for monitoring execution of user request in distributed system

    US20140082184A1