CN114398179B - Method and device for acquiring tracking identifier, server and storage medium - Google Patents

Method and device for acquiring tracking identifier, server and storage medium Download PDF

Info

Publication number
CN114398179B
CN114398179B CN202210042168.3A CN202210042168A CN114398179B CN 114398179 B CN114398179 B CN 114398179B CN 202210042168 A CN202210042168 A CN 202210042168A CN 114398179 B CN114398179 B CN 114398179B
Authority
CN
China
Prior art keywords
identifier
candidate
coroutine
tracking
identification
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210042168.3A
Other languages
Chinese (zh)
Other versions
CN114398179A (en
Inventor
解路连
黄道巍
王宇航
曾鹏轩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Siming Qichuang Technology Co ltd
Original Assignee
Beijing Siming Qichuang Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Siming Qichuang Technology Co ltd filed Critical Beijing Siming Qichuang Technology Co ltd
Priority to CN202210042168.3A priority Critical patent/CN114398179B/en
Publication of CN114398179A publication Critical patent/CN114398179A/en
Application granted granted Critical
Publication of CN114398179B publication Critical patent/CN114398179B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/542Event management; Broadcasting; Multicasting; Notifications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/547Messaging middleware
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a device for acquiring a tracking identifier, a server and a storage medium. The method comprises the following steps: under the condition that an identification acquisition request initiated by the current coroutine is detected, acquiring a current coroutine identification of the current coroutine; acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request; and writing the target tracking identification into a basic component. By the scheme of the embodiment, the problems of large workload and redundancy existing when context parameters are added in each function in the prior art are solved, the tracking identifier is determined based on the association relationship between the tracking identifier and the coroutine identifier, and the efficiency of obtaining the full link log can be improved.

Description

Method and device for acquiring tracking identifier, server and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a method and a device for acquiring a tracking identifier, a server and a storage medium.
Background
The micro-service architecture has the advantages of micro-service loose coupling and fast iteration by splitting a single application into a plurality of micro-services for deployment, and can greatly reduce the service complexity. Under the microservice architecture, one user service often involves the invocation of multiple microservices.
In order to locate and track the abnormality in the micro service architecture, a log tracking scheme is usually adopted to track micro service logs related to user services, which may be called full link logs, so as to locate and track the problem in the micro service architecture by analyzing the full link logs. In the prior art, usually, a trace identifier (traceID) is added into a context parameter and is passed down when a function is called. To achieve the purpose of using the traceID at any time, a context parameter needs to be added to each function, and the workload is increased. In addition, as each function does not need to use the context information, the redundancy of the functions is increased, and the efficiency of obtaining the full link log is further reduced.
Therefore, how to set and acquire the trace identifier to efficiently obtain the full link log becomes a problem that needs to be solved by those skilled in the art.
Disclosure of Invention
The invention provides a method and a device for acquiring a tracking identifier, a server and a storage medium, which aim to improve the acquisition efficiency of the tracking identifier.
In a first aspect, an embodiment of the present invention provides a method for acquiring a tracking identifier, where the method is applied to a server, and the method includes:
acquiring a current coroutine program identifier of a current coroutine program under the condition of detecting an identifier acquisition request initiated by the current coroutine program;
acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request;
writing the target tracking identification to a base component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
In a second aspect, an embodiment of the present invention further provides an apparatus for acquiring a tracking identifier, where the apparatus includes:
a current coroutine identification obtaining module, configured to obtain a current coroutine identification of a current coroutine when an identification obtaining request initiated by the current coroutine is detected;
the target tracking identifier acquisition module is used for acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request;
the target tracking identifier writing module is used for writing the target tracking identifier into a basic component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
In a third aspect, an embodiment of the present invention further provides a server, where the server includes:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for acquiring the tracking identifier according to any embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for acquiring the tracking identifier according to any embodiment of the present invention.
The method, the device, the server and the storage medium for acquiring the tracking identifier provided by the embodiment of the invention acquire the current protocol identifier of the current protocol by detecting the identifier acquisition request initiated by the current protocol; acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request; writing the target tracking identification to a base component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component. According to the scheme of the embodiment, the problems of large workload and redundancy existing when context parameters are added in each function in the prior art are solved, the tracking identifier is determined based on the association relation between the tracking identifier and the coroutine identifier, and the tracking identifier is written into the basic component, so that the efficiency of obtaining full-link logs subsequently can be improved, and a new thought is provided for obtaining the tracking identifier.
Drawings
Fig. 1 is a flowchart of a method for acquiring a tracking identifier according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for acquiring a tracking identifier according to a second embodiment of the present invention;
fig. 3 is a flowchart of a method for acquiring a tracking identifier according to a third embodiment of the present invention;
fig. 4 is a block diagram of a device for acquiring a tracking identifier according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of a server according to a fifth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a method for acquiring a trace identifier according to an embodiment of the present invention, which is applicable to a situation where a trace identifier is acquired by printing a log or calling a hypertext Transfer protocol (HTTP), and is particularly applicable to mapping a coroutine identifier and a trace identifier and matching the trace identifier with the coroutine identifier. The method can be executed by the device for acquiring the tracking identifier provided by the embodiment of the invention, and the device can be implemented in a software and/or hardware manner and can be integrated on a server.
Specifically, as shown in fig. 1, the method for acquiring a tracking identifier according to an embodiment of the present invention may include the following steps:
s110, under the condition that an identification obtaining request initiated by the current coroutine is detected, obtaining a current coroutine identification of the current coroutine.
The coroutine is a bottom-layer scheduling unit, which is not managed by the kernel of the operating system, but is completely controlled by the program, namely, is executed in a user mode. This has the advantage of a substantial increase in performance because resources are not consumed as in thread switching.
Coroutines are not processes or threads, but rather are special functions that may be suspended somewhere and may resume running at the suspension. Coroutines are therefore not a single-dimensional concept as compared to processes and threads. A process may contain multiple threads, and a thread may also contain multiple coroutines. In short, a plurality of such special functions can be executed in one thread, but it must be understood that the execution of the coroutines in one thread is serial. In the case of a multi-core CPU, multiple processes or multiple threads within a process can run in parallel, but a coroutine within a thread is absolutely serial, no matter how many cores the CPU has. After all, the corollary is a special function but still a function. Multiple functions may be run within a thread, but these functions are run serially. While one coroutine is running, other coroutines must be suspended.
It should be noted that, in this embodiment, the coroutine identifier is a relatively unique identifier in the coroutine system, and is equivalent to an "identity card", and is generally not changed in the life cycle, and specifically, after the coroutine is finished, the coroutine identifier may be recovered, and may also be reused by other coroutines. What is used for identification can be determined by the rules set by the designer himself.
Similarly, the tracking identifier (traceID) is also unique and unique. the traceID is used to identify a specific request ID at a time. After a user request enters a system, a globally unique traceID is generated at the first layer of a Remote Procedure Call (RPC) network and is continuously transmitted back along with the RPC Call of each layer, so that paths called in the system by the user request can be connected in series through the traceID to perform link tracking.
And if the current coroutine needs to acquire the tracking identifier, initiating an identifier acquisition request. Specifically, print logs and HTTP calls often use trace identifiers during service administration. In view of the fact that the workload of directly adding the context parameter to each function is large, the function redundancy is realized, and the calling efficiency is low, in the embodiment, before the tracking identifier is obtained, a first association relationship between the candidate tracking identifier and the candidate coroutine identifier is established by using a coroutine identifier and a tracking identifier mapping method. Under the condition that an identification acquisition request initiated by the current coroutine is detected, the current coroutine identification of the current coroutine is acquired to determine a target tracking identification according to the current coroutine identification, and each function is not required to have a context parameter to transmit information, so that the function redundancy can be reduced, and the acquisition efficiency of the tracking identification is improved.
S120, acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by the client and a candidate coroutine for processing the event request.
The target tracking identifier can be simply understood as a tracking identifier to be acquired.
Under the condition that the first association relationship between the candidate tracking identifier and the candidate coroutine identifier is determined, after the current coroutine identifier of the current coroutine is obtained, the current coroutine identifier can be matched with the first association relationship between the candidate tracking identifier and the candidate coroutine identifier, and the tracking identifier associated with the current coroutine identifier is obtained as the target tracking identifier. The first incidence relation is determined according to an event request initiated by the client and a candidate coroutine for processing the event request.
Preferably, the determining the first association relationship according to the event request initiated by the client and the candidate routine for processing the event request may include: receiving an event request initiated by a client, and determining a candidate tracking identifier of the event request; determining candidate coroutine identifiers of candidate coroutines for processing the event request; and establishing a first association relation between the candidate tracking identifier and the candidate coroutine identifier based on the candidate tracking identifier and the candidate coroutine identifier.
S130, writing the target tracking identification into the basic component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
After the target tracking identification is determined, the target tracking identification may be written to the base component. Wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
Specifically, the log printing component is configured to format the log when the log is printed, where the format is: time-coroutine identification-tracking identification-log content; the message header transmission component is used for adding the traceIDA into the HTTP header when the HTTP is called, so that the upstream HTTP service can obtain the same traceIDA; and the database printing component is used for customizing the log by using a SetLogger () function of gorm, and when the mysql log is printed, traceIDA is carried over as the log is printed.
Taking the example that after the target tracking identifier is determined, the target tracking identifier is written into the log, and the service log after being written has the tracking identifier, which requests are the same in the log can be distinguished.
Further, on the basis of the above embodiment, in order to improve the efficiency and accuracy of the anomaly location, if an anomaly is detected, the processing logic of the program is determined according to the target tracking identifier in the log; according to the processing logic, an exception is located.
According to the technical scheme of the embodiment, the current coroutine identification of the current coroutine is acquired under the condition that the identification acquisition request initiated by the current coroutine is detected; acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; determining a first incidence relation according to an event request initiated by a client and a candidate coroutine for processing the event request; the target tracking identification is written to the base component. According to the scheme of the embodiment, the problems that in the prior art, when the context parameters are added to each function, the workload is large and redundancy exists are solved, the tracking identifier is determined based on the incidence relation between the tracking identifier and the coroutine identifier, and is written into the basic component, so that the efficiency of obtaining the full-link log can be improved, and a new idea is provided for obtaining the tracking identifier.
Example two
Fig. 2 is a flowchart of a method for acquiring a tracking identifier according to a second embodiment of the present invention, which is further optimized based on the second embodiment, and provides a description of a specific case where a first association relationship is determined according to an event request initiated by a client and a candidate routine for processing the event request.
Specifically, as shown in fig. 2, the method includes:
s210, receiving an event request initiated by a client, and determining a candidate tracking identifier of the event request.
Wherein the candidate tracking identifier may uniquely identify the event request. In this embodiment, after receiving an event request initiated by a client, a corresponding candidate tracking identifier may be determined according to the event request. For example, if an HTTP request is received, since the traceID is in the header of the HTTP, the traceID may be taken out from the header as a candidate traceID.
Considering that not all headers contain a traceID, in this embodiment, in order to ensure that the traceID is accurately obtained after receiving the event request, preferably, receiving the event request initiated by the client and determining the candidate tracking identifier of the event request may include: receiving an event request initiated by a client, and judging whether a candidate tracking identifier exists in a message associated with the event request; if yes, determining candidate tracking identification from a message header of the message; otherwise, generating a candidate tracking identifier of the event request through a snowflake algorithm.
By way of example, HTTP is used as an example to explain: the client sends an HTTP request, when the HTTP request passes through nginx, the nginx generates a traceIDA, and the traceIDA is added into an HTTP message header, and Ht-Trace-Id = traceIDA; the nginx reverse proxy sends the request to the service; the service receives the HTTP request, and takes Ht-Trace-Id = traceIDA out of the header. If there is no traceIDA in the header, a snowflake algorithm is used to generate a traceIDA.
Preferably, in addition to obtaining the HTTP request, when the service is used as a timed task or a message queue consumer, if the timed time of the timed task is reached or the message queue consumes the message, the candidate tracking identifier may also be generated using a snowflake algorithm.
S220, determining candidate coroutine identification of the candidate coroutine for processing the event request.
The candidate coroutine identification is used for uniquely identifying the candidate coroutine. It should be noted that, the candidate coroutine identifiers for determining the candidate coroutines for processing the event request and the candidate tracking identifiers for determining the event request have no clear sequence, and may be performed simultaneously or not simultaneously.
Specifically, the candidate coroutine identifier of the candidate coroutine for processing the event request is determined, and the candidate coroutine identifier of the candidate coroutine 1 for processing the event request may be obtained by using a gitub.
S230, establishing a first association relation between the candidate tracking identification and the candidate coroutine identification based on the candidate tracking identification and the candidate coroutine identification.
In this embodiment, the first association relationship between the candidate tracking identifier and the candidate coroutine identifier is established based on the candidate tracking identifier and the candidate coroutine identifier, which may be simply understood as associating the event request with the coroutine for processing the request.
Because the candidate tracking identification can uniquely determine the event request, and the candidate coroutine identification can uniquely determine the candidate coroutine, in order to facilitate query, the effect of associating the event request with the coroutine for processing the request can be achieved by establishing the first association relationship between the candidate tracking identification and the candidate coroutine identification.
For example, establishing a first association relationship between the candidate tracking identity and the candidate coroutine identity, map GID1 and traceIDA may be mapped to gTraceMap using sync.
When the traceID needs to be used, acquiring the protocol identifier GID1 of the current protocol, then acquiring the traceIDA from the gTraceMap, and then performing the following logic as required:
A. and packaging the log library. When the log is printed, the log is formatted as follows: time-protocol identification-trace identification-log content.
HTTP call. At the time of calling, traceIDA is added to the HTTP header, so that the upstream HTTP service can also obtain the same traceIDA.
Mysql call. Using the firm's SetLogger () function, the log is custom, and when printing mysql log, the traceIDA is taken as it was when printing the log. redis or kafka calls the same way, taking traceIDA when printing the log.
S240, under the condition that an identification obtaining request initiated by the current coroutine is detected, obtaining the current coroutine identification of the current coroutine.
S250, acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by the client and a candidate coroutine for processing the event request.
S260, writing the target tracking identifier into the basic component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
According to the technical scheme, a concrete situation introduction that the first association relation is determined according to the event request initiated by the client and the candidate coroutine for processing the event request is given, the problems of large workload and redundancy existing when context parameters are added in each function in the prior art are solved by mapping the coroutine identification and the tracking identification, the tracking identification is determined based on the association relation between the tracking identification and the coroutine identification, the target tracking identification is convenient to take out at any time, and the efficiency of obtaining the full-link log can be improved.
EXAMPLE III
Fig. 3 is a flowchart of a method for acquiring a tracking identifier according to a third embodiment of the present invention, which is further optimized based on the third embodiment, and provides a description of a specific situation where a concurrent task is detected.
Specifically, as shown in fig. 3, the method includes:
s310, under the condition that an identification obtaining request initiated by the current coroutine is detected, obtaining a current coroutine identification of the current coroutine.
S320, acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by the client and a candidate coroutine for processing the event request.
S330, in the execution process of the current coroutine, if a concurrent task is detected, creating a subprocess of the current coroutine.
The concurrent operation means that in an operating system, several programs are in a period from the time when the programs are started to the time when the programs are completely run, and the programs are all run on the same processor, but only one program is run on the processor at any time point; logically, the system has the capability of simultaneously processing a plurality of tasks. If the multi-program runs on a single thread or a single process, the multi-program has the characteristic of concurrency.
In this embodiment, when asynchronization is required, a coroutine is created. It can be understood that, during the execution process of the current coroutine, if a concurrent task is detected, a subprocess of the current coroutine is created.
Illustratively, instead of creating directly using a go keyword, a function may be created using encapsulated goroutine. The encapsulation function executes as follows: acquiring a local negotiation identifier GID1, and then acquiring traceIDA from a gTraceMap; creating a subprogram GID2 by using the go keywords, and transmitting traceIDA to the subprogram; storing GID2 and traceIDA of the subprocess into a gTraceMap, wherein key is GID2, and value is traceIDA; when the son coroutine needs to print a log, call HTTP, mysql, redis and message queues, as with the father coroutine, traceIDA is taken according to GID2 and then used.
S340, transmitting the target tracking identification to the subprogram, and acquiring a subprogram identification of the subprogram.
After creating the subprocess of the current coroutine, acquiring a subprocess identifier of the subprocess, and transmitting the target tracking identifier corresponding to the current coroutine to the subprocess to establish the association between the target tracking identifier and the candidate subprocess.
And S350, establishing a second association relation between the target tracking identifier and the candidate sub-coroutine identifier.
It should be noted that, this embodiment only takes establishing the second association between the target tracking identifier and the candidate sub-coroutine identifier as an example for description, and does not limit that only two-layer coroutine relationship exists.
If a second subprogram exists on the subprogram lower layer, establishing a third correlation between the target tracking identifier and the candidate second subprogram identifier; if a third subprogram exists on the lower layer of the second subprogram, establishing a fourth association relation between the target tracking identifier and the candidate third subprogram identifier; by analogy, a multilayer incidence relation can be established.
And S360, under the condition that the identification acquisition request initiated by the target subprogram is detected, determining the target tracking identification associated with the target subprogram based on the second association relation.
Similarly, when the identifier obtaining request initiated by the target subprogram is detected, the target tracking identifier associated with the target subprogram is determined based on the second association relationship, which is not limited herein. In addition, when an identifier acquisition request initiated by the target second subprocess is detected, the target tracking identifier associated with the target second subprocess may be determined based on the third association relationship; when an identifier acquisition request initiated by the target third subprocess is detected, a target tracking identifier associated with the target third subprocess can be determined based on the fourth association relation; and so on.
S370, writing the target tracking identification into the basic component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
According to the technical scheme, when asynchronization is needed, the subprocess is created, the target tracking identifier is transmitted to the subprocess, the second association relation between the target tracking identifier and the candidate subprocess identifier is established, the target tracking identifier associated with the target subprocess is determined based on the second association relation, the purpose of tracking through the association relation when multiple layers of calling are achieved, and the tracking efficiency is improved.
Example four
Fig. 4 is a schematic structural diagram of an apparatus for acquiring a tracking identifier according to a fourth embodiment of the present invention, where the apparatus is adapted to execute the method for acquiring a tracking identifier according to the fourth embodiment of the present invention, so as to improve the efficiency of acquiring a tracking identifier. As shown in fig. 4, the apparatus includes a current negotiation identity obtaining module 410, a target tracking identity obtaining module 420, and a target tracking identity writing module 430.
The current negotiation procedure identifier obtaining module 410 is configured to obtain a current negotiation procedure identifier of a current negotiation procedure when an identifier obtaining request initiated by the current negotiation procedure is detected;
a target tracking identifier obtaining module 420, configured to obtain, according to a first association relationship between a candidate tracking identifier and a candidate coroutine identifier, a tracking identifier associated with a current coroutine identifier as a target tracking identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request;
a target tracking identity writing module 430, configured to write a target tracking identity into the base component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component.
According to the technical scheme of the embodiment, the current coroutine identification of the current coroutine is acquired under the condition that the identification acquisition request initiated by the current coroutine is detected; acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; determining a first incidence relation according to an event request initiated by a client and a candidate coroutine for processing the event request; the target tracking identification is written to the base component. By the scheme of the embodiment, the problems of large workload and redundancy when context parameters are added in each function in the prior art are solved, the tracking identifier is determined based on the incidence relation between the tracking identifier and the coroutine identifier, the efficiency of obtaining the full-link log is improved, and a new idea is provided for obtaining the tracking identifier.
Preferably, the apparatus further comprises:
the candidate tracking identifier determining module is used for receiving an event request initiated by a client and determining candidate tracking identifiers of the event request;
the candidate coroutine identification determining module is used for determining candidate coroutine identifications of the candidate coroutines for processing the event request;
and the first association relation establishing module is used for establishing a first association relation between the candidate tracking identifier and the candidate coroutine identifier on the basis of the candidate tracking identifier and the candidate coroutine identifier.
Preferably, the candidate tracking identifier determining module is specifically configured to receive an event request initiated by a client, and determine whether a candidate tracking identifier exists in a message associated with the event request; if yes, determining candidate tracking identification from a message header of the message; otherwise, generating a candidate tracking identifier of the event request through a snowflake algorithm.
Preferably, the apparatus further comprises:
the subprogram creating module is used for creating the subprogram of the current coroutine program if a concurrent task is detected in the execution process of the current coroutine program;
the subprogram identification acquisition module is used for transmitting the target tracking identification to the subprogram and acquiring a subprogram identification of the subprogram;
the second association relation establishing module is used for establishing a second association relation between the target tracking identifier and the candidate subprocess identifier;
and the target tracking identifier acquisition module is further used for determining a target tracking identifier associated with the target subprocess based on the second association relation under the condition that an identifier acquisition request initiated by the target subprocess is detected.
Preferably, the apparatus further comprises:
the processing logic determining module is used for determining the processing logic of the program according to the target tracking identifier in the log if the abnormality is detected;
and the exception positioning module is used for positioning the exception according to the processing logic.
The device for acquiring the tracking identifier provided by the embodiment of the invention can execute the method for acquiring the tracking identifier provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
EXAMPLE five
Fig. 5 is a schematic structural diagram of a server according to a fifth embodiment of the present invention. FIG. 5 illustrates a block diagram of an exemplary server 12 suitable for use in implementing embodiments of the present invention. The server 12 shown in fig. 5 is only an example, and should not bring any limitation to the function and the use range of the embodiment of the present invention.
As shown in fig. 5, the server 12 is in the form of a general purpose computing device. The components of the server 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro Channel Architecture (MCA) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
The server 12 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by server 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. The server 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 5, and commonly referred to as a "hard drive"). Although not shown in FIG. 5, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination of which may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
The server 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with the server 12, and/or with any devices (e.g., network card, modem, etc.) that enable the server 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the server 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the Internet) via the network adapter 20. As shown, the network adapter 20 communicates with the other modules of the server 12 via the bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the server 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, to name a few.
The processing unit 16 executes various functional applications and data processing by executing programs stored in the system memory 28, for example, to implement the tracking identifier acquisition method provided by the embodiment of the present invention.
Example six
The sixth embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for obtaining the tracking identifier according to any embodiment of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will appreciate that the present invention is not limited to the particular embodiments described herein, and that various obvious changes, rearrangements and substitutions will now be apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (8)

1. A method for acquiring tracking identification is applied to a server, and comprises the following steps:
under the condition that a tracking identification acquisition request initiated by the current coroutine is detected, acquiring a current coroutine identification of the current coroutine;
acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request;
writing the target tracking identification to a base component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component;
the method for determining the first association relationship according to the event request initiated by the client and the candidate routine for processing the event request comprises the following steps:
receiving an event request initiated by a client, and determining a candidate tracking identifier of the event request;
determining candidate coroutine identifiers of candidate coroutines for processing the event request;
and establishing a first association relation between the candidate tracking identifier and the candidate coroutine identifier on the basis of the candidate tracking identifier and the candidate coroutine identifier.
2. The method of claim 1, wherein receiving an event request initiated by a client and determining a candidate tracking identifier for the event request comprises:
receiving an event request initiated by a client, and judging whether a candidate tracking identifier exists in a message associated with the event request;
if yes, determining a candidate tracking identifier from a message header of the message;
otherwise, generating the candidate tracking identification of the event request through a snowflake algorithm.
3. The method of claim 1, further comprising:
in the execution process of the current coroutine, if a concurrent task is detected, creating a subprocess of the current coroutine;
transmitting the target tracking identification to the subprogram, and acquiring a subprogram identification of the subprogram;
establishing a second association relation between the target tracking identifier and the candidate subprocess identifier;
and under the condition that an identification acquisition request initiated by the target subprocess is detected, determining a target tracking identification associated with the target subprocess based on the second association relation.
4. The method of claim 1, further comprising:
if the abnormality is detected, determining the processing logic of the program according to the target tracking identification in the log;
locating the exception according to the processing logic.
5. An apparatus for obtaining tracking identification, the apparatus comprising:
the system comprises a current coroutine identification acquisition module, a tracking identification acquisition module and a tracking identification acquisition module, wherein the current coroutine identification acquisition module is used for acquiring a current coroutine identification of a current coroutine under the condition of detecting a tracking identification acquisition request initiated by the current coroutine;
the target tracking identifier acquisition module is used for acquiring a tracking identifier associated with the current coroutine identifier as a target tracking identifier according to a first association relation between the candidate tracking identifier and the candidate coroutine identifier; the first incidence relation is determined according to an event request initiated by a client and a candidate coroutine for processing the event request;
the target tracking identifier writing module is used for writing the target tracking identifier into a basic component; wherein the base assembly comprises at least one of: the system comprises a log printing component, a message header transmission component and a database printing component;
wherein the apparatus further comprises:
the candidate tracking identifier determining module is used for receiving an event request initiated by a client and determining a candidate tracking identifier of the event request;
a candidate coroutine identification determining module, configured to determine a candidate coroutine identification of a candidate coroutine for processing the event request;
and the first association relation establishing module is used for establishing a first association relation between the candidate tracking identifier and the candidate coroutine identifier on the basis of the candidate tracking identifier and the candidate coroutine identifier.
6. The apparatus of claim 5, further comprising:
the subprogram creating module is used for creating the subprogram of the current corogram if a concurrent task is detected in the execution process of the current corogram;
a subprocess identification obtaining module, configured to transmit the target tracking identification to the subprocess, and obtain a subprocess identification of the subprocess;
the second association relation establishing module is used for establishing a second association relation between the target tracking identifier and the candidate subprogram identifier;
the target tracking identifier obtaining module is further configured to determine, based on the second association relationship, a target tracking identifier associated with the target subprocess, when the identifier obtaining request initiated by the target subprocess is detected.
7. A server, characterized in that the server comprises:
one or more processors;
a storage device to store one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a method of obtaining a tracking identity as claimed in any one of claims 1 to 4.
8. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out a method for obtaining a tracking identity according to any one of claims 1 to 4.
CN202210042168.3A 2022-01-14 2022-01-14 Method and device for acquiring tracking identifier, server and storage medium Active CN114398179B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210042168.3A CN114398179B (en) 2022-01-14 2022-01-14 Method and device for acquiring tracking identifier, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210042168.3A CN114398179B (en) 2022-01-14 2022-01-14 Method and device for acquiring tracking identifier, server and storage medium

Publications (2)

Publication Number Publication Date
CN114398179A CN114398179A (en) 2022-04-26
CN114398179B true CN114398179B (en) 2023-03-14

Family

ID=81230556

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210042168.3A Active CN114398179B (en) 2022-01-14 2022-01-14 Method and device for acquiring tracking identifier, server and storage medium

Country Status (1)

Country Link
CN (1) CN114398179B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115022410A (en) * 2022-05-27 2022-09-06 北京有竹居网络技术有限公司 Network request tracking method, device and equipment
CN117032844B (en) * 2023-10-07 2024-01-09 北京集度科技有限公司 Cooperative link tracking device and method and intelligent vehicle

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108810097A (en) * 2018-05-21 2018-11-13 千寻位置网络有限公司 The method and system of Web magnanimity timely collection NMEA data
CN110069358A (en) * 2019-04-18 2019-07-30 彩讯科技股份有限公司 Call chain trace analysis method, apparatus, electronic equipment and storage medium
CN112000429A (en) * 2020-08-06 2020-11-27 北京浪潮数据技术有限公司 Connection tracking deletion method, device and equipment of cloud platform management platform
CN112328410A (en) * 2020-11-04 2021-02-05 网易(杭州)网络有限公司 Method, device, equipment and storage medium for realizing remote procedure call
CN112965832A (en) * 2021-02-18 2021-06-15 腾讯科技(深圳)有限公司 Remote Procedure Call (RPC) service calling method and related device
CN113094136A (en) * 2021-04-09 2021-07-09 广州博冠信息科技有限公司 Page display control method and device, storage medium and electronic equipment
WO2021151312A1 (en) * 2020-08-07 2021-08-05 平安科技(深圳)有限公司 Method for determining inter-service dependency, and related apparatus
CN113626213A (en) * 2021-03-31 2021-11-09 中汽创智科技有限公司 Event processing method, device and equipment and computer readable storage medium
CN113867913A (en) * 2021-09-27 2021-12-31 平安国际智慧城市科技股份有限公司 Business request processing method, device, equipment and storage medium for microservice

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10747645B2 (en) * 2018-04-27 2020-08-18 Microsoft Technology Licensing, Llc Selectively tracing portions of computer process execution
CN113448936A (en) * 2020-03-25 2021-09-28 阿里巴巴集团控股有限公司 Log tracking method, device, server, system and storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108810097A (en) * 2018-05-21 2018-11-13 千寻位置网络有限公司 The method and system of Web magnanimity timely collection NMEA data
CN110069358A (en) * 2019-04-18 2019-07-30 彩讯科技股份有限公司 Call chain trace analysis method, apparatus, electronic equipment and storage medium
CN112000429A (en) * 2020-08-06 2020-11-27 北京浪潮数据技术有限公司 Connection tracking deletion method, device and equipment of cloud platform management platform
WO2021151312A1 (en) * 2020-08-07 2021-08-05 平安科技(深圳)有限公司 Method for determining inter-service dependency, and related apparatus
CN112328410A (en) * 2020-11-04 2021-02-05 网易(杭州)网络有限公司 Method, device, equipment and storage medium for realizing remote procedure call
CN112965832A (en) * 2021-02-18 2021-06-15 腾讯科技(深圳)有限公司 Remote Procedure Call (RPC) service calling method and related device
CN113626213A (en) * 2021-03-31 2021-11-09 中汽创智科技有限公司 Event processing method, device and equipment and computer readable storage medium
CN113094136A (en) * 2021-04-09 2021-07-09 广州博冠信息科技有限公司 Page display control method and device, storage medium and electronic equipment
CN113867913A (en) * 2021-09-27 2021-12-31 平安国际智慧城市科技股份有限公司 Business request processing method, device, equipment and storage medium for microservice

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
FastAPI 全链路日志追踪;endRuz;《https://zhuanlan.zhihu.com/p/432010113》;1-2 *
Mining the use of higher-order functions;Yisen Xu等;《Empirical Software Engineering》;4547-4584 *
基于的trace_id链路追踪;码上得天下;《https://blog.csdn.net/meser88/article/details/120187184》;1-6 *
增强现实作品创作平台的设计与实现;李全亮;《中国优秀硕士学位论文全文数据库 信息科技辑》;I138-1859 *

Also Published As

Publication number Publication date
CN114398179A (en) 2022-04-26

Similar Documents

Publication Publication Date Title
CN114398179B (en) Method and device for acquiring tracking identifier, server and storage medium
CN110069358A (en) Call chain trace analysis method, apparatus, electronic equipment and storage medium
WO2021259013A1 (en) Data processing method and apparatus, electronic device, and computer-readable medium
US9497095B2 (en) Dynamic control over tracing of messages received by a message broker
CN111563014A (en) Interface service performance test method, device, equipment and storage medium
CN112313627B (en) Mapping mechanism of event to serverless function workflow instance
CN111625422B (en) Thread monitoring method, thread monitoring device, electronic equipment and computer readable storage medium
CN111966653A (en) Data processing method, device, server and storage medium for micro-service call link
US8984124B2 (en) System and method for adaptive data monitoring
CN110457132B (en) Method and device for creating functional object and terminal equipment
CN111414263A (en) Information processing method, device, server and storage medium
CN113238815B (en) Interface access control method, device, equipment and storage medium
CN113111666B (en) System and method for realizing multi-language translation of application program
CN113760562A (en) Link tracking method, device, system, server and storage medium
CN113625998A (en) Request processing method and device
CN112364109A (en) Event service association method, system, device, electronic equipment and storage medium
CN111611479A (en) Data processing method and related device for network resource recommendation
CN115499493A (en) Asynchronous transaction processing method and device, storage medium and computer equipment
CN112950447B (en) Resource scheduling method, device, server and storage medium
CN114168607A (en) Global serial number generation method, device, equipment, medium and product
CN114443480A (en) Test method, test system, readable medium and electronic device
CN113849287A (en) Processing method and device of algorithm service, electronic equipment and storage medium
CN112818204A (en) Service processing method, device, equipment and storage medium
CN114764324A (en) Enterprise resource planning system and integration method thereof
CN112364268A (en) Resource acquisition method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant