Network request tracing method and apparatus, electronic device and storage medium
Patent Information
- Authority / Receiving Office
- EP · EP
- Patent Type
- Applications
- Current Assignee / Owner
- SIEMENS AG
- Filing Date
- 2023-09-28
- Publication Date
- 2026-07-01
Smart Images

Figure CN2023122845_03042025_PF_FP_ABST
Abstract
Description
NETWORK REQUEST TRACING METHOD AND APPARATUS, ELECTRONIC DEVICE AND STORAGE MEDIUMTECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computers, in particular to a network request tracing method and apparatus, an electronic device and a storage medium.BACKGROUND
[0002] In a distributed service architecture, for a network request, multiple services may be called to process the request to get a final result. In this process, the communication between every two services is a separate network request, and a failure or slow processing of any service used for processing the network request may have an impact on a front end. In order to easily find out which service experiences problems in the process of network request processing, a common solution is to trace a network request. By tracing the network request, a log during request processing may be queried, and then the problematic service can be determined based on the log.
[0003] At present, network requests are traced through distributed link tracing services, such as OpenTelemetry.
[0004] However, application interfaces provided by the existing distributed link tracing services are not oriented to real-time applications, which leads to poor time efficiency in tracing real-time applications.SUMMARY
[0005] In view of the above, the present disclosure provides a network request tracing method and apparatus, an electronic device and a storage medium, which can improve the time efficiency of tracing real-time applications.
[0006] In accordance with a first aspect of the present disclosure, an embodiment provides a network request tracing method, including: inserting a trace code into a service code of an application to obtain an application code, where the application is configured to process a network request; compiling the application code to obtain an executable file; acquiring span information collected by a tracing program corresponding to the trace code during execution of the executable file, where the span information includes information about service calling; generating a target span corresponding to the application according to the acquired span information; and sending the target span to a trace tool, so that the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request.
[0007] In a possible implementation, the inserting a trace code into a service code of an application to obtain an application code includes: pre-compiling the service code of the application to obtain a pre-compiled code; checking the pre-compiled code based on a preset checking rule; in response to the pre-compiled code meeting the checking rule, inserting the trace code into the pre-compiled code to obtain the application code.
[0008] Before the trace code is inserted into the service code, the pre-compiled code (pre-compiled service code) is checked based on a preset checking rule. If the checking result indicates that the pre-compiled code has been set completely and meets the condition for inserting the trace code, the trace code is inserted into the pre-compiled code to obtain an application code. Then, the application code is compiled to obtain an executable file, and it is ensured that both the application and the tracing program can run normally when the executable file is executed, thereby ensuring the reliability of the application in processing the network request and the reliability of the tracing program in tracing the application.
[0009] In a possible implementation, the checking the pre-compiled code based on a preset checking rule includes: checking, based on a configuration rule comprised in the preset checking rule, the pre-compiled code for at least some of : a level of a function called by the application, a type of the called function, a real-time configuration code, and a maximum response time of the application; in response to the pre-compiled code meeting the configuration rule, checking a maximum response time of function calls of the pre-compiled code based on a semantic rule comprised in the checking rule; and in response to the pre-compiled code meeting the semantic rule, determining that the pre-compiled code meets the checking rule.
[0010] The checking rule includes a configuration rule and a semantic rule. Whether the code content of the service code is complete can be checked according to the configuration rule, and whether the code format of the service code is complete can be checked according to the semantic rule. After checking the pre-compiled code based on the configuration rule and the semantic rule, if the pre-compiled code meets the configuration rule and the semantic rule, the trace code is inserted into the pre-compiled code to obtain an application code, and if the pre-compiled code does not meet at least one of the configuration rule and the semantic rule, the trace code is not inserted into the pre-compiled code. Thus, it is ensured that the application can normally process the network request when the application is run based on the obtained application code, and that the tracing program can effectively trace the process of the application processing the network request.
[0011] In a possible implementation, the compiling the application code includes: checking the application code based on the configuration rule and the semantic rule respectively; checking, based on a preset trace rule, the application code for at least some of : whether a root function is called, whether a trace for a function call is comprehensive, and whether the trace is completed when an error is handled; and in response to the application code meeting the configuration rule, the semantic rule and the trace rule, compiling the application code.
[0012] Because inserting the trace code may change the content and format of the pre-compiled code, the application code is checked based on the configuration rule and the semantic rule before being complied to ensure that the application code is complete in content and correct in format. The application code is checked based on the trace rule to determine whether the trace code can trace the application normally. After the application code meets the configuration rule, the semantic rule and the trace rule, the application code is compiled to obtain an executable file, and it is ensured that the application can normally process the network request when the executable file is executed, and the tracing program can trace the application accurately in real time.
[0013] In a possible implementation, the inserting a trace code into the pre-compiled code to obtain an application code includes: extracting, according to a pre-created template file, an attribute tag of a function from the pre-compiled code; generating a trace code according to the attribute tag; and inserting the trace code into the pre-compiled code in a corresponding position to obtain the application code.
[0014] A trace code for the application is automatically generated by a preset template file, and the generated trace code is inserted into the pre-compiled code in a corresponding position to obtain an application code including the service code and the trace code. In this way, the automatic generation and insertion of the trace code are achieved, and the labor intensity of the developer in the process of application tracing is reduced.
[0015] In a possible implementation, the tracing program is configured to call span carriers from a span pool during execution of the executable file, and store the collected information about function calls into the called span carriers to obtain the span information, wherein the span pool includes multiple span carriers, and the span pool is created when the executable file starts to be executed.
[0016] Creating span carriers during runtime of the tracing program will occupy a large amount of memory. Therefore, when the executable file starts to be executed, that is, when the application initiates, a span pool is created. When needing to generate span information, the tracing program calls span carriers from the span pool to generate the span information, instead of temporarily generating span carriers when generating span information, which reduces the memory consumption in the running process of a span program and ensures that the application has enough memory resources to process the network request, thereby ensuring the real-time efficiency of processing the network request by the application.
[0017] In a possible implementation, generating a target span corresponding to the application according to the acquired span information includes: in response to one piece of span information being acquired, determining the span information as a target span corresponding to the application; and in response to multiple pieces of span information being acquired, nesting the multiple pieces of span information according to a service calling relationship recorded in the span information to obtain a target span.
[0018] The tracing program traces the function / service call process of the application, generates span information and outputs the generated span information. After acquiring the span information output by the tracing program, the span collector sends the span information to the span processor which serves as a trace context holder and nested span generator, and the span processor outside the application processes the span information to obtain a target span (nested span) . The tracing program inside the application only generates span information and sends the span information to the span processor, which reduces the workload of the application in processing the span information and allows the application to focus on processing the network request, thereby ensuring the real-time efficiency of the application in processing the network request.
[0019] In accordance with a second aspect of the present disclosure, an embodiment provides a network request tracing apparatus, including: an insertion unit configured to insert a trace code into a service code of an application to obtain an application code, where the application is configured to process a network request; a compilation unit configured to compile the application code to obtain an executable file; an acquisition unit configured to acquire span information collected by a tracing program corresponding to the trace code during execution of the executable file, where the span information includes information about service calling; a generation unit configured to generate a target span corresponding to the application according to the acquired span information; and an output unit configured to send the target span to a trace tool, so that the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request.
[0020] In accordance with a third aspect of the present disclosure, an embodiment provides an electronic device, including: a processor, a memory, a communication interface and a bus, where the processor, the memory and the communication interface communicate with each other through the bus; and the memory is configured to store at least one executable instruction which, when executed by the processor, causes the processor to perform an operation corresponding to the network request tracing method in the first aspect described above.
[0021] In accordance with a fourth aspect of the present disclosure, an embodiment provides a computer-readable storage medium, storing a computer instruction which, when executed by a processor, causes the processor to perform the network request tracing method in the first aspect described above.
[0022] In accordance with a fifth aspect of the present disclosure, an embodiment provides a computer program product tangibly stored on a computer-readable medium and including a computer-executable instruction which, when executed by at least one processor, causes the at least one processor to perform the network request tracing method in the one aspect described above.
[0023] In the above technical solutions, the application code includes a service code and a trace code. The application code is compiled to obtain an executable file, and a tracing program corresponding to the trace code can collect span information during execution of the executable file. After the span information collected by the tracing program is acquired, a target span corresponding to the application can be generated according to the span information, and the target span is sent to a trace tool. The trace tool can generate trace information corresponding to the network request according to the target spans of multiple applications for processing the request. The tracing program collects and outputs span information, and the span information is processed outside the application, such that the preceding span information can be synchronously processed while the tracing program collects the succeeding span information, and the application does not need to process the span information after all the span information is collected, thus saving the time for processing the span information, and improving the time efficiency of tracing network requests of real-time applications.BRIEF DESCRIPTION OF DRAWINGS
[0024] Fig. 1 is a flowchart of a network request tracing method according to an embodiment of the present disclosure;
[0025] Fig. 2 is a schematic diagram of a service calling relationship according to an embodiment of the present disclosure;
[0026] Fig. 3 is a flowchart of a pre-compiled code checking method according to an embodiment of the present disclosure;
[0027] Fig. 4 is a schematic diagram of a network request tracing apparatus according to an embodiment of the present disclosure; and
[0028] Fig. 5 is a schematic diagram of an electronic device according to an embodiment of the present disclosure.
[0029] List of reference numerals:
[0030] 100: Network request tracing method 300: Pre-compiled code checking method
[0031] 400: Network request tracing apparatus
[0032] 500: Electronic device 401: Insertion unit 402: Compilation unit
[0033] 403: Acquisition unit 404: Generation unit 405: Output unit
[0034] 502: Processor 504: Communication interface 506: Memory
[0035] 508: Bus 510: Program
[0036] 101: Insert a trace code into a service code of an application to obtain an application code
[0037] 102: Compile the application code to obtain an executable file
[0038] 103: Acquire span information collected by a tracing program corresponding to the trace code during execution of the executable file
[0039] 104: Generate a target span corresponding to the application according to the acquired span information
[0040] 105: Send the target span to a trace tool, so that the trace tool generates trace information according to multiple target spans.
[0041] 301: Check a pre-compiled code according to a configuration rule
[0042] 302: Judge whether the pre-compiled code meets the configuration rule
[0043] 303: Check the pre-compiled code according to a semantic rule
[0044] 304: Judge whether the pre-compiled code meets the semantic rule
[0045] 305: Determine that the pre-compiled code meets a checking rule
[0046] 306: Generate an error report and outputting the error reportDESCRIPTION OF EMBODIMENTS
[0047] To make those having ordinary skills in the art better understand the technical solutions in the embodiments of the present disclosure, the technical solutions in the embodiments of the present disclosure will be described clearly and completely below in conjunction with the figures in the embodiments of the present disclosure. Obviously, the described embodiments are only some of the embodiments of the present disclosure, but not all of the embodiments. Based on some of the embodiments of the present disclosure, all other embodiments obtained by those having ordinary skills in the existing technology shall belong to the protection scope of the embodiments of the present disclosure.
[0048] In a distributed service architecture, the processing of a network request involves a plurality of network nodes. For example, a client sends a data query request to a server, the server sends a data reading request to a database according to the data query request, and the database returns data to the client according to the data reading request. The network request cause the network nodes to process the network request by calling services of the network nodes, and the network nodes can provide one or more services to process the network request. A failure or slow response of any service used for processing the network request will result in a failure of normal implementation of the network request. By tracing the network request, a log during network request processing can be obtained, and then the service that experiences problems can be determined based on the log, thus facilitating operation and maintenance of the distributed service architecture. At present, network requests are traced through distributed link tracing services, such as OpenTelemetry. However, application interfaces of these distributed link tracing services are not oriented to real-time applications, which have strict requirements for time latency, causing unsatisfactory time efficiency in tracing network requests of real-time applications, and making it impossible to determine the service that experiences problems through the tracing result.
[0049] In an embodiment of the present disclosure, a trace code is inserted into a service code of an application, a tracing program corresponding to the trace code can collect span information during processing of a network request by the application, the span information including information about service calling. After the span information collected by the tracing program is acquired, a target span corresponding to a current application is generated according to the span information, and the target span is sent to a trace tool, the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request. In this way, the service that experiences problems can be determined according to the trace information. The tracing program collects and outputs the span information, and the preceding span information collected by the tracing program is synchronously nested to obtain a target span while the succeeding span information is collected by the tracing program, and the application does not need to nest the span information after all the span information is collected, thus saving the time for nesting the span information, and improving the time efficiency of tracing network requests of real-time applications.
[0050] The network request tracing method and apparatus, electronic device and storage medium provided by the embodiments of the present disclosure will be described in detail in conjunction with the drawings.
[0051] Network Request Tracing Method
[0052] Fig. 1 is a flowchart of a network request tracing method according to an embodiment of the present disclosure. As shown in Fig. 1, the network request tracing method 100 includes following steps.
[0053] In a step of 101, a trace code is inserted into a service code of an application to obtain an application code.
[0054] The application is software deployed on a network node and configured to process a network request. For a certain network request, a plurality of network nodes involved in processing the network request each have an application deployed thereon, and the applications deployed on different network nodes handle the network request at different stages.
[0055] The service code is a core code for the application to implement its functions, that is, respective stages of the network request are handled through the service codes. In the embodiment of the present disclosure, a programming language of the service code is not limited.
[0056] The trace code is a code of a tracing program. After the trace code is inserted into the service code, during processing of the network request by the application, the tracing program can trace the process of the application processing network request to obtain span information. For example, the application provides multiple services, the services call each other during the processing of the network request, and the tracing program can trace a calling time of the services, a caller and a callee of the services, and so on. The trace code has the same encoding language as the service code.
[0057] In a step of 102, the application code is compiled to obtain an executable file.
[0058] The application code includes the service code and the trace code. By compiling the application code, an executable file which is executable by a computer can be obtained. The executable file, when executed by the computer, causes the computer to run the application and the tracing program, to process the network request by the application, and trace the process of the application processing the network request by the tracing program.
[0059] In a step of 103, span information collected by a tracing program corresponding to the trace code is acquired during execution of the executable file.
[0060] During execution of the executable file, the application processes the network request, and the tracing program corresponding to the trace code traces the process of the application processing the network request, and collects span information. The application may process the network request by means of service calling, and the tracing program may trace the process of service calling and collect information about service calling to obtain span information. The services adopted in processing the network request may be various types of functions. The span information may include a span name, time-related data, structured log information and other metadata. The time-related data includes a start time and an end time of a service call, such as the time when a service A calls a service B, the time when the service B returns feedback data to the service A, etc. The other metadata may indicate how services are called, for example, services are called by sending User Datagram Protocol (UDP) messages, Transmission Control Protocol (TCP) messages, etc.
[0061] In a step of 104, a target span corresponding to the application is generated according to the acquired span information.
[0062] Because there may be multiple service calling relationships when the application processes a network message, and there may also be mutual calls between multiple functions within a service, the tracing program can follow calls between services and calls between functions to obtain multiple pieces of span information. In order to determine a service or function that experiences problems in the process of network request processing, a propagation path of the network request between services or functions needs to be determined. Therefore, the obtained multiple pieces of span information need to be processed to obtain a target span corresponding to the application, and the target span can indicate the propagation path of the network request within the application.
[0063] Fig. 2 is a schematic diagram of a service calling relationship according to an embodiment of the present disclosure. As shown in Fig. 2, when the application processes the network request, four services are involved, where a service SA calls a service SB, the service SB calls a service SC, and the service SC calls a service SD. The service SA includes a function FA, a function FB and a function FC.When the service SA processes the network request, the function FA calls the function FB, and the function FB calls the function FC. The tracing program may trace a process of the function FA calling the function FB, a process of the function FB calling the function FC, a process of the service SA calling the service SB, a process of the service SB calling the service SC, and a process of the service SC calling the service SD, and corresponding span information can be generated in each traced process, thus obtaining five pieces of span information.
[0064] When generating target span information according to the span information, multiple pieces of span information may be integrated according to a calling relationship between services and functions to obtain a target span.
[0065] In a step of 105, the target span is sent to a trace tool, so that the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request.
[0066] The target span may indicate information about service calling when the applications process the network request. The network request needs to be processed by multiple applications deployed on a plurality of network nodes. Each application can generate a corresponding target span. After each application sends the generated target span to the trace tool, the trace tool can generate trace information corresponding to the network request according to the received multiple target spans. The trace information can indicate information about service calling in the entire process of network request processing. According to the trace information, a service that experiences problems or has a slow response in the process of network request processing can be determined, thereby providing technical support for the operation and maintenance of the distributed service architecture.
[0067] The trace tool is configured to generate trace information according to the target span, and the type of the trace tool is not limited in the embodiment of the present disclosure. However, in order to ensure the time efficiency of tracing real-time applications, the trace tool needs to have desirable real-time efficiency, for example, the trace tool may be a Software Development Kit (SDK) implemented based on an application interface of OpenTelemetry. After the trace tool generates the trace information, the trace information may be displayed through visualization tools, to facilitate users to view the process of network request processing. The visualization tools may be server-side components such as IOWA, Jaeger, Zipkin, and Prometheus.
[0068] In an embodiment of the present disclosure, the application code includes a service code and a trace code. After the application code is compiled to obtain an executable file, a tracing program corresponding to the trace code can collect span information during execution of the executable file. After the span information collected by the tracing program is acquired, a target span corresponding to the application can be generated according to the span information, and the target span is sent to a trace tool. The trace tool can generate trace information corresponding to the network request according to target spans of multiple applications for processing the request. The tracing program collects and outputs the span information, and the span information is processed outside the application, such that the preceding span information can be synchronously processed while the tracing program collects the succeeding span information, and the application does not need to process the span information after all the span informationis collected, thus saving the time for processing the span information, and improving the time efficiency of tracing network requests of real-time applications.
[0069] In a possible implementation, after the tracing program collects span information, the span information collected by the tracing program may be acquired by a remote collector, or the span information collected by the tracing program may be exported through an embedded or local exporter. The remote collector may configure applications, and the collector is completely independent of the applications. The applications generate span information using trace codes, and pour the span information into the collector through http / gRPC, etc. An embedded or local exporter, for example an ostream exporter provided by OpenTelemetry, is used in the applications. The collector or exporter may send the received span information to the trace tool, for the trace tool to perform nesting or other processing on the span information.
[0070] According to actual demands, the remote collector or the embedded or local exporter may be adopted to acquire the span information collected by the tracing program, so as to ensure the applicability of the network request tracing method provided by the present disclosure.
[0071] In an embodiment of the present disclosure, the span information collected by the tracing program may be exported through the remote collector or the embedded or local exporter, and then nesting or other processing may be performed on the span information by the trace tool outside the application. The application focuses on the processing of the network request, thereby improving the real-time efficiency of tracing the network request while ensuring the efficiency of network request processing.
[0072] In a possible implementation, when a trace code is inserted into a service code to obtain an application code, the service code of the application is first pre-compiled to obtain a pre-compiled code, and then the pre-compiled code is checked based on a preset checking rule. If the pre-compiled code meets the checking rule, the trace code is inserted into the pre-compiled code to obtain the application code.
[0073] Before a trace code is inserted into a service code, the service code is pre-compiled to obtain a pre-compiled code, and then the pre-compiled code is checked by a preset checking rule to determine whether the service code has been set and meets the condition for inserting the trace code. After it is determined that the service code meets the checking rule, the trace code is inserted into the pre-compiled code to obtain an application code including the pre-compiled code and the trace code.
[0074] It should be noted that the trace code is usually adopted to trace the service calling process of an application, and the application may make multiple service calls in the process of network request processing, so that the trace code may include multiple code segments which are inserted into the service code in different positions. For example, the trace code is inserted after a service calling code included in the service code.
[0075] In an embodiment of the present disclosure, before the trace code is inserted into the service code, the pre-compiled code (pre-compiled service code) is checked based on a preset checking rule. If the checking result indicates that the pre-compiled code has been set completely and meets the condition for inserting the trace code, the trace code is inserted into the pre-compiled code to obtain an application code. Then, the application code is compiled to obtain an executable file, and it is ensured that both the application and the tracing program can run normally when the executable file is executed, thereby ensuring the reliability of the application in processing the network request and the reliability of the tracing program in tracing the application.
[0076] In a possible implementation, the preset checking rule includes a configuration rule and a semantic rule. The configuration rule is configured to check whether the content of the service code is complete, and the semantic rule is configured to check whether the format of the service code is complete. When the pre-compiled code is checked based on the checking rule, the pre-compiled code may be checked based on the configuration rule and semantic rule sequentially to determine whether the pre-compiled code meets the condition for inserting the trace code. The process of checking the pre-compiled code is described in detail below.
[0077] Fig. 3 is a flowchart of a pre-compiled code checking method according to an embodiment of the present disclosure. As shown in Fig. 3, the pre-compiled code checking method 300 includes following steps.
[0078] In a step of 301, a pre-compiled code is checked based on a configuration rule.
[0079] The checking rule includes a configuration rule and a semantic rule. The pre-compiled code may be checked for at least some of the following checking items based on the configuration rule: a level of a function called by the application, a type of the called function, a real-time configuration code and a maximum response time of the application.
[0080] When the application processes a network message, services are called. If one service includes multiple functions (sub-services) , when the service is called, multiple levels of functions are called inside the service. As shown in Fig. 2, when a service SA is called, the service SA includes a function FA, a function FB and a function FC. When the service SA processes a network request, the function FA calls the function FB, and the function FB calls the function FC, which involves calling of three levels of functions. In order to ensure that the tracing program can correctly trace the function calling process of the application, the configuration rule defines a maximum number of levels of function called by the application. The pre-compiled code is scanned to determine whether the number of levels of function called by the application exceeds the maximum number defined by the configuration rule.
[0081] The configuration rule defines whether the application allows loop function calls. When the pre-compiled code is checked based on the configuration rule, if the application includes loop function calls and the configuration rule does not allow loop function calls, the pre-compiled code does not meet the configuration rule.
[0082] The configuration rule defines that the application needs to include a real-time configuration (scheduler, memory lock) code, to ensure the real-time efficiency of real-time applications. If the application is a real-time application and the application does not include a real-time configuration code, the pre-compiled code does not meet the configuration rule.
[0083] The configuration rule defines a maximum response time of the application. By checking the pre-compiled code, it can be determined whether the response time of the application exceeds the maximum response time defined by the configuration rule. If the response time of the application exceeds the maximum response time defined by the configuration rule, the pre-compiled code does not meet the configuration rule.
[0084] In a step of 302, it is judged whether the pre-compiled code meets the configuration rule, if yes, step 303 is performed, if no, step 306 is performed.
[0085] After scanning the pre-compiled code according to the configuration rule, if the pre-compiled code meets various rules defined by the configuration rule, it is determined that the pre-compiled code meets the configuration rule, and step 303 is performed accordingly. If the pre-compiled code does not meet any one or more rules defined by the configuration rule, it is determined that the pre-compiled code does not meet the configuration rule, and step 306 is performed accordingly.
[0086] In a step of 303, the pre-compiled code is checked based on a semantic rule.
[0087] The semantic rule defines the format of the service code, so it is convenient for the trace code to trace the application and generate span information. At least the maximum response time of function calls of the pre-compiled code can be checked according to the semantic rule.
[0088] A real-time application contains some codes that may cause overtime response. In order to ensure the accuracy of a processing result of the real-time application, functions called by the real-time application need to respond in time, so the real-time application needs to define the maximum response time of function calls. By scanning the pre-compiled code, it can be determined whether the application defines the maximum response time of function calls. If the application does not define the maximum response time of function calls, the pre-compiled code does not meet the semantic rule.
[0089] In a step of 304, it is judged whether the pre-compiled code meets the semantic rule, if yes, step 305 is performed, if no, step 306 is performed.
[0090] After scanning the pre-compiled code according to the semantic rule, if the pre-compiled code meets various rules defined by the semantic rule, it is determined that the pre-compiled code meets the semantic rule, and step 305 is performed accordingly. If the pre-compiled code does not meet any one or more rules defined by the semantic rule, it is determined that the pre-compiled code does not meet the semantic rule, and step 306 is performed accordingly.
[0091] In a step of 305, it is determined that the pre-compiled code meets a checking rule, and a current process is ended.
[0092] After determining that the pre-compiled code meets the configuration rule and semantic rule, it is determined that the pre-compiled code meets the checking rule, and the trace code can be inserted into the pre-compiled code to obtain an application code.
[0093] In a step of 306, an error report is generated and output.
[0094] After determining that the pre-compiled code does not meet the configuration rule or the semantic rule, an error report is generated and displayed to inform a software developer of a problem existing in the application. According to the error report, the software developer can determine which configurations of the service code are missing and which code formats are inaccurate, such that the software developer can correct the service code.
[0095] It should be noted that when checking the pre-compiled code based on the checking rule, it is only one implementation to check the pre-compiled code based on the configuration rule first and then check the pre-compiled code based on the semantic rule. The pre-compiled code may be first checked based on the semantic rule first and then checked based on the configuration rule.
[0096] In an embodiment of the present disclosure, the checking rule includes a configuration rule and a semantic rule. Whether the code content of the service code is complete can be checked according to the configuration rule, and whether the code format of the service code is complete can be checked according to the semantic rule. After checking the pre-compiled code based on the configuration rule and the semantic rule, if the pre-compiled code meets the configuration rule and the semantic rule, the trace code is inserted into the pre-compiled code to obtain an application code, and if the pre-compiled code does not meet at least one of the configuration rule and the semantic rule, the trace code is not inserted into the pre-compiled code. Thus, it is ensured that the application can normally process the network request when the application is run based on the obtained application code, and that the tracing program can effectively trace the process of the application processing the network request.
[0097] In a possible implementation, prior to compiling the application code, the application code can be checked, and after confirming that the application code is correct, the application code is compiled to obtain an executable file.
[0098] When the application code is checked, the application code may be checked based on the configuration rule, the semantic rule, and a trace rule respectively. If the application code meets the configuration rule, the semantic rule and the trace rule, the application code is compiled to obtain an executable file. If the application code does not meet at least one of the configuration rule, the semantic rule, and the trace rule, the application code will not be compiled.
[0099] The checking items included in the configuration rule and semantic rule have been described in the above embodiment. For related contents of checking the application code based on the configuration rule and the semantic rule, reference may be made to the process of checking the pre-compiled code based on the configuration rule and semantic rule in the above embodiment, which will not be repeated here.
[0100] When the application code is checked based on the trace rule, the application code may be checked for at least some of the following items: whether a root function is called, whether a trace for a function call is comprehensive, and whether the trace is completed when an error is handled.
[0101] The trace rule defines that when the application is traced, the root function should not be called by other functions. By scanning the application code, it can be determined whether the root function is called by other functions when the application is traced. If the root function is called by other functions, the application code does not meet the trace rule.
[0102] The trace rule requires that when the application is traced, all the function calls adopted in the process of the application processing the network request should be traced. By scanning the application code, it can be determined whether the trace code can trace all the function calling processes of the application. If the trace code fails to trace any one or more function calling processes of the application, the application code does not meet the trace rule.
[0103] The trace rule requires that when the application handles an error, that is, when an error occurs in the process of network request processing and the application is handling the error, the tracing program needs to stop tracing the application. By scanning the application code, it can be determined whether the trace code stops tracing when the application processes an error. If the trace code does not stop tracing when the application processes an error, the application code does not meet the trace rule.
[0104] In an embodiment of the present disclosure, because inserting the trace code may change the content and format of the pre-compiled code, the application code is checked based on the configuration rule and the semantic rule before being complied to ensure that the application code is complete in content and correct in format. The application code is checked based on the trace rule to determine whether the trace code can trace the application normally. After the application code meets the configuration rule, the semantic rule and the trace rule, the application code is compiled to obtain an executable file, and it is ensured that the application can normally process the network request when the executable file is executed, and the tracing program can trace the application accurately in real time.
[0105] In a possible implementation, when the trace code is inserted into the pre-compiled code, an attribute tag of a function may be extracted from the pre-compiled code according to a pre-created template file, and a trace code is generated according to the extracted attribute tag and inserted into the pre-compiled code in a corresponding position to obtain an application code.
[0106] The template file defines the basic meta information about traces when the application is traced, such as function callers, function callees, timestamp, event information and other attributes. In addition, the template file may further include formatted meta codes used to print the code. The template file may be created by any meta language which can be parsed by a program. For example, a template file in xml format may be created.
[0107] The basic meta information defined by the template file includes attribute tags and some sub-attributes of the tags. According to the attribute tags and sub-attributes defined by the template file, a code generator can determine which information needs to be collected at the stage of compilation. A format-code tag shows the trace code to be inserted into the pre-compiled code by the code generator, and the trace code is usually inserted before a function call. After the trace code is inserted into the pre-compiled code to obtain an application code, the code check process will be run over again, that is, the application code is checked based on the configuration rule, semantic rule and trace rule as described in the above embodiment. If all the checks pass, the application code is compiled. After the application code is compiled to obtain the executable file, information such as timestamps, errors, etc., can be collected during execution of the executable file.
[0108] The template file can be implemented in a variety of ways for the purpose of automatically generating span information, and the specific implementation should follow the given specification or SDKs.
[0109] When the trace code is inserted into the pre-compiled code according to the template file, there may be a situation where the insertion of the trace code fails because the template file is invalid. In this case, an error report is generated to inform a software developer to check the template file.
[0110] In an embodiment of the present disclosure, a trace code for the application is automatically generated by a preset template file, and the generated trace code is inserted into the pre-compiled code in a corresponding position to obtain an application code including the service code and the trace code. In this way, the automatic generation and insertion of the trace code are achieved, and the labor intensity of the developer in the process of application tracing is reduced.
[0111] In a possible implementation, during execution of the executable file, the tracing program may call span carriers from a span pool, and store collected information about function calls into the called span carriers to obtain the span information. The span pool includes multiple span carriers and is created when the executable file starts to be executed.
[0112] By creating span pool SDKs, when the executable file starts to be executed, that is, when the application initiates, a span pool can be created by the span pool SDKs, the span pool including all the span carriers required for the tracing program to generate span information. During runtime of the application, when the tracing program needs to generate span information, the tracing program may call span carriers from the span pool, and store the collected information about function calls into the called span carriers to obtain the span information.
[0113] The number of span carriers included in the span pool may be determined according to the complexity of the application, so as to ensure that the span carriers included in the span pool are sufficient for the tracing program to generate span information. For example, as shown in Fig. 2, there are four network nodes over the network, and each network node provides a service. For example, a network node 1 provides a service SA, a network node 2 provides a service SB, a network node 3 provides a service SC, and a network node 4 provides a service SD. The service SA has three nested function calls, thereby generating three layers of nested spans. Each of the service SB, the service SC and the service SD is a simple service with only one function, and generates one layer of span. When a function FA calls a function FB, the function FB calls a function FC, the service SA calls the service SB, the service SB calls the service SC, and the service SC calls the service SD, corresponding span information needs to be generated. Therefore, a total of five pieces of span information will be generated, each of which needs a span carrier, so that the span pool needs to include at least five span carriers.
[0114] In an embodiment of the present disclosure, creating span carriers during runtime of the tracing program will occupy a large amount of memory. Therefore, when the executable file starts to be executed, that is, when the application initiates, a span pool is created. When needing to generate span information, the tracing program calls span carriers from the span pool to generate the span information, instead of temporarily generating span carriers when generating span information, which reduces the memory consumption in the running process of a span program and ensures that the application has enough memory resources to process the network request, thereby ensuring the real-time efficiency of processing the network request by the application.
[0115] In a possible implementation, when generating a target span corresponding to the application according to the acquired span information, if one piece of span information is acquired, the span information is determined to be the target span corresponding to the application. If multiple pieces of span information are acquired, the multiple pieces of span information are nested according to a service calling relationship recorded in the span information to obtain a target span.
[0116] If the application only includes one service, and the service is a simple service with only one function, the tracing program may only generate one piece of span information when tracing function calls and generating span information. After a span collector acquires the trace information, there is no need to perform other processing on the trace information, and the trace information is sent as a target span to the trace tool, which generates trace information according to target spans from multiple applications.
[0117] If the application includes multiple services, or the application includes a complex service with multiple functions, the tracing program generates multiple pieces of span information when tracing function calls and generating span information. After acquiring the multiple pieces of span information, the span collector may nest the multiple pieces of span information according to a service calling relationship recorded in the span information to obtain a target span, and then send the target span to the trace tool.
[0118] The span collector is arranged outside the application and is configured to collect the span information generated by the tracing program. A span processor is configured to process the span information to obtain a target span. The span collector and the span processor may be integrated.
[0119] During runtime of the application, the span processor will initiate a trace context holder to store the span information received by the span collector. These span information will not be nested spans but only simple spans and with some structural information the span processor can build nested spans during runtime of the application. Furthermore, the span processor may also calculate some metrics which developers concern about how the applications run in general.
[0120] To make the span processor work normally, there is a need to define some specifications about the format of spans. The format specifications at least include information of span connections, timestamps and error information if errors occur. After the tracing program generates the span information, the span information will be sent to the span processor, and the span processor will receive and hold the span information and build the nested spans based on the received span information. When a root span ends, the span processor will generate a complete span structure (target span) and export the complete span structure to the trace tool.
[0121] Nested spans include link nodes with extra attributes, and the link nodes are the span information. There are pointers on each span information pointing to its parent span information, and a key attribute of the span information is a relation between a function caller and a function callee. With the timestamp of each span information, the whole timespan of a service can be calculated.
[0122] In an embodiment of the present disclosure, the tracing program traces the function / service call process of the application, generates span information and outputs the generated span information. After acquiring the span information output by the tracing program, the span collector sends the span information to the span processor which serves as a trace context holder and nested span generator, and the span processor outside the application processes the span information to obtain a target span (nested span) . The tracing program inside the application only generates span information and sends the span information to the span processor, which reduces the workload of the application in processing the span information and allows the application to focus on processing the network request, thereby ensuring the real-time efficiency of the application in processing the network request.
[0123] Network Request Tracing Apparatus
[0124] Fig. 4 is a schematic diagram of a network request tracing apparatus according to an embodiment of the present disclosure. As shown in Fig. 4, the network request tracing apparatus 400 includes: an insertion unit 401, a compilation unit 402, an acquisition unit 403, a generation unit 404 and an output unit 405.
[0125] The insertion unit 401 is configured to insert a trace code into a service code of an application to obtain an application code, where the application is configured to process a network request.
[0126] The compilation unit 402 is configured to compile the application code to obtain an executable file.
[0127] The acquisition unit 403 is configured to acquire span information collected by a tracing program corresponding to the trace code during execution of the executable file, where the span information includes information about service calling.
[0128] The generation unit 404 is configured to generate a target span corresponding to the application according to the acquired span information.
[0129] The output unit 405 is configured to send the target span to a trace tool, so that the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request.
[0130] In an embodiment of the present disclosure, the insertion unit 401 inserts a trace code into a service code to obtain an application code, and the compilation unit 402 compiles the application code to obtain an executable file, a tracing program corresponding to the trace code can collect span information during execution of the executable file. After the acquisition unit 403 acquires the span information collected by the tracing program, the generation unit 404 can generate a target span corresponding to the application according to the span information. The output unit 405 sends the target span to a trace tool, and the trace tool can generate trace information corresponding to the network request according to target spans of multiple applications for processing the request. The tracing program collects and outputs the span information, and the span information is processed outside the application, such that the preceding span information can be synchronously processed while the tracing program collects the succeeding span information, and the application does not need to process the span information after all the span information is collected, thus saving the time for processing the span information, and improving the time efficiency of tracing network requests of real-time applications.
[0131] It should be noted that the content such as the interaction between various parts of the above-mentioned network request tracing apparatus is based on the same concept as the aforementioned network request tracing method embodiment, and for the specific content and beneficial effects, reference may be made to the description in the above-mentioned network request tracing method embodiment, which will not be repeated here.
[0132] Electronic Device
[0133] Fig. 5 is a schematic diagram of an electronic device provided by an embodiment of the present disclosure, and the specific implementation of the electronic device is not limited in this embodiment of the present disclosure. Referring to Fig. 5, an electronic device 500 provided by an embodiment of the present disclosure includes a processor 502, a communication interface 504, a memory 506, and a bus 508.
[0134] The processor 502, the communication interface 504 and the memory 506 communicate with each other through the bus 508.
[0135] The communication interface 504 is configured to communicate with other electronic devices or servers.
[0136] The processor 502 is configured to execute a program 510, specifically, execute related steps in the above-mentioned network request tracing method embodiment.
[0137] Specifically, the program 510 may include a program code which includes a computer operation instruction.
[0138] The processor 502 may be a Central Processing Unit (CPU) , or an Application Specific Integrated Circuit (ASIC) , or one or more integrated circuits configured to implement the embodiments of the present disclosure. One or more processors included in an intelligent device may be of the same type, such as one or more CPUs, or may also be of different types, such as one or more CPUs and one or more ASICs.
[0139] The memory 506 is configured to store the program 510. The memory 506 may include a high-speed Random Access Memory (RAM) , and may also include a non-volatile memory, such as at least one disk memory.
[0140] The program 510 may be specifically configured to cause the processor 502 to perform the network request tracing method in any of the aforementioned embodiments.
[0141] For the specific implementation of each step in the program 510, reference may be made to the corresponding description in corresponding steps and units in the above-mentioned network request tracing method embodiment, which will not be repeated here. Those having ordinary skills in the art can clearly understand that, for convenience and conciseness of the description, the specific operating process of the above-described device and module may refer to the corresponding process description in the aforementioned method embodiment, which will not be repeated here.
[0142] According to the electronic device of this embodiment, the application code includes a service code and a trace code. After the application code is compiled to obtain an executable file, a tracer corresponding to the trace code can collect span information during execution of the executable file. After the span information collected by the tracer is acquired, a target span corresponding to the application can be generated according to the span information, and the target span is sent to a trace tool. The trace tool can generate trace information corresponding to the network request according to target spans of multiple applications for processing the request. The tracing program collects and outputs the span information, and the span information is processed outside the application, such that preceding span information can be synchronously processed while the tracing program collects succeeding span information, and the application does not need to process the span information after all the span information is collected, thus saving the time for processing the span information, and improving the time efficiency of tracing network requests of real-time applications.
[0143] Computer-readable Storage Medium
[0144] The present disclosure further provides a computer-readable storage medium, storing an instruction which, when executed by a machine, causes the machine to implement the network request tracing method as described herein. Specifically, a system or apparatus equipped with a storage medium may be provided, where the storage medium has stored thereon a software program code for implementing the functions of any one of the aforementioned embodiments, and a computer (or CPU or MPU) of the system or apparatus is caused to read and execute the program code stored in the storage medium.
[0145] In this case, the program code itself read from the storage medium can implement the functions of any one of the above-mentioned embodiments, so the program code and the storage medium storing the program code form a part of the present disclosure.
[0146] Embodiments of storage media for providing program codes include floppy disk, hard disk, magneto-optical disk, optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW) , magnetic tape, non-volatile memory card and ROM. Alternatively, the program code may be downloaded from a server computer by a communication network.
[0147] In addition, it should be noted that some or all of the actual operations may be completed not only by executing the program code read by a computer, but also by causing an operating system to operate on the computer by the program code-based instructions, thereby implementing the functions of any one of the above-mentioned embodiments.
[0148] In addition, it can be understood that the program code read from the storage medium is written into a memory set in an expansion board inserted into the computer or written into a memory set in an expansion module connected to the computer, and then the program code-based instructions cause the CPU installed on the expansion board or an expansion module to perform some or all actual operations, thereby implementing the functions of any one of the above-mentioned embodiments.
[0149] Computer Program Product
[0150] An embodiment of the present disclosure further provides a computer program product tangibly stored on a computer-readable medium and including a computer-executable instruction which, when executed by at least one processor, causes the at least one processor to perform the network request tracing method provided by each of the above-mentioned embodiments. It should be understood that each scheme in this embodiment has corresponding technical effects in the above-mentioned method embodiments, which will not be repeated here.
[0151] It should be noted that not all steps and modules in all the above-mentioned flows and apparatus structure diagrams are necessary, and some steps or modules may be omitted according to actual needs. The execution order of each step is not fixed and may be adjusted as needed. The system structure described in each of the above-mentioned embodiments may be a physical structure or may be a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities separately or may be implemented by some components in multiple independent devices together.
[0152] Nouns and pronouns about people in the patent application are not limited to specific gender.
[0153] In all the above-mentioned embodiments, hardware modules may be implemented mechanically or electrically. For example, one hardware module may include a permanent dedicated circuit or logic (such as a specialized processor, FPGA or ASIC) to complete corresponding operations. The hardware module may further include a programmable logic or circuit (such as a general-purpose processor or other programmable processors) , which may be temporarily set by software to complete corresponding operations. The specific implementation (mechanical mode, or dedicated permanent circuit, or temporarily set circuit) can be determined based on the consideration of costs and time.
[0154] The present disclosure has been shown and illustrated in detail through the drawings and preferred embodiments. However, the present disclosure is not limited to these disclosed embodiments. Based on the above-mentioned multiple embodiments, those having ordinary skills in the art may know that more embodiments of the present disclosure can be obtained by combining the code auditing means in the above-mentioned different embodiments, and these embodiments also fall within the protection scope of the present disclosure.
Claims
1.A network request tracing method (100) , comprising:inserting a trace code into a service code of an application to obtain an application code, wherein the application is configured to process a network request;compiling the application code to obtain an executable file;acquiring span information collected by a tracing program corresponding to the trace code during execution of the executable file, wherein the span information comprises information about service calling;generating a target span corresponding to the application according to the acquired span information; andsending the target span to a trace tool, so that the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request.2.The method of claim 1, wherein the inserting a trace code into a service code of an application to obtain an application code comprises:pre-compiling the service code of the application to obtain a pre-compiled code;checking the pre-compiled code based on a preset checking rule;in response to the pre-compiled code meeting the checking rule, inserting the trace code into the pre-compiled code to obtain the application code.3.The method of claim 2, wherein the checking the pre-compiled code based on a preset checking rule comprises:checking, based on a configuration rule comprised in the preset checking rule, the pre-compiled code for at least some of: a level of a function called by the application, a type of the called function, a real-time configuration code, and a maximum response time of the application;in response to the pre-compiled code meeting the configuration rule, checking a maximum response time of function calls of the pre-compiled code based on a semantic rule comprised in the checking rule; andin response to the pre-compiled code meeting the semantic rule, determining that the pre-compiled code meets the checking rule.4.The method of claim 3, wherein the compiling the application code comprises:checking the application code based on the configuration rule and the semantic rule respectively;checking, based on a preset trace rule, the application code for at least some of: whether a root function is called, whether a trace for a function call is comprehensive, and whether the trace is completed when an error is handled; andin response to the application code meeting the configuration rule, the semantic rule and the trace rule, compiling the application code.5.The method of claim 2, wherein the inserting a trace code into the pre-compiled code to obtain an application code comprises:extracting, according to a pre-created template file, an attribute tag of a function from the pre-compiled code;generating a trace code according to the attribute tag; andinserting the trace code into the pre-compiled code in a corresponding position to obtain the application code.6.The method of claim 1, wherein the tracing program is configured to call span carriers from a span pool during execution of the executable file, and store the collected information about function calls into the called span carriers to obtain the span information, wherein the span pool comprises multiple span carriers, and the span pool is created when the executable file starts to be executed.7.The method of any one of claims 1 to 6, wherein generating a target span corresponding to the application according to the acquired span information comprises:in response to one piece of span information being acquired, determining the span information as a target span corresponding to the application; andin response to multiple pieces of span information being acquired, nesting the multiple pieces of span information according to a service calling relationship recorded in the span information to obtain a target span.8.A network request tracing apparatus (400) , comprising:an insertion unit (401) configured to insert a trace code into a service code of an application to obtain an application code, wherein the application is configured to process a network request;a compilation unit (402) configured to compile the application code to obtain an executable file;an acquisition unit (403) configured to acquire span information collected by a tracing program corresponding to the trace code during execution of the executable file, wherein the span information comprises information about service calling;a generation unit (404) configured to generate a target span corresponding to the application according to the acquired span information; andan output unit (405) configured to send the target span to a trace tool, so that the trace tool generates trace information corresponding to the network request according to target spans of multiple applications for processing the network request.9.An electronic device (500) , comprising: a processor (502) , a communication interface (504) , a memory (506) and a bus (508) , wherein the processor (502) , the communication interface (504) and the memory (506) communicate with each other through the bus (508) ; andthe memory (506) is configured to store at least one executable instruction which, when executed by the processor (502) , cause the processor (502) to perform an operation corresponding to the network request tracing method of any one of claims 1 to 7.10.A computer-readable storage medium, storing a computer instruction which, when executed by a processor, causes the processor to perform the method of any one of claims 1 to 7.11.A computer program product tangibly stored on a computer-readable medium and comprising a computer-executable instruction, wherein the computer-executable instruction, when executed by at least one processor, causes the at least one processor to perform the method of any one of claims 1 to 7.