Link tracking method and device based on script language and electronic equipment
By embedding link tracing logic into the reverse proxy server to generate and update link data, the problem of incomplete link information in traditional link tracing technology is solved, and the efficiency of comprehensive tracking and fault location of distributed systems is improved.
Patent Information
- Application Number
- CN202511260812.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-04
- Publication Date
- 2025-11-11
AI Technical Summary
Traditional link tracing technology fails to fully cover critical links at network entry and exit points in distributed systems, resulting in incomplete link information and affecting the accuracy and efficiency of system fault location, especially in microservice architectures where there is a lack of support for scripting language application scenarios.
The method employs a scripting language-based link tracing approach. By embedding link tracing logic into the critical lifecycle stages of the reverse proxy server, the configuration is loaded and the server is initialized, upstream link data and span data are generated, link data entries are dynamically updated, and they are associated with network requests, saved as context information, and finally sent to the link tracing server.
It enables comprehensive tracking of service call chains, ensuring that the execution span of each link from the front end to the back end is recorded, and intelligently associates upstream and downstream link data to form a continuous service request trajectory. This solves the problem that the link tracing system cannot obtain complete link information, and improves fault location efficiency and system manageability.
Smart Images

Figure CN120935249A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of distributed and cloud computing technology or other related fields. Specifically, it relates to a scripting language-based link tracing method and apparatus, and an electronic device. Background Technology
[0002] In the highly interconnected information age, distributed systems and cloud computing architectures have become the cornerstone of enterprise applications and internet services. With the widespread adoption of microservice architectures, the complex and intertwined call chains between services are becoming increasingly important. Distributed tracing technology is used to capture and analyze every detail of the service call chain to diagnose the causes of latency and improve system performance and reliability.
[0003] Traditional distributed tracing solutions effectively monitor critical link nodes; however, they overlook blind spots in distributed systems. For example, HTTP (Hypertext Transfer Protocol) servers and reverse proxies, acting as gateways to numerous distributed services, not only manage traffic between external and internal services but also undertake multiple responsibilities such as load balancing, security protection, and caching. However, current distributed tracing practices fail to adequately cover critical links at network entry and exit points when tracing distributed application call chains, and lack support for scripting language applications. This inadequacy leads to incomplete link information and limitations in troubleshooting. Particularly in microservice architectures, this information gap and technical limitations make it difficult for developers and operations teams to obtain a complete view from user requests to service responses, and to achieve unified distributed tracing across multiple languages and frameworks, impacting the accuracy and efficiency of system fault location.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] The main objective of this application is to provide a link tracing method, apparatus, and electronic device based on a scripting language, so as to at least solve the technical problem in the related art where incomplete link coverage in the processing of network requests leads to the link tracing system being unable to obtain complete link information.
[0006] To achieve the above objectives, according to one aspect of this application, a scripting language-based link tracing method is provided. The method includes: loading a link tracing configuration and initializing a server using the configuration to obtain a target server, wherein the target server includes at least an upload component and a recording component; upon receiving a network request, generating upstream link data and span data of the current request based on the network request; during the processing of the network request, updating link data entries based on the upstream link data and the span data through the recording component, associating the index of the link data entries with the network request, and saving it as context information; after the network request is processed, extracting the link data entries related to the current request from the context information, and uploading the link data entries to the link tracing server through the upload component.
[0007] Further, the step of initializing the server using the link tracing configuration to obtain the target server includes: reading configuration information from the link tracing configuration, wherein the configuration information includes: service name, link tracing server address, and sampling rate; loading a scripting language environment when starting the server based on the configuration information, wherein the scripting language environment is used to execute the link tracing script; initializing the upload component according to the link tracing server address; initializing the recording component using the service name and the sampling rate; and setting a global status flag after completing the initialization operation to obtain the target server, wherein the global status flag is used to indicate that the target server is ready.
[0008] Further, the step of generating upstream link data and span data of the current request based on the network request includes: extracting the request header information of the network request and checking the request header information to obtain a check result; if the check result indicates that the request header information does not contain trace information of upstream service calls, setting the upstream link data to null and generating the span data of the current request based on the current timestamp; or, if the check result indicates that the request header information contains trace information of upstream service calls, generating the upstream link data and span data of the current request based on the request header information.
[0009] Further, the step of generating the upstream link data and the span data of the current request based on the request header information includes: extracting the tracking information from the request header information to obtain the upstream link data, wherein the tracking information includes an upstream tracking identifier and an upstream span identifier; reusing the upstream tracking identifier as the tracking identifier of the current request, and generating the span identifier of the current request based on the upstream span identifier, wherein the upstream span identifier is the parent identifier of the span identifier of the current request; and integrating the tracking identifier, the span identifier, and the current timestamp of the current request to obtain the span data.
[0010] Further, the step of updating the link data entry based on the upstream link data and the span data by the recording component includes: obtaining existing context information; determining whether the link data entry corresponding to the network request exists in the existing context information based on the upstream link data, and obtaining a determination result; if the determination result indicates that the link data entry corresponding to the network request does not exist, generating a link data entry related to this request based on the span data by the recording component; or, if the determination result indicates that the link data entry corresponding to the network request exists, obtaining the link data entry and adding the span data to the link data entry by the recording component, and obtaining the updated link data entry.
[0011] Further, the step of associating the index of the link data entry with the network request and saving it as context information includes: if the determination result indicates that there is no link data entry corresponding to the network request, creating a context entry, wherein the context entry contains an index pointing to the link data entry, which is used to directly locate the link data entry; establishing an association between the network request and the index in the context entry, and storing the context entry in the existing context information; or, if the determination result indicates that there is a link data entry corresponding to the network request, obtaining the existing context entry corresponding to the link data entry in the context information; and updating the index and link information in the existing context based on the parent-child relationship between the span identifier of the current request and the upstream span identifier.
[0012] Furthermore, after extracting the link data entries related to the current request from the context information, the method further includes: calculating the time consumption of the current request corresponding to the network request based on all the extracted link data entries and using the timestamps in the link data entries; and packaging the time consumption of the current request with all the link data entries and sending it to the link tracing server through the uploading component.
[0013] To achieve the above objectives, according to another aspect of this application, a scripting language-based link tracing device is also provided. This device includes: a loading unit, configured to load a link tracing configuration and initialize a server using the configuration to obtain a target server, wherein the target server includes at least an upload component and a recording component; a generation unit, configured to generate upstream link data and span data of the current request based on the network request received; an update unit, configured to update link data entries based on the upstream link data and the span data through the recording component during the processing of the network request, and associate the index of the link data entries with the network request, saving it as context information; and an extraction unit, configured to extract the link data entries related to the current request from the context information after the network request processing is completed, and upload the link data entries to the link tracing server through the upload component.
[0014] Further, the loading unit includes: a reading module for reading configuration information in the link tracing configuration, wherein the configuration information includes: service name, link tracing server address, and sampling rate; a loading module for loading a scripting language environment when starting the server based on the configuration information, wherein the scripting language environment is used to execute a link tracing script; a first initialization module for initializing the uploading component according to the link tracing server address; a second initialization module for initializing the recording component using the service name and the sampling rate; and a setting module for setting a global status identifier after completing the initialization operation to obtain the target server, wherein the global status identifier is used to indicate that the target server is ready.
[0015] Further, the generation unit includes: an extraction module, used to extract the request header information of the network request and check the request header information to obtain a check result; a first generation module, used to set the upstream link data to null and generate the span data of this request based on the current timestamp when the check result indicates that the request header information does not contain trace information of upstream service calls; and a second generation module, used to generate the upstream link data and the span data of this request based on the request header information when the check result indicates that the request header information contains trace information of upstream service calls.
[0016] Further, the second generation module includes: an extraction submodule, used to extract tracing information from the request header information to obtain the upstream link data, wherein the tracing information includes an upstream tracing identifier and an upstream span identifier; a generation submodule, used to reuse the upstream tracing identifier as the tracing identifier for this request, and generate a span identifier for this request based on the upstream span identifier, wherein the upstream span identifier is the parent identifier of the span identifier for this request; and an integration submodule, used to integrate the tracing identifier, the span identifier, and the current timestamp of this request to obtain the span data.
[0017] Further, the updating unit includes: a determining module, configured to acquire existing context information, determine whether a link data entry corresponding to the network request exists in the existing context information based on the upstream link data, and obtain a determining result; a third generating module, configured to generate a link data entry related to this request based on the span data through the recording component when the determining result indicates that no link data entry corresponding to the network request exists; and an adding module, configured to acquire the link data entry when the determining result indicates that a link data entry corresponding to the network request exists, and add the span data to the link data entry through the recording component, to obtain the updated link data entry.
[0018] Furthermore, the update unit further includes: a creation module, configured to create a context entry when the determination result indicates that there is no link data entry corresponding to the network request, wherein the context entry contains an index pointing to the link data entry, the index being used to directly locate the link data entry; an establishment module, configured to establish an association between the network request and the index in the context entry, and store the context entry in the existing context information; an acquisition module, configured to acquire the existing context entry corresponding to the link data entry in the context information when the determination result indicates that there is a link data entry corresponding to the network request; and an update module, configured to update the index and link information in the existing context based on the parent-child relationship between the span identifier of the current request and the upstream span identifier.
[0019] Furthermore, the scripting language-based link tracing device further includes: a calculation module, used to calculate the time consumption of the current request corresponding to the network request based on the timestamps in all the extracted link data entries after extracting the link data entries related to the current request from the context information; and a packaging module, used to package the time consumption of the current request and all the link data entries together and send them to the link tracing server through the uploading component.
[0020] To achieve the above objectives, according to another aspect of this application, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to execute the scripting language-based link tracing method described in any one of the above claims.
[0021] To achieve the above objectives, according to another aspect of this application, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the scripting language-based link tracing method described in any of the above claims.
[0022] To achieve the above objectives, according to another aspect of this application, a computer program product is also provided, including computer instructions, wherein when the computer instructions are executed by a processor, they implement the steps of the scripting language-based link tracing method described in any of the preceding claims.
[0023] This invention proposes a scripting-based link tracing method. First, a link tracing configuration is loaded and used to initialize the server, resulting in a target server. The target server includes at least an upload component and a recording component. Upon receiving a network request, upstream link data and the span data of the current request are generated based on the network request. During network request processing, the recording component updates link data entries based on the upstream link data and span data, associating the index of each link data entry with the network request and saving it as context information. Finally, after the network request is processed, the link data entries related to the current request are extracted from the context information and uploaded to the link tracing server via the upload component.
[0024] This invention employs embedded programming in a scripting language to embed link tracing logic into the critical lifecycle stages of a reverse distributed proxy server. This achieves the goal of automatically capturing and recording the entire network request link data, thereby realizing a comprehensive and seamless tracking effect of the service call link. It breaks through the limitations of traditional link tracing technology, not only meticulously recording the execution span of each link from the front end to the back end of the service, but also intelligently associating upstream and downstream link data to form a continuous and clear service request trajectory. This solves the technical problem in related technologies where incomplete coverage of network request processing links prevents the link tracing system from obtaining complete link information.
[0025] Specifically, the link tracing logic can load the configuration when the server starts, achieving global initialization of link tracing and ensuring that the uploading and recording components are active. When the server receives a network request, it takes effect immediately, automatically capturing and parsing header information to generate upstream link data and span data specific to this request. Throughout the network request processing, it dynamically updates link data entries and closely associates the indexes of these data entries with the network request, storing them in the context information. This makes the proxy server no longer just a "transfer station" for traffic, but a "starting station" for link tracing. Once the network request is completed, it can accurately extract the link data related to this request based on the stored context information, ensuring timely and complete reporting to the link tracing server through the pre-set uploading mechanism. This achieves closed-loop management of link data, enhancing the practical value and analytical capabilities of the link tracing system. Attached Figure Description
[0026] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0027] Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a scripting language-based link tracing method is shown.
[0028] Figure 2 This is a flowchart of an optional scripting language-based link tracing method according to an embodiment of the present invention;
[0029] Figure 3 This is a schematic diagram of an optional network request tracing process according to an embodiment of the present invention;
[0030] Figure 4 This is a schematic diagram of an optional scripting language-based link tracing device according to an embodiment of the present invention;
[0031] Figure 5 This is a structural block diagram of an electronic device that executes a scripting language-based link tracing method according to an embodiment of the present invention. Detailed Implementation
[0032] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0033] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0034] To facilitate understanding of the present invention by those skilled in the art, some terms or nouns involved in the various embodiments of the present invention are explained below:
[0035] SL, Scripting Language, is an interpreted, high-level programming language designed to simplify and accelerate development tasks such as system administration, web page generation, and data processing. Typical scripting languages are known for their lightweight, high efficiency, and ease of embedding, and are commonly used in game development, web applications, and embedded systems.
[0036] Link tracing is a monitoring technique used to trace the complete call chain in a distributed system from a client's request to the final server response. Its purpose is to diagnose system latency, performance bottlenecks, and error propagation. In a microservices architecture, link tracing is used to understand the interactions between services.
[0037] A span, the basic unit of measurement in distributed tracing, represents a single unit of work in a request processing process, such as an HTTP call or a database query. It contains a timestamp, a unique ID, and other metadata information used to identify and track calls between services.
[0038] A trace, a collection of interconnected spans, describes the request processing process from the client to the server and then to other servers, forming a complete call chain, which helps to understand the execution flow of distributed applications.
[0039] It should be noted that the scripting language-based link tracing method and apparatus in this application can be used in the field of distributed and cloud computing technology for comprehensive monitoring and analysis of network request processing links, and can also be used in any field other than distributed and cloud computing technology for comprehensive monitoring and analysis of network request processing links. This application does not limit the application field of the scripting language-based link tracing method and apparatus.
[0040] It should be noted that all relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data) involved in this application are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, processing, transmission, provision, disclosure, use, and handling of such data comply with the laws, regulations, and standards of the relevant regions, necessary confidentiality measures have been taken, and they do not violate public order and good morals. Corresponding access points are provided for users to choose to authorize or refuse access. For example, this system has interfaces with relevant users or organizations. Before obtaining relevant information, a request to obtain the information needs to be sent to the aforementioned user or organization through the interface, and the relevant information is obtained only after receiving consent from the aforementioned user or organization.
[0041] The information collection (e.g., user voice, video, and text collection) and analysis operations involved in this application have provided users with corresponding operation entry points during execution, allowing users to choose to agree to or reject the automated decision results; if the user chooses to reject, the process will proceed to the expert decision-making process.
[0042] The following embodiments of the present invention can be applied to various systems / applications / devices that require distributed tracing and microservice monitoring, enabling a high-performance distributed tracing solution based on scripting languages. This invention uses scripting languages to control the lifecycle of the reverse proxy server and generate distributed tracing data. Then, through a pre-built upload component, the distributed tracing data entries are reported to the distributed tracing server. This allows for better capture and correlation of every call detail from the traffic entry point to the backend service in a microservice architecture, while ensuring the accuracy and real-time nature of the tracing data, providing powerful tool support for the operation and development of distributed systems.
[0043] This invention can automatically load and initialize the link tracing configuration, and intelligently generate and update link data when processing each network request. By using a reverse proxy server as the originating station for link tracing, it ensures the integrity of link data, thereby significantly improving the efficiency of problem localization and enhancing the manageability and reliability of the system. Furthermore, this invention achieves accurate extraction and reporting of link data through dynamic monitoring and the preservation of context information, making link tracing more flexible and efficient, and helping to optimize service response time and improve user experience.
[0044] The present invention will now be described in detail with reference to various embodiments.
[0045] Example 1
[0046] According to an embodiment of the present invention, an embodiment of a link tracing method based on a scripting language is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0047] The scripting language-based link tracing method embodiment provided in Embodiment 1 of the present invention can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware block diagram of a computer terminal (or mobile device) for implementing a scripting language-based link tracing method is shown. Figure 1 As shown, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) 102 (processor 102 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0048] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0049] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the scripting language-based link tracing method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the aforementioned scripting language-based link tracing method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0050] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0051] The display can be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0052] Under the above operating environment, the present invention provides, as follows: Figure 2 The scripting-based distributed tracing method illustrated here is implemented by a distributed tracing system. Combining scripting language technology, it is used in distributed and cloud computing scenarios, particularly addressing the issue of incomplete distributed tracing coverage. This is achieved by embedding distributed tracing logic into key lifecycle stages of the reverse proxy server, specifically through steps such as loading configuration, initializing tracing components, generating tracing data entries, saving context information, and reporting tracing data. This process aims to construct a complete and continuous distributed service call chain. By filling the gaps in distributed tracing, this method ensures that every call from the traffic entry point to the backend service is accurately recorded and traced. This provides operations and development personnel with a comprehensive view of the service call chain, significantly improving the efficiency and accuracy of troubleshooting in distributed systems.
[0053] The embodiments of the present invention will now be described in detail with reference to each specific step.
[0054] Figure 2 This is a flowchart of an optional scripting language-based link tracing method according to an embodiment of the present invention, such as... Figure 2 As shown, the method includes the following steps:
[0055] Step S201: Load the link tracing configuration and use the link tracing configuration to initialize the server to obtain the target server, wherein the target server contains at least: an upload component and a recording component.
[0056] Specifically, in a distributed system, tracing configuration refers to a set of preset rules and parameters that guide the tracing component in collecting, parsing, storing, and sending tracing data related to service calls. These include, but are not limited to, service node identifiers (such as service names), the storage destination of tracing data (such as the tracing server address), data formatting requirements (such as the use of header information like X-B3-TraceId and X-B3-SpanId), and data reporting strategies (such as sampling rate and reporting interval). These parameters are loaded and parsed when the server starts up to initialize the tracing component, ensuring that subsequent tracing activities follow the preset rules.
[0057] It's important to note that initializing the server (especially critical servers acting as traffic ingress and reverse proxy) means activating and configuring the necessary components (at least the reporter and tracer components) and logic for tracing by loading the tracing configuration when the server starts up, making it ready to handle all subsequent network requests. This ensures seamless integration of the tracing components with the server and the continued effectiveness of the tracing logic throughout the server's lifecycle.
[0058] Furthermore, a target server refers to a configured and initialized server capable of automatically capturing and processing link tracing information, and should at least include an upload component and a recording component. The upload component is responsible for sending tracing data to the tracing server for storage and analysis, while the recording component is responsible for storing link data entries locally on the server. The target server is characterized by its high degree of automation and sensitivity to link data, enabling it to intelligently generate corresponding link information based on network requests and report data at appropriate times.
[0059] To efficiently initialize the server to support link tracing and ensure that the server automatically loads necessary configuration information upon startup, optionally, in the link tracing method based on a scripting language provided in this embodiment of the invention, the step of initializing the server using link tracing configuration to obtain the target server includes: reading configuration information from the link tracing configuration, wherein the configuration information includes: service name, link tracing server address, and sampling rate; loading a scripting language environment upon server startup based on the configuration information, wherein the scripting language environment is used to execute link tracing scripts; initializing the upload component according to the link tracing server address; initializing the recording component using the service name and sampling rate; and setting a global status flag after completing the initialization operation to obtain the target server, wherein the global status flag is used to indicate that the target server is ready.
[0060] It should be noted that in the configuration information, the service name is used to identify the server's identity or role in the tracing system, making it easier to distinguish different service nodes when analyzing tracing data; the link tracing server address refers to the destination information of the tracing data, ensuring that the collected data can be correctly sent to the centralized processing and analysis platform for tracing data; the sampling rate is used to define the frequency of tracing data collection. By adjusting the sampling rate, a balance can be found between performance consumption and the amount of tracing data, which is suitable for high-concurrency distributed environments.
[0061] Loading the scripting language environment at server startup refers to dynamically loading the scripting language environment at the initial stage of server startup. This provides environmental support for the execution of subsequent tracing scripts, avoids the performance overhead of loading the scripting environment with each request, ensures that the server can execute the tracing logic quickly and efficiently, and maintains the flexibility and scalability of the scripting language, allowing the tracing logic to be updated and expanded without restarting the server.
[0062] Furthermore, configuring and initializing the component responsible for data reporting based on the link tracing server address ensures that tracing data is sent to the tracing server in a timely and accurate manner. Going a step further, initializing the recording component using the service name and sampling rate allows this component to store link data locally on the server while controlling the data volume through the sampling rate to avoid excessive memory consumption.
[0063] After all initialization operations are completed, a global status flag is set to indicate that the server is ready for the link tracing components and can start processing network requests and executing link tracing logic. The server can start tracing links only after it is fully ready, avoiding the loss or anomaly of tracing data due to incomplete initialization.
[0064] Step S202: Upon receiving a network request, generate upstream link data and the span data of this request based on the network request.
[0065] Specifically, a network request refers to various types of requests initiated by a client and reaching a server via the network, including but not limited to HTTP requests and RPC (Remote Procedure Call) calls. In a distributed system, each network request may trigger a series of cross-service calls, forming a complex call chain.
[0066] In distributed calls, each service node can be an upstream of a downstream service. Upstream link data refers to the data generated to continue upstream link tracing when a network request carries trace information from an upstream service. This involves reusing the upstream trace ID and parent span ID, and may use the same sampling decision.
[0067] Span data is the basic unit in distributed tracing, representing a segment of a service call. When a network request is received, the span data for this request is generated based on information about the current request (such as method, path, timestamp, and status code) to record detailed information about the request and its position in the chain.
[0068] To achieve automated and intelligent link tracing logic and ensure that each network request accurately generates or inherits the correct link data based on whether it belongs to an existing link, optionally, in the scripting language-based link tracing method provided in this embodiment of the invention, the step of generating upstream link data and span data of the current request based on the network request includes: extracting the request header information of the network request and checking the request header information to obtain the check result; if the check result indicates that the request header information does not contain tracing information of upstream service calls, setting the upstream link data to null and generating the span data of the current request based on the current timestamp; or, if the check result indicates that the request header information contains tracing information of upstream service calls, generating upstream link data and span data of the current request based on the request header information.
[0069] It should be noted that in a network request, the request header must contain at least metadata such as source information, authentication information, protocol version, and content type. In the context of distributed tracing, specific request headers (such as X-B3-TraceId, X-B3-SpanId, X-B3-ParentSpanId, and X-B3-Sampled) are used to carry the tracing context, helping downstream service nodes understand and join the existing tracing chain.
[0070] The purpose of checking the request headers is to determine whether the request carries context information for distributed tracing. If the request headers contain tracing information about upstream service calls, then the request is considered part of a distributed tracing, and the tracing needs to be correctly inherited and extended. Conversely, if the request headers do not contain this information, it is generally considered a new tracing starting point, and tracing data needs to be generated independently.
[0071] When the server determines that the request is the start of a new link, it generates span data based on the current timestamp, including creating a new Trace ID and a new Span ID, and attaching a sampling decision flag, which constitutes the link tracing context for this request.
[0072] In some preferred embodiments of the invention, the generated span data is added to the request context to ensure that the span information can flow with the request through subsequent service calls, thereby forming complete link data. When the request processing is completed, the span data is obtained from the request context, necessary log information is recorded, and the tracking data is reported to the tracking server through the upload component.
[0073] To further process and extend the link tracing data, and to more accurately track and analyze the flow path of requests between services, optionally, in the link tracing method based on scripting language provided in this embodiment of the invention, the step of generating upstream link data and span data of the current request based on request header information includes: extracting tracing information from the request header information to obtain upstream link data, wherein the tracing information includes an upstream tracing identifier and an upstream span identifier; reusing the upstream tracing identifier as the tracing identifier of the current request, and generating a span identifier of the current request based on the upstream span identifier, wherein the upstream span identifier is the parent identifier of the span identifier of the current request; and integrating the tracing identifier, span identifier, and current timestamp of the current request to obtain span data.
[0074] It should be noted that extracting tracing information to obtain upstream link data involves extracting key information for link tracing from the request header of the network request. This mainly includes the upstream tracing identifier (usually called Trace ID, such as X-B3-TraceId) and the upstream span identifier (Parent Span ID, such as X-B3-ParentSpanId), which are used to identify and continue the link tracing context from the upstream service.
[0075] Furthermore, the server generates upstream link data based on the extracted tracing information, including identifying which tracing link the upstream request belongs to and its position within that link, i.e., the parent span. The generation of upstream link data is fundamental to link continuity, ensuring that each service call can be accurately added to an existing link, rather than creating a new, isolated link. Directly using the tracing identifier carried in the upstream request ensures that the current request belongs to the same tracing link, thus maintaining the continuity and consistency of link data.
[0076] The generation of upstream link data signifies that the server understands the request as a link in a distributed call chain, a continuation rather than the beginning of the chain. The core of this step is ensuring the reuse of the trace ID and the correct identification of the parent span ID, thereby constructing a complete link view.
[0077] Furthermore, the server generates a span identifier (Span ID) for this request based on the upstream span identifier (Parent Span ID), or it can create a new unique ID. Simultaneously, it marks the upstream span identifier as the parent span to indicate the relationship and sequence of this request with the upstream requests. Establishing this parent-child relationship facilitates the construction and visualization of the link diagram, clearly demonstrating the hierarchical relationship and order of request calls.
[0078] During the integration of span data, timestamps are used to record the lifecycle of the span and are an important basis for identifying latency and performance bottlenecks in link analysis. The generated span data will be stored in an appropriate context, such as request context or thread-local storage, for use in subsequent request processing phases (such as logging phases).
[0079] In step S203, during the processing of network requests, the link data entries are updated by the recording component based on upstream link data and span data, and the index of the link data entries is associated with the network request and saved as context information.
[0080] Specifically, in a distributed system, each service node needs to be able to understand and participate in the tracing process when handling network requests. This involves not only the routine business processing of the requests but also ensuring the accurate recording and transmission of tracing information.
[0081] When a service node receives a network request, it updates the locally stored link data entries based on the extracted upstream link data (if any) and the span data automatically generated for this request. Each link data entry represents the service node's behavior in the link, including but not limited to: the start and end times of request processing, service name, and request type. When updating a link data entry, the service node adds new span data to the entry while maintaining the association with the upstream span, ensuring the integrity and continuity of the link data.
[0082] To ensure accurate association between link data entries and specific network requests, service nodes assign an index (which can be a request ID or a session ID) to each network request. By associating the index of the link data entry with the network request, service nodes can ensure that the link information of each request is correctly recorded and tracked, even if multiple service calls are involved in the lifecycle of the network request. This provides accurate data support for subsequent link analysis and troubleshooting.
[0083] It's important to note that context information refers to environment variables or thread-local variables used by service nodes to store and transmit trace data when processing requests. By storing the information associating the index of trace data entries with the network request in the context information, service nodes can ensure that trace data is available throughout the entire lifecycle of the request and is not confused across threads or requests.
[0084] To automate and accurately record and manage link tracing information in a distributed environment, ensuring that the tracing information can be correctly captured, inherited, and extended when a request crosses multiple services, optionally, in the scripting language-based link tracing method provided in this embodiment of the invention, the step of updating link data entries based on upstream link data and span data by a recording component includes: obtaining existing context information; determining whether a link data entry corresponding to a network request exists in the existing context information based on upstream link data, and obtaining a determination result; if the determination result indicates that no link data entry corresponding to a network request exists, generating a link data entry related to this request based on span data by a recording component; or, if the determination result indicates that a link data entry corresponding to a network request exists, obtaining the link data entry and adding span data to the link data entry by a recording component, obtaining an updated link data entry.
[0085] It's important to note that in a distributed system, each network request carries certain contextual information throughout its lifecycle. This typically includes a request ID, trace ID, span ID, and any status identifiers related to the trace and request. Existing contextual information refers to all the traces and business context that a service node already possesses regarding a request when it arrives at the node.
[0086] When processing a request, the service node checks the existing context information for a link data entry corresponding to the current network request, based on upstream link data (if it exists). This ensures that if the request is a subsequent request in the link, the tracing information can be correctly inherited and extended. If the request is the starting point of a new link, a new link data entry needs to be generated.
[0087] When the result indicates that no link data entry exists for the network request, it signifies that the current request marks the beginning of a new link. At this point, the service node will generate a link data entry related to this request based on the span data. This includes creating a new record in local memory or a log to record request processing details, including but not limited to: timestamp, service name, operation description, span ID, and tracking ID.
[0088] Conversely, if the result indicates the existence of a link data entry corresponding to the network request, the service node will add the span data of this request (including span ID, start and end times, service name, etc.) to the existing link data entry to update the link data. This involves recording key indicators such as the start and end times of the span, operation status, and error information in the link data entry, while updating the span ID list in the link data entry to ensure that the link data entry can reflect the complete link trajectory of the request processing.
[0089] To ensure that the link tracing data for each network request can be accurately and efficiently recorded and managed, optionally, in the link tracing method based on a scripting language provided in this embodiment of the invention, the step of associating the index of a link data entry with a network request and saving it as context information includes: if the determination result indicates that there is no link data entry corresponding to the network request, creating a context entry, wherein the context entry contains an index pointing to the link data entry, which is used to directly locate the link data entry; establishing an association between the network request and the index in the context entry, and storing the context entry in the existing context information; or, if the determination result indicates that there is a link data entry corresponding to the network request, obtaining the existing context entry corresponding to the link data entry in the context information; and updating the index and link information in the existing context based on the parent-child relationship between the span identifier of the current request and the upstream span identifier.
[0090] It's important to note that when it's determined that the current network request doesn't have a corresponding link data entry, meaning the request is considered the starting point of a new link, a new context entry is created to store and maintain all tracking data and metadata related to that request. The core information in the context entry is the index of the link data entry, pointing to the newly created link data entry. This allows subsequent processing to quickly locate the correct link data for updating and maintenance. Specifically, a unique context entry is allocated in memory for this request, containing key information such as the tracking ID, span ID, and timestamp, as well as an index pointing to the link data entry. This index can be a simple pointer, an ID reference, or a reference to a data structure; the specific implementation depends on the system design and storage mechanism.
[0091] After creating a context entry, it's necessary to associate the network request with the index of the link data entry so that the link data can be quickly accessed and updated during subsequent request processing. This association can be stored directly in the request object, or the index can be embedded into the request processing flow using a mechanism (such as the decorator pattern) to ensure that each service call accesses the correct link data index. Context entries are typically stored in request-related objects or use thread-local storage to ensure that the context of each request is independent and correct in a multi-threaded environment.
[0092] For existing network request link data entries, since the parent span identifier in the span data forms a parent-child relationship with the existing spans in the link data entry, newly generated span data needs to be correctly added to the link data entry to reflect the new service call relationship. Specifically, this includes the following steps: obtaining the index of the existing link data entry from the context information; locating the link data entry using the index and adding the span data of this request (including service name, timestamp, span ID, etc.) to the entry; updating the index, if necessary, to reflect the latest status and information in the link data entry.
[0093] Step S204: After the network request is processed, extract the link data entries related to this request from the context information and send the link data entries to the link tracing server through the upload component.
[0094] Specifically, in a distributed system, each network request generates a series of trace data during its processing, including service call time, span ID, trace ID, and other tracing information. The trace data entries related to this request refer to the trace data records generated and maintained by the service nodes throughout the lifecycle of this request, containing all trace-related information from the start to the end of the request.
[0095] After a request is processed, retrieving the relevant link data entries is typically done by searching the context information in the request object or thread-local storage. This context information contains an index that directly points to the link data entries stored in memory. Therefore, the retrieval process essentially involves quickly locating the correct link data using the index.
[0096] Optionally, extracting the link data entry related to the current request may include the following steps: triggering the link data extraction process when the request ends; reading the stored context information from the request object or thread local storage to locate the index of the link data entry related to the current request; and using the index to retrieve the complete link data entry from memory.
[0097] Furthermore, sending link data entries to the link tracing server refers to sending the locally collected link information to a central service that is specifically responsible for collecting and analyzing link data. This is done through network communication, using HTTP, RPC, or other protocols to package and send the data.
[0098] Optionally, uploading link data entries to the link tracing server may include the following steps: converting the link data entries into a specified format to meet the requirements of the link tracing server; using a configured upload component (such as an HTTP client or a message queue producer) to send the link data entries to the link tracing server; and setting up retransmission mechanisms, timeout policies, and error handling mechanisms to ensure reliable data transmission.
[0099] A tracing server is a centralized service or platform used to collect, store, and analyze tracing data from various service nodes, providing a unified interface and tools for operations and maintenance personnel and developers to monitor and troubleshoot performance issues and faults in distributed systems.
[0100] Furthermore, upon receiving link data entries from service nodes, the link tracing server parses the data to verify its integrity and format; stores the link data entries in a persistent database, such as a time-series database or a document database; integrates link data entries from different nodes to construct a complete request call chain; and provides data analysis and visualization functions, such as latency statistics, fault location, and link topology mapping.
[0101] To provide a comprehensive insight into the performance of distributed system request calls, optionally, in the scripting language-based link tracing method provided in this embodiment of the invention, after extracting the link data entries related to the current request from the context information, the method further includes: calculating the time consumption of the current request corresponding to the network request based on all extracted link data entries using the timestamps in the link data entries; and packaging the time consumption of the current request and all link data entries together and sending them to the link tracing server via an upload component.
[0102] It should be noted that the steps for calculating the time taken for this request may include: extracting all link data entries related to this request from the context information, with each entry containing timestamps for the start and end of the request and service call; calculating the total time taken for this request involves finding the earliest service call start time (i.e., request start time) and the latest service call end time (i.e., request end time), and the time difference between the two is the total time taken for this request.
[0103] Furthermore, the total time taken for this request is encapsulated together with all link data entries into a single data packet, which may be in JSON, Protobuf (Protocol Buffers), or other serialization formats to facilitate network transmission. The data packet is then sent to the link tracing server using a configured upload component, such as an HTTP client or a message queue producer.
[0104] Furthermore, after receiving the data packet, the link tracing server parses, stores, and performs further analysis and processing on the data, including but not limited to: decoding the data packet to restore the original link data and request time; storing the parsed data in persistent storage, such as time-series databases, document databases, etc.; and performing latency analysis, performance bottleneck location, and fault diagnosis based on the stored link data and request time.
[0105] Through steps S201 to S204 above, the link tracing configuration can be loaded first, and the server can be initialized using the link tracing configuration to obtain the target server. The target server includes at least an upload component and a record component. Then, when a network request is received, upstream link data and the span data of the current request are generated based on the network request. During the processing of the network request, the link data entries are updated by the record component based on the upstream link data and the span data, and the index of the link data entries is associated with the network request and saved as context information. Finally, after the network request is processed, the link data entries related to the current request are extracted from the context information, and the link data entries are uploaded to the link tracing server by the upload component.
[0106] In this embodiment of the invention, embedded programming using a scripting language is employed. By embedding link tracing logic into the critical lifecycle stages of the reverse distributed proxy server, the goal of automatically capturing and recording the entire network request link data is achieved. This enables comprehensive and seamless tracking of the service call link, overcoming the limitations of traditional link tracing technologies. It not only meticulously records the execution span of each link from the front-end to the back-end service but also intelligently associates upstream and downstream link data to form a continuous and clear service request trajectory. This solves the technical problem in related technologies where incomplete coverage of the network request processing link prevents the link tracing system from obtaining complete link information.
[0107] Specifically, the link tracing logic can load the configuration when the server starts, achieving global initialization of link tracing and ensuring that the uploading and recording components are active. When the server receives a network request, it takes effect immediately, automatically capturing and parsing header information to generate upstream link data and span data specific to this request. Throughout the network request processing, it dynamically updates link data entries and closely associates the indexes of these data entries with the network request, storing them in the context information. This makes the proxy server no longer just a "transfer station" for traffic, but a "starting station" for link tracing. Once the network request is completed, it can accurately extract the link data related to this request based on the stored context information, ensuring timely and complete reporting to the link tracing server through the pre-set uploading mechanism. This achieves closed-loop management of link data, enhancing the practical value and analytical capabilities of the link tracing system.
[0108] Figure 3 This is a schematic diagram of an optional network request tracing process according to an embodiment of the present invention. As shown in the figure, the tracing process includes an initiation phase and a request phase.
[0109] First, during the startup phase, after starting the proxy server, the initialization configuration information is loaded, including at least the initialization of opentracing, reading configuration information, initializing the reporter, and initializing the tracer.
[0110] Then, the request phase begins. During the request access phase, after obtaining the HTTP request, the global tracer is retrieved and the request header information is parsed. It is determined whether the request header information contains X-B3-TracerID, X-B3SpanID, etc.: if not, the TracerID and SpanID are regenerated, and Span information is constructed accordingly; if they are present, Span information is directly constructed based on the header information. The Span information is stored in the context information, and the parsed TraceID and SpanID are added to the request header to continue processing the HTTP request.
[0111] At the end of the request phase, the global tracer is still obtained first, and the Span information is obtained from the context information. The reporter information is then extracted and reported asynchronously to the proxy server.
[0112] The technical benefits of the above tracing process are reflected in the following aspects: Regardless of whether the request carries tracing context, the proxy server can generate complete link data, covering the entire process from the start to the end of the request; by parsing and utilizing the tracing information in the request header, the parent-child span relationship is automatically established, ensuring the consistency and contextual relevance of the link data; the asynchronous reporting mechanism reduces the impact of data transmission on request processing, improving the overall performance of the system and the success rate of tracing data reporting; by accurately capturing and recording the link information of each request, operations and maintenance personnel can quickly locate performance bottlenecks and fault points in service calls, significantly improving the efficiency of problem investigation and system optimization; the process is flexibly designed to adapt to different service architectures and tracing needs, supporting future expansion and optimization of the tracing logic.
[0113] The invention will now be described in conjunction with another alternative embodiment.
[0114] Example 2
[0115] This invention also provides a scripting language-based link tracing device. It should be noted that the scripting language-based link tracing device of this invention includes multiple implementation units, which can be used to execute the scripting language-based link tracing method provided in the first embodiment above. Each implementation unit corresponds to each implementation step in the first embodiment above.
[0116] Figure 4 This is a schematic diagram of an optional scripting language-based link tracing device according to an embodiment of the present invention, such as... Figure 4 As shown, the device may include: a loading unit 41, a generating unit 42, an updating unit 43, and an extracting unit 44.
[0117] The loading unit 41 is used to load the link tracing configuration and use the link tracing configuration to initialize the server to obtain the target server. The target server contains at least an upload component and a record component.
[0118] The generation unit 42 is used to generate upstream link data and span data of the current request based on the network request when a network request is received.
[0119] The update unit 43 is used to update the link data entries based on upstream link data and span data by the recording component during the processing of network requests, and associate the index of the link data entries with the network request and save it as context information.
[0120] The extraction unit 44 is used to extract the link data entries related to the current request from the context information after the network request is processed, and to send the link data entries to the link tracing server through the upload component.
[0121] The aforementioned scripting-based link tracing device can first load the link tracing configuration through the loading unit 41 and use the link tracing configuration to initialize the server to obtain the target server. The target server includes at least an upload component and a recording component. Then, when a network request is received, the generation unit 42 generates upstream link data and the span data of the current request based on the network request. Then, during the processing of the network request, the update unit 43 updates the link data entries based on the upstream link data and span data through the recording component, associates the index of the link data entries with the network request, and saves it as context information. Finally, after the network request is processed, the extraction unit 44 extracts the link data entries related to the current request from the context information and uploads the link data entries to the link tracing server through the upload component.
[0122] In this embodiment of the invention, by using embedded programming in a scripting language and embedding link tracing logic into the critical lifecycle stages of the reverse distributed proxy server, the goal of automatically capturing and recording the entire network request link data is achieved. This enables comprehensive and seamless tracking of the service call link, overcoming the limitations of traditional link tracing technology. It can not only meticulously record the execution span of each link from the front end to the back end of the service, but also intelligently associate upstream and downstream link data to form a continuous and clear service request trajectory. This solves the technical problem in related technologies where incomplete coverage of the network request processing link leads to the link tracing system's inability to obtain complete link information.
[0123] Specifically, the link tracing logic can load the configuration when the server starts, achieving global initialization of link tracing and ensuring that the uploading and recording components are active. When the server receives a network request, it takes effect immediately, automatically capturing and parsing header information to generate upstream link data and span data specific to this request. Throughout the network request processing, it dynamically updates link data entries and closely associates the indexes of these data entries with the network request, storing them in the context information. This makes the proxy server no longer just a "transfer station" for traffic, but a "starting station" for link tracing. Once the network request is completed, it can accurately extract the link data related to this request based on the stored context information, ensuring timely and complete reporting to the link tracing server through the pre-set uploading mechanism. This achieves closed-loop management of link data, enhancing the practical value and analytical capabilities of the link tracing system.
[0124] Furthermore, the loading unit includes: a reading module for reading configuration information from the link tracing configuration, wherein the configuration information includes: service name, link tracing server address, and sampling rate; a loading module for loading a scripting language environment when starting the server based on the configuration information, wherein the scripting language environment is used to execute the link tracing script; a first initialization module for initializing the uploading component according to the link tracing server address; a second initialization module for initializing the recording component using the service name and sampling rate; and a setting module for setting a global status flag after completing the initialization operation to obtain the target server, wherein the global status flag is used to indicate that the target server is ready.
[0125] Furthermore, the generation unit includes: an extraction module, used to extract the request header information of the network request, and check the request header information to obtain the check result; a first generation module, used to set the upstream link data to null and generate the span data of this request based on the current timestamp when the check result indicates that the request header information does not contain the tracing information of the upstream service call; and a second generation module, used to generate the upstream link data and the span data of this request based on the request header information when the check result indicates that the request header information contains the tracing information of the upstream service call.
[0126] Furthermore, the second generation module includes: an extraction submodule, used to extract tracing information from the request header information to obtain upstream link data, wherein the tracing information includes an upstream tracing identifier and an upstream span identifier; a generation submodule, used to reuse the upstream tracing identifier as the tracing identifier for this request, and generate the span identifier for this request based on the upstream span identifier, wherein the upstream span identifier is the parent identifier of the span identifier for this request; and an integration submodule, used to integrate the tracing identifier, span identifier, and current timestamp for this request to obtain span data.
[0127] Furthermore, the updating unit includes: a determination module, used to obtain existing context information, determine whether there is a link data entry corresponding to the network request in the existing context information based on upstream link data, and obtain a determination result; a third generation module, used to generate a link data entry related to this request based on span data through a recording component when the determination result indicates that there is no link data entry corresponding to the network request; and an addition module, used to obtain the link data entry when the determination result indicates that there is a link data entry corresponding to the network request, and add the span data to the link data entry through a recording component, to obtain the updated link data entry.
[0128] Furthermore, the update unit also includes: a creation module, used to create a context entry when the determination result indicates that there is no link data entry corresponding to the network request, wherein the context entry contains an index pointing to the link data entry, which is used to directly locate the link data entry; an establishment module, used to establish the association between the network request and the index in the context entry, and store the context entry in the existing context information; an acquisition module, used to acquire the existing context entry corresponding to the link data entry in the context information when the determination result indicates that there is a link data entry corresponding to the network request; and an update module, used to update the index and link information in the existing context based on the parent-child relationship between the span identifier of the current request and the upstream span identifier.
[0129] Furthermore, the scripting language-based link tracing device also includes: a calculation module, used to calculate the time taken for the current request based on the timestamps in all extracted link data entries after extracting the link data entries related to the current request from the context information; and a packaging module, used to package the time taken for the current request and all link data entries together and send them to the link tracing server via an uploading component.
[0130] It should be noted that the loading unit 41, generating unit 42, updating unit 43, and extracting unit 44 mentioned above correspond to steps S201 to S204 in Embodiment 1. The instances and application scenarios implemented by the above units and corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules or units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above modules or units can also run as part of a device in the computer terminal 10 provided in Embodiment 1.
[0131] The invention will now be described in conjunction with another alternative embodiment.
[0132] Example 3
[0133] The present invention can also provide an electronic device. Figure 5 This is a structural block diagram of an electronic device that executes a scripting language-based link tracing method according to an embodiment of the present invention, such as... Figure 5 As shown, the electronic device may include: one or more ( Figure 5 Only one of the components is shown: processor 502, memory 504, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module, and display.
[0134] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the scripting language-based link tracing method and apparatus in this application embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the aforementioned scripting language-based link tracing method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0135] The processor can access information and applications stored in memory via the transmission device to perform the following steps: load the link tracing configuration and initialize the server using the link tracing configuration to obtain the target server, wherein the target server includes at least an upload component and a recording component; upon receiving a network request, generate upstream link data and span data of the current request based on the network request; during the processing of the network request, update the link data entries based on the upstream link data and span data through the recording component, associate the index of the link data entries with the network request, and save it as context information; after the network request is processed, extract the link data entries related to the current request from the context information, and upload the link data entries to the link tracing server through the upload component.
[0136] The processor can also invoke information and applications stored in memory via the transmission device to perform the following steps: read configuration information from the link tracing configuration, including: service name, link tracing server address, and sampling rate; load the scripting language environment when starting the server based on the configuration information, wherein the scripting language environment is used to execute the link tracing script; initialize the uploading component according to the link tracing server address; initialize the recording component using the service name and sampling rate; and set a global status flag after completing the initialization operation to obtain the target server, wherein the global status flag is used to indicate that the target server is ready.
[0137] The processor can also invoke information and applications stored in memory via the transmission device to perform the following steps: extract the request header information of the network request, and check the request header information to obtain the check result; if the check result indicates that the request header information does not contain trace information of upstream service calls, set the upstream link data to null and generate the span data of this request based on the current timestamp; or, if the check result indicates that the request header information contains trace information of upstream service calls, generate the upstream link data and the span data of this request based on the request header information.
[0138] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: extract the trace information in the request header information to obtain the upstream link data, wherein the trace information includes the upstream trace identifier and the upstream span identifier; reuse the upstream trace identifier as the trace identifier of this request, and generate the span identifier of this request based on the upstream span identifier, wherein the upstream span identifier is the parent identifier of the span identifier of this request; integrate the trace identifier, span identifier and current timestamp of this request to obtain the span data.
[0139] The processor can also invoke information and applications stored in the memory via the transmission device to perform the following steps: obtain existing context information, determine whether there is a link data entry corresponding to the network request in the existing context information based on upstream link data, and obtain a determination result; if the determination result indicates that there is no link data entry corresponding to the network request, generate a link data entry related to this request based on the span data through the recording component; or, if the determination result indicates that there is a link data entry corresponding to the network request, obtain the link data entry, and add the span data to the link data entry through the recording component to obtain an updated link data entry.
[0140] The processor can also invoke information and applications stored in memory via the transmission device to perform the following steps: if the result indicates that there is no link data entry corresponding to the network request, create a context entry, wherein the context entry contains an index pointing to the link data entry, which is used to directly locate the link data entry; establish an association between the network request and the index in the context entry, and store the context entry in the existing context information; or, if the result indicates that there is a link data entry corresponding to the network request, retrieve the existing context entry corresponding to the link data entry from the context information; update the index and link information in the existing context based on the parent-child relationship between the span identifier of this request and the upstream span identifier.
[0141] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: based on all the extracted link data entries, calculate the time taken for this request corresponding to the network request using the timestamps in the link data entries; and package the time taken for this request with all the link data entries and send it to the link tracing server through the upload component.
[0142] This invention provides a scripting language-based distributed tracing solution. By embedding distributed tracing logic into the critical lifecycle stages of a reverse distributed proxy server through scripting language embedded programming, it achieves the goal of automatically capturing and recording the entire network request chain data. This enables comprehensive and seamless tracing of the service call chain, overcoming the limitations of traditional distributed tracing technologies. It not only meticulously records the execution span of each link from the front-end to the back-end service but also intelligently correlates upstream and downstream chain data to form a continuous and clear service request trajectory. This solves the technical problem in related technologies where incomplete coverage of network request processing chains prevents the distributed tracing system from obtaining complete chain information.
[0143] Those skilled in the art will understand that Figure 5 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones, tablets, PDAs, mobile internet devices (M identifier), PADs, and other terminal devices. Figure 5 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 5 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 5 The different configurations shown.
[0144] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0145] The invention will now be described in conjunction with another alternative embodiment.
[0146] Example 4
[0147] This invention also provides a computer-readable storage medium. Optionally, in this invention, the computer-readable storage medium can be used to store the program code executed by the scripting language-based link tracing method provided in Embodiment 1.
[0148] Optionally, in this embodiment of the invention, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0149] This invention also provides a computer program product, which, when executed on a data processing device, is suitable for executing the steps of a scripting language-based link tracing method: loading a link tracing configuration and initializing a server using the link tracing configuration to obtain a target server, wherein the target server includes at least an upload component and a recording component; upon receiving a network request, generating upstream link data and span data of the current request based on the network request; during the processing of the network request, updating link data entries based on the upstream link data and span data through the recording component, associating the index of the link data entries with the network request, and saving it as context information; after the network request is processed, extracting the link data entries related to the current request from the context information, and uploading the link data entries to the link tracing server through the upload component.
[0150] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0151] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0152] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0153] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0154] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0155] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0156] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A link tracing method based on a scripting language, characterized in that, include: Load the link tracing configuration and use the link tracing configuration to initialize the server to obtain the target server, wherein the target server includes at least: an upload component and a recording component; Upon receiving a network request, upstream link data and the span data of this request are generated based on the network request; During the processing of the network request, the recording component updates the link data entry based on the upstream link data and the span data, and associates the index of the link data entry with the network request, saving it as context information; After the network request is processed, the link data entry related to the current request is extracted from the context information and sent to the link tracing server through the uploading component.
2. The link tracing method according to claim 1, characterized in that, The steps of initializing the server using the aforementioned link tracing configuration to obtain the target server include: Read the configuration information in the link tracing configuration, wherein the configuration information includes: service name, link tracing server address, and sampling rate; Based on the configuration information, a script language environment is loaded when the server starts, wherein the script language environment is used to execute the link tracing script; The uploading component is initialized based on the link tracing server address; The recording component is initialized using the service name and the sampling rate; After the initialization operation is completed, a global status flag is set to obtain the target server, wherein the global status flag is used to indicate that the target server is ready.
3. The link tracing method according to claim 1, characterized in that, The steps for generating upstream link data and span data of the current request based on the network request include: Extract the request header information of the network request, and examine the request header information to obtain the examination result; If the inspection result indicates that the request header information does not contain trace information of upstream service calls, the upstream link data is set to null, and the span data of this request is generated based on the current timestamp; or, If the inspection result indicates that the request header information contains trace information of upstream service calls, the upstream link data and the span data of this request are generated based on the request header information.
4. The link tracing method according to claim 3, characterized in that, The steps of generating the upstream link data and the span data of this request based on the request header information include: Extract the tracing information from the request header information to obtain the upstream link data, wherein the tracing information includes an upstream tracing identifier and an upstream span identifier; The upstream tracking identifier is reused as the tracking identifier for this request, and the span identifier for this request is generated based on the upstream span identifier, wherein the upstream span identifier is the parent identifier of the span identifier for this request. The span data is obtained by integrating the tracking identifier, the span identifier, and the current timestamp from this request.
5. The link tracing method according to claim 1, characterized in that, The step of updating the link data entry based on the upstream link data and the span data by the recording component includes: Obtain existing context information, and based on the upstream link data, determine whether there is a link data entry corresponding to the network request in the existing context information, and obtain the determination result; If the determination result indicates that there is no link data entry corresponding to the network request, the recording component generates a link data entry related to this request based on the span data; or... If the determination result indicates the existence of the link data entry corresponding to the network request, the link data entry is obtained, and the span data is added to the link data entry through the recording component to obtain the updated link data entry.
6. The link tracing method according to claim 5, characterized in that, The step of associating the index of the link data entry with the network request and saving it as context information includes: If the determination result indicates that there is no link data entry corresponding to the network request, a context entry is created, wherein the context entry contains an index pointing to the link data entry, which is used to directly locate the link data entry; Establish the association between the network request and the index in the context entry, and store the context entry in the existing context information; or, If the determination result indicates the existence of the link data entry corresponding to the network request, the existing context entry corresponding to the link data entry is obtained from the context information; Based on the parent-child relationship between the span identifier of this request and the upstream span identifier, update the index and link information in the existing context.
7. The link tracing method according to claim 1, characterized in that, After extracting the link data entries related to this request from the context information, the process further includes: Based on all the extracted link data entries, the time taken for the current network request is calculated using the timestamps in the link data entries. The upload component packages the request time and all the link data entries and uploads them to the link tracing server.
8. A link tracing device based on a scripting language, characterized in that, include: A loading unit is used to load the link tracing configuration and initialize the server using the link tracing configuration to obtain the target server, wherein the target server includes at least an upload component and a recording component; The generation unit is used to generate upstream link data and span data of the current request based on the network request when a network request is received. The update unit is used to update the link data entry based on the upstream link data and the span data through the recording component during the processing of the network request, and associate the index of the link data entry with the network request and save it as context information; The extraction unit is used to extract the link data entry related to the current request from the context information after the network request is processed, and to send the link data entry to the link tracing server through the uploading component.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device containing the computer-readable storage medium to perform the link tracing method based on any one of claims 1 to 7.
10. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the scripting language-based link tracing method according to any one of claims 1 to 7.
11. A computer program product, characterized in that, It includes computer instructions, wherein when executed by a processor, the computer instructions implement the steps of the scripting language-based link tracing method according to any one of claims 1 to 7.