Logging tool
A logging tool system, product and method for employing within a live production environment, the logging tool comprising: a mock stack configured to track function executions of a computer program; an endpoint module configured to track invocations of endpoints; and a plurality of hooks embedded within functions of interest of the computer program, wherein the plurality of hooks is configured to interact with the mock stack and the endpoint module during execution of the computer program, wherein the logging tool is configured to determine, for an invocation of a function, whether a call flow of the function is firstly encountered, and wherein the logging tool is configured to determine, based on the endpoint module, at least one endpoint that triggered the invocation of the function.
1 . A method comprising:
initializing a mock stack of a logging tool, the mock stack is initialized within a data segment belonging to a process executing a computer program, the data segment is separate from a stack segment used for a call stack of the computer program, the process is executed within the live production environment;
tracking, by the mock stack, function executions of the computer program and maintaining indications of the function executions within the data segment;
tracking, by an endpoint module, invocations of endpoints and the maintaining indications of the invocations within the data segment;
interacting, by a plurality of hooks, that are embedded within functions of interest of the computer program, with the mock stack and the endpoint module during execution of the computer program;
determining, by the logging tool, for an invocation of a function that is hooked by a hook of the plurality of hooks, whether a call flow of the function is firstly encountered, wherein the call flow of the function comprises a flow from a calling function of the functions of interest that invoked the function to the function, wherein the call flow of the function is identified based on the mock stack; and
determining, by the logging tool, at least one endpoint that triggered the invocation of the function, based on the endpoint module.
2 . The method of claim 1 , further comprising:
counting, by the logging tool, a number of occurrences of the call flow within a reporting time window; and
reporting the number to a server after the reporting time window elapses.
3 . The method of claim 1 , further comprising:
adding an indication of the function, by the logging tool, to the mock stack upon the invocation of the function; and
removing, by the logging tool, the indication upon execution termination of the function.
4 . The method of claim 1 , further comprising:
adding, by the logging tool, an indication of an endpoint to the endpoint module upon invocation of the endpoint; and
removing, by the logging tool, the indication after one or more chains of function calls invoked by the endpoint, complete a termination.
5 . The method of claim 4 , wherein the endpoint comprises at least one of:
an API;
a service entry point;
a cron job;
a queue management service; and
a webhook.
6 . The method of claim 1 , wherein the function is part of a chain of function calls that is triggered by multiple endpoints, and the method further comprising:
adding indications of the multiple endpoints to the endpoint module; and
associating the function with the multiple endpoints.
7 . The method of claim 1 , wherein the mock stack and the endpoint module are implemented as first and second global variables, respectively, within a data segment of the process.
8 . The method of claim 1 , wherein the mock stack and the endpoint module are maintained within a heap of the process.
9 . The method of claim 1 , wherein the indications of the function executions comprise unique identifiers that uniquely identify each of the functions of interest upon execution.
10 . The method of claim 1 , further comprising
performing a complete data collection of an execution of the function upon determining that the call flow of the function is firstly encountered;
setting a sampling rate for the function upon determining that a subsequent call flow of the function was already encountered, thereby performing an incomplete data collection, the subsequent call flow comprises the flow from the calling function to the function, the subsequent call flow is invoked after the call flow.
11 . The method of claim 10 , wherein the sampling rate for the function is configured to gradually decrease as a number of invocations of the call flow increases.
12 . The method of claim 1 , further comprising:
applying a first sampling rate for the function; and
upon determining that an exception occurs during an execution of the function, adjusting the first sampling rate to a second sampling rate, the second sampling rate is greater than the first sampling rate.
13 . The method of claim 1 , further comprising:
selectively sampling performance data of invocations of the function over a defined time window;
aggregating sampled performance data over the defined time window, thereby obtaining aggregated data, wherein the aggregated data comprises at least the number of occurrences of the call flow and performance data of the occurrences of the call flow; and
transmitting the aggregated data to a server.
14 . The method of claim 13 , wherein the performance data comprises at least one of:
an overall average execution time of the function over all call flows and endpoints;
an average execution time of the function for the call flow;
an average execution time of the function for the endpoint;
a percentile execution time of the function over all call flows and endpoints;
a percentile execution time of the function for the call flow;
a percentile execution time of the function for the endpoint;
computational resource consumption of the function; and
a memory usage of the function.
15 . The method of claim 14 , further comprising:
determining a total invocation count of the function;
determining a sampled invocation count of the function; and
calculating the overall average execution time based on a ratio between the total invocation count and the sampled invocation count.
16 . The method of claim 1 , wherein the plurality of hooks comprises a plurality of pre-hooks and post-hooks, wherein the pre-hooks and post-hooks are used to instrument the functions of interest, wherein the pre-hooks are configured to register the functions of interest to the mock stack, wherein the post-hooks are configured to remove registrations of the functions of interest after their executions terminate.
17 . The method of claim 1 , wherein the plurality of hooks comprises a mid-hook that is embedded prior to an asynchronous primitive of the function, wherein the mid-hook is configured to be invoked mid-execution of the function, wherein the mid-hook is configured to extract an indication of the function from the mock stack before the asynchronous primitive is executed, and to restore the indication after termination of the asynchronous primitive.
18 . A system comprising a processor and coupled memory, said processor is adapted to execute a logging tool within a live production environment, said processor being adapted to:
instrument a computer program with a plurality of hooks, the plurality of hooks is embedded within functions of interest of the computer program;
initialize a mock stack of the logging tool, the mock stack is initialized within a data segment belonging to a process executing the computer program, the data segment is separate from a stack segment used for a call stack of the computer program, the process is executed within the live production environment;
track, using the mock stack, function executions of the computer program and maintain indications of the function executions;
initialize an endpoint module in the data segment,
track, using the endpoint module invocations of endpoints and maintain indications of the invocations,
direct the plurality of hooks to interact with the mock stack and with the endpoint module during execution of the computer program;
determine, for an invocation of a function that is hooked by a hook of the plurality of hooks, whether a call flow of the function is firstly encountered, wherein the call flow of the function comprises a flow from a calling function that invoked the function to the function, wherein the call flow of the function is identified based on the mock stack; and
determine, based on the endpoint module, at least one endpoint that triggered the invocation of the function.
19 . The system of claim 18 , wherein the functions of interest are selected by a user.
20 . A computer program product comprising a non-transitory computer readable medium retaining program instructions, which program instructions when read by a processor, cause the processor to execute a logging tool within a live production environment, said processor being adapted to:
instrument a computer program with a plurality of hooks, the plurality of hooks is embedded within functions of interest of the computer program;
initialize a mock stack of the logging tool, the mock stack is initialized within a data segment belonging to a process executing the computer program, the data segment is separate from a stack segment used for a call stack of the computer program, the process is executed within the live production environment;
track, using the mock stack, function executions of the computer program and to maintain indications of the function executions;
initialize an endpoint module in the data segment;
track, using the endpoint module, invocations of endpoints and maintain indications of the invocations;
direct the plurality of hooks to interact with the mock stack and with the endpoint module during execution of the computer program;
determine, for an invocation of a function that is hooked by a hook of the plurality of hooks, whether a call flow of the function is firstly encountered, wherein the call flow of the function comprises a flow from a calling function that invoked the function to the function, wherein the call flow of the function is identified based on the mock stack; and
determine, based on the endpoint module, at least one endpoint that triggered the invocation of the function.