Observability data acquisition method and device of Go source code
By compiling and enhancing the Go source code, and using OpenTelemetry's API and SDK, non-intrusive monitoring data reporting in Go language is realized, which solves the cumbersome problem of manual tracking, improves monitoring efficiency and functions, and supports link tracking and monitoring indicators. .
Patent Information
- Application Number
- CN202410797593.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2024-01-18
- Filing Date
- 2024-06-20
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-06-20
AI Technical Summary
The Go language cannot automate instrumentation when obtaining observability data, requiring developers to manually embed points in the business code for monitoring, resulting in a cumbersome and inefficient monitoring process.
By introducing the proxy module, OpenTelemetry's API and SDK are used to compile and enhance the Go source code, generate modified code, and initialize Tracer and Metrics instances when the executable file is running, achieving non-intrusive monitoring data reporting and supporting link tracking. and the ability to monitor indicators.
Implemented non-intrusive support for OpenTelemetry in Go language, automated the acquisition and reporting of monitoring data, simplified the development process, supported link tracking and monitoring indicator functions, improved the application of compilation enhancement in the observable field, and avoided manual burying of points. cumbersome operations.
Smart Images

Figure CN118672918A
Abstract
Description
[0001] This application claims priority to a patent application with application number CN202410070581.X, application date January 18, 2024, and patent name “A method and device for acquiring observability data of Go source code”. Technical Field
[0002] The present application relates to the field of observability technology, and more specifically, to a method and device for obtaining observability data of Go source code. Background Art
[0003] Traditional service monitoring for microservice applications, such as obtaining observability data, mainly adopts the solution of instrumentation in business code. The solution is to launch different APM SDKs or Agents for different languages. However, some development languages such as Go and C are difficult to achieve automatic instrumentation. Only SDK packages can be provided for manual instrumentation. Developers need to manually instrument in the business code to achieve monitoring. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a method and device for obtaining observability data of Go source code, so as to solve the problem that when obtaining observability data for the Go language, it is impossible to automatically insert piles, and developers need to manually embed points in the business code to achieve monitoring.
[0005] An embodiment of the present application provides a method for obtaining observability data of a Go source code, including:
[0006] Use the proxy module to introduce OpenTelemetry's API and SDK. The proxy module includes an API part and an implementation part.
[0007] Compile and enhance the business side's Go source code to obtain the modified code;
[0008] Compile the modified code together with the Go source code to get an executable file;
[0009] During the execution of the executable file, the proxy module is used to call the OpenTelemtry API and initialize the Tracer instance and / or Metrics instance of OpenTelemetry. The initialized Tracer instance and / or Metrics instance is used to use the tracing data reporter to report observability data; observability data includes tracing data and / or metric data.
[0010] In the above technical solution, by connecting to the compilation enhancement capability provided by Golang, the business system can be non-invasively connected to the monitoring system of OpenTelemetry. The compilation parameters are automatically embedded through the continuous integration / continuous delivery (CI / CD) system, and the business side has no perception. The upgrade action can also be automatically completed through the CI / CD system. This embodiment realizes non-invasive support for OpenTelemetry through the proxy module, thereby expanding the application of compilation enhancement in the observable field, not only supporting the link tracking function, but also expanding the support for the monitoring indicator function.
[0011] In some optional implementations, Go source code is compiled and enhanced, including:
[0012] Enhance the runtime package of the Go source code to allow plugin developers to store custom variables in the goroutine context;
[0013] Enhance the agent core plugin to provide the ability to copy the agent module plugin directory, associate the enhanced content in the runtime package, and provide a series of initialization functions for external calls;
[0014] Enhance the program entry to provide the ability to call the initialization program;
[0015] Enhance the plug-in to detect whether the module needs to be enhanced, detect third-party models introduced by the business side, and match the abstract syntax tree inside the module;
[0016] Enhance metrics to provide the ability to inject metrics monitoring functionality into the API.
[0017] In the above technical solutions, custom variable storage allows plug-in developers to store custom variables in the goroutine context by enhancing the runtime package of the Go source code, which allows developers to set and obtain custom variables for specific goroutines at runtime, providing a more flexible plug-in development experience. Proxy module plug-in directory replication, by enhancing the proxy core plug-in, provides the ability to copy the proxy module plug-in directory, so that plug-in developers can easily copy their plug-in directory to the program running directory, avoiding the trouble of manual copying and configuration. External initialization function call, providing a series of initialization functions for external calls, so that developers can call these functions at the program entry or other appropriate locations to complete the initialization of the plug-in. Module enhancement detection and abstract syntax tree (AST) application, by enhancing the plug-in to detect whether the module needs to be enhanced and detect the third-party model introduced by the business party, and matching the abstract syntax tree inside the module, so that developers can more easily apply AST, so as to conduct more in-depth code analysis and modification. Indicator monitoring function injection, by enhancing indicators, providing API capabilities to inject indicator monitoring functions, so that developers can implement custom indicator monitoring in the program, so as to better understand the program's running status and performance. In general, these compilation enhancements provide more flexible and powerful plug-in development support, making it easier for developers to develop, configure, and deploy plug-ins.
[0018] In some optional implementations, the observability data also includes log data;
[0019] Compilation enhancement of Go source code also includes: enhancing the logrus and zap logging frameworks to achieve the coupling of logs and observation data.
[0020] In the above technical solution, by coupling the log framework with the observation data, the log information and observable data (such as indicators, tracking, etc.) can be displayed in the same context. This makes it easier for developers to better understand the program running status and quickly locate and solve problems.
[0021] In some optional implementations, initializing a Tracer instance and / or a Metrics instance of OpenTelemetry includes:
[0022] The Tracer instance and / or Metrics instance is initialized by calling the init method according to the parameters passed by the user. The user can pass the parameters by implicitly passing them through environment variables or configuration files.
[0023] In the above technical solution, by calling the init method, the parameters passed by the user can be used to initialize the Tracer and Metrics instances, which can make the initialization process more flexible and configurable. Users can pass specific parameters, such as tracer name, metric name and label of metrics, etc. to control the initialization and configuration of the instance. Users can define the configuration of Tracer and Metrics instances by passing parameters, such as sampling rate, buffer size, etc., which can meet different usage scenarios and requirements and make the configuration of the instance more customized and flexible. By encapsulating the initialization logic in the init method, the initialization process of Tracer and Metrics instances can be simplified. Users only need to call the init method and pass the necessary parameters to complete the initialization of the instance without manual tedious configuration and settings.
[0024] In some optional implementations, during the execution of the executable file, the following steps are also included:
[0025] By calling the performance analysis tool pprof provided by the Go language, performance analysis is performed to obtain performance data; the performance data includes CPU usage and / or memory allocation and / or lock allocation.
[0026] In the above technical solution, by using the performance analysis tool pprof that comes with the Go language, performance data including CPU usage, memory allocation, and lock allocation can be obtained, so as to comprehensively evaluate and analyze the performance of the program. These data can help developers understand the performance of the program in the use of various resources, and provide an important basis for optimizing program performance. By performing performance analysis when the program is running, the performance data of the program can be obtained in real time. This is very helpful for timely discovering and solving performance problems of the program during operation, and can avoid unexpected performance bottlenecks in the program in the production environment. Based on the obtained performance data, developers can perform in-depth performance tuning of the program. For example, according to the CPU usage, optimize the algorithm and data structure to reduce unnecessary calculations; optimize the memory management strategy according to the memory allocation to avoid memory leaks and unnecessary memory allocation; optimize the concurrency control strategy according to the lock allocation to improve concurrency performance. The data obtained through performance analysis can also be used for troubleshooting and diagnosis. When the program has performance degradation or abnormal behavior, the possible problem can be found by analyzing these data, so as to locate and solve potential faults more quickly. During the development process, the performance of the program can be tested and evaluated through performance analysis. This helps ensure that the developed programs have excellent performance in various scenarios and meet the needs of users.
[0027] In some optional implementations, the Go source code is compiled and enhanced to obtain a modified code, including:
[0028] Dynamically link the Setter function, which is used to assign the initialized Tracer instance and / or Metrics instance to the global variable by means of dynamic linking during the execution of the executable file, so that the agent module can use the Tracer instance and / or Metrics instance by calling the Tracer API and / or Metrics API.
[0029] In the above technical solution, by assigning Tracer instances and / or Metrics instances to global variables, the proxy module can easily access and call these instances anywhere. This avoids repeated API calls or other complex operations in the proxy module, improving the efficiency and readability of the code. Dynamic linking makes it possible to use Tracer instances and / or Metrics instances on different operating systems and platforms. Even in different environments, only simple configuration and settings are required without modifying the underlying code.
[0030] In some optional implementations, during the execution of the executable file, the following steps are also included:
[0031] The proxy module assigns the initialized Tracer instance and / or Metrics instance to the global variable through the Setter function dynamically linked at compile time;
[0032] The agent module calls global variables through the Tracer API and / or the Metrics API to call the OpenTelemetry API.
[0033] An observability data acquisition device for Go source code provided in an embodiment of the present application includes:
[0034] The import module is used to import the OpenTelemetry API and SDK using the proxy module. The proxy module includes an API part and an implementation part.
[0035] The compilation module is used to compile and enhance the Go source code of the business party to obtain the modified code; the modified code is mixed and compiled with the Go source code to obtain an executable file;
[0036] The running module is used to use the proxy module to call the OpenTelemtry API during the execution of the executable file, and initialize the Tracer instance and / or Metrics instance of OpenTelemetry, and use the initialized Tracer instance and / or Metrics instance to use the tracing data reporter to report observability data; observability data includes tracing data and / or metric data.
[0037] An electronic device provided in an embodiment of the present application includes: a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, any of the above methods is performed.
[0038] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, any of the above methods is executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 A flowchart of a method for obtaining observability data of a Go source code provided in an embodiment of the present application;
[0041] Figure 2 A schematic diagram of the process of compiling and enhancing Go source code provided in an embodiment of the present application;
[0042] Figure 3 A flowchart of the steps for implementing OpenTelemetry injection provided in an embodiment of the present application;
[0043] Figure 4 A flowchart of the steps of performance analysis supported by the proxy module provided in the embodiment of the present application;
[0044] Figure 5 A possible structural diagram of an electronic device provided in an embodiment of the present application.
[0045] Icon: 1-processor, 2-memory, 3-communication interface, 4-communication bus. DETAILED DESCRIPTION
[0046] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0047] First introduce some terms involved in this application:
[0048] OpenTelemetry is an open source project for collecting, processing, exporting, and analyzing observation data in distributed systems, such as monitoring metrics, logs, and traces. The purpose of this project is to provide a consistent, efficient, and convenient end-to-end monitoring solution for distributed systems, especially microservices.
[0049] Tracing: OpenTelemetry provides tools and APIs to collect tracing data to help developers understand how requests propagate in distributed systems.
[0050] Performance indicators (Metrics): It can collect indicator data, such as latency, throughput, or custom business indicators. Usually a kind of statistical data.
[0051] OpenTelemetry provides APIs and SDKs in multiple programming languages, such as Java, Python, Go, JavaScript, etc., to help application developers connect to various languages and frameworks. OpenTelemetry has designed an extensible Exporter architecture that allows you to send data to a variety of monitoring, tracing, and logging platforms, including but not limited to Prometheus, Jaeger, Zipkin, and many other commercial solutions.
[0052] Profiling is a technique for analyzing software applications to provide detailed information about which parts of the program execution take up most of the time and / or resources. In the field of observability, profiling has become an important tool to supplement traditional metrics, logging, and tracing.
[0053] While traditional metrics and tracebacks can tell us how long a system or application takes to respond, they can't tell us why. Profilers can drill down to the code level and tell us which functions or methods are taking up most of the processing time. Through performance profiling, developers and operations teams can understand which parts of the code use the most CPU, memory, I / O and other resources. This is particularly important for optimizing resource usage and controlling costs.
[0054] OpenTelemetry provides APIs and SDKs for integration with applications, but developers need to spend a lot of manpower to understand and use the tools and methods provided by OpenTelemetry, and choose the appropriate SDK and version. In large enterprises, this integration method is often inefficient, and developers from various business teams need to do a lot of repetitive work. In addition, when it is necessary to upgrade the SDK version, all teams need to cooperate with the upgrade action.
[0055] OpenTelemetry currently provides an automatic tracing tool based on eBPF, but the eBPF-based implementation has the following defects: 1. It has relatively high requirements for the kernel version and Golang version; 2. It has a relatively large performance loss on the application: executing eBPF programs requires frequent switching between kernel mode and user mode.
[0056] Apache SkyWalking Go uses compilation enhancement technology to track Golang programs, but it can only support SkyWalking private protocols and cannot adapt to the widely used OpenTelemetry and OpenTracing technology stacks. At the same time, SkyWalking Go cannot support performance analysis.
[0057] Based on this, an embodiment of the present application provides a method for obtaining observability data of Go source code, so as to realize non-intrusive support of OpenTelemetry in GO language, thereby obtaining a solution for observability data.
[0058] Please refer to Figure 1 , Figure 1 A flowchart of a method for obtaining observability data of a Go source code provided in an embodiment of the present application specifically includes:
[0059] Step 100: Use the proxy module to introduce the OpenTelemetry API and SDK; the proxy module includes an API part and an implementation part;
[0060] Step 200: Compile and enhance the Go source code of the business party to obtain the modified code;
[0061] Step 300: compile the modified code together with the Go source code to obtain an executable file;
[0062] Step 400: During the execution of the executable file, the proxy module is used to call the OpenTelemtry API, and the Tracer instance and / or Metrics instance of OpenTelemetry is initialized. The initialized Tracer instance and / or Metrics instance is used to use the tracing data reporter to report observability data; the observability data includes tracing data and / or metric data.
[0063] Among them, the compilation enhancement solution has certain limitations. For example, new dependencies cannot be used in third-party enhanced modules, and only standard libraries and modules that the modules originally depend on can be used. This makes it difficult to introduce modules similar to OpenTelemetry. Therefore, this embodiment needs to import the Go module of OpenTelemetry in the proxy module and its submodules. That is, Go does not allow the introduction of new dependent modules during the mixed compilation process, so the purpose of the import here is to provide a dependency tree basis for subsequent mixed compilation.
[0064] By creating a Tracer instance, developers can collect and transmit tracing data related to application execution. By creating a Metrics instance, developers can collect and transmit metric data related to application execution.
[0065] In the embodiment of the present application, by connecting to the compilation enhancement capability provided by Golang, the business system can be non-invasively connected to the monitoring system of OpenTelemetry, and the compilation parameters are automatically embedded through the continuous integration / continuous delivery (CI / CD) system. The business party has no perception, and the upgrade action can also be automatically completed through the CI / CD system. This embodiment realizes non-invasive support for OpenTelemetry through the proxy module, thereby expanding the application of compilation enhancement in the observable field, not only supporting the link tracking function, but also expanding the support for the monitoring indicator function.
[0066] In some optional implementations, please refer to Figure 2 , Figure 2 The schematic diagram of the process of compiling and enhancing the Go source code provided in the embodiment of the present application includes:
[0067] The runtime package of the Go source code is enhanced to allow plug-in developers to store custom variables in the goroutine context; the proxy core plug-in is enhanced to provide the ability to copy the proxy module plug-in directory, associate the enhanced content in the runtime package, and provide a series of initialization functions for external calls; the program entry is enhanced to provide the ability to call the initialization program; the plug-in is enhanced to detect whether the module needs to be enhanced, detect the third-party model introduced by the business party, and match the abstract syntax tree inside the module; the indicators are enhanced to provide the ability to inject the indicator monitoring function API.
[0068] The runtime package is an important package in the Go programming language standard library, which is used to handle the runtime operations and underlying system management of Go programs. It provides functions for interacting with the runtime status of programs and the system, including coroutine management, garbage collection, memory allocation, and underlying thread control.
[0069] Goroutine is a lightweight thread implementation in the Go language. It is a lightweight abstraction built on top of threads and managed by the Go runtime. Goroutine allows us to execute multiple functions or methods in parallel in the same address space at a very low cost. Compared with threads, its creation and destruction costs are much smaller, and its scheduling is independent of threads. In the Go language, each concurrent execution unit is called a goroutine. We only need to add the go keyword in front of the called function to make the function run as a coroutine. The concurrent design of the Go language is centered on goroutine. Compared with threads, it is lighter and easier to use, so it can run thousands of concurrent tasks at the same time. Goroutine is a key component for the Go language to implement concurrent programming.
[0070] Logrus is a structured, pluggable Go log framework that is fully compatible with the official log library interface and also provides custom plug-in functionality. Enhancing logrus may include adding more plug-ins, such as two optional log output formats, TEXT and JSON, or more refined logging and distribution through the Field mechanism and extensible HOOK mechanism.
[0071] Zap is a high-performance logging framework. Its overall architecture includes API interface, log encoding and log writing. Enhancing Zap may include adding more internal modules, optimizing encoding management, improving writing performance, etc.
[0072] In the embodiment of the present application, the control of the compilation process is realized by injecting the program through the -toolexec parameter provided by the Go compilation tool chain. Among them, custom variable storage, by enhancing the runtime package of the Go source code, allows plug-in developers to store custom variables in the goroutine context, which allows developers to set and obtain custom variables for specific goroutines at runtime, providing a more flexible plug-in development experience. Proxy module plug-in directory replication, by enhancing the proxy core plug-in, provides the ability to copy the proxy module plug-in directory, so that plug-in developers can easily copy their plug-in directory to the program running directory, avoiding the trouble of manual copying and configuration. External initialization function call, providing a series of initialization functions for external calls, so that developers can call these functions at the program entry or other appropriate locations to complete the initialization of the plug-in. Module enhancement detection and abstract syntax tree (AST) application, by enhancing the plug-in to detect whether the module needs to be enhanced and detect the third-party model introduced by the business party, and matching the abstract syntax tree inside the module, so that developers can more easily apply AST, so as to perform more in-depth code analysis and modification. Indicator monitoring function injection, by enhancing indicators and providing API capabilities to inject indicator monitoring functions, developers can implement customized indicator monitoring in the program to better understand the program's running status and performance. In general, these compilation enhancements provide more flexible and powerful plug-in development support, allowing developers to more easily develop, configure and deploy plug-ins.
[0073] Among them, during the compilation process of the Go language, the -toolexec parameter allows you to specify an executable file that will be used to construct the tool chain, that is, the execution environment of the Go language compiler and linker. Using the -toolexec parameter, you can specify a custom executable file to replace the default tool chain execution environment of the Go language. This custom executable file should be able to receive and process the command line parameters of the Go language compiler through command line parameters, and return the corresponding compilation and linking results. By using the -toolexec parameter, you can integrate a custom tool chain execution environment into the build process, such as for performing specific compilation optimizations, custom link scripts, or other build tool chains.
[0074] In some optional implementations, the observability data also includes log data; and the compilation enhancement of the Go source code also includes: enhancing the logrus and zap log frameworks to achieve coupling of logs and observation data.
[0075] In the embodiment of the present application, by coupling the log framework with the observation data, the log information and observability data (such as indicators, tracking, etc.) can be displayed in the same context. This makes it easier for developers to better understand the program running status and quickly locate and solve problems.
[0076] In some optional implementations, under the compilation enhancement framework, automatic framework enhancement still has certain limitations. The embodiment of the present application also supports users to directly interact with the API provided by the proxy module to realize the manual indicator collection function. The method of this function and other auxiliary methods for constructing indicator options are empty methods before compilation enhancement, which can ensure that the program will not go wrong even if compilation enhancement is not performed. During compilation, the package name is matched through the indicator plug-in, and the method logic is replaced. The modules referenced by both before and after compilation are the same, so compilation failure will not occur.
[0077] In some optional embodiments, initializing the Tracer instance and / or Metrics instance of OpenTelemetry includes: initializing the Tracer instance and / or Metrics instance by calling the init method and according to the parameters passed by the user; wherein the method in which the user passes the parameters includes implicitly passing through environment variables or configuration files.
[0078] Among them, the init method is a special method in the class. It is a magic method inherited by the class name by default and is used to initialize the class. This method is essentially an object method, but it does not need to be called by the programmer. It will be called automatically when the object is created. When creating an object through a class (that is, creating an object through a constructor), the system will automatically call the init method in the class and pass the single actual parameter in the constructor to the init method. The function of the init method is to initialize the created object, and it is usually used to assign values to the attributes of the object.
[0079] In an embodiment of the present application, by calling the init method, the parameters passed by the user can be used to initialize the Tracer and Metrics instances, which can make the initialization process more flexible and configurable. The user can pass specific parameters, such as the tracer name, the metric name and label of the metrics, etc., to control the initialization and configuration of the instance. The user can define the configuration of the Tracer and Metrics instances by passing parameters, such as sampling rate, buffer size, etc., which can meet different usage scenarios and requirements and make the configuration of the instance more customized and flexible. By encapsulating the initialization logic in the init method, the initialization process of the Tracer and Metrics instances can be simplified. The user only needs to call the init method and pass the necessary parameters to complete the initialization of the instance without manual cumbersome configuration and settings.
[0080] In some optional implementations, during the execution of the executable file, it also includes: performing performance analysis by calling the performance analysis tool pprof provided by the Go language to obtain performance data; the performance data includes CPU usage and / or memory allocation and / or lock allocation.
[0081] Specifically, the performance analysis flow chart is as follows Figure 4 As shown in the figure, the core module in the agent module references the profiling module. The agent / core module initializes and creates the manager in the profiling module. The profiling manager starts the background task. Through the scheduled task, it polls the control plane service to check whether there are performance analysis tasks that can be run. If there are tasks that can be executed, the performance analysis task is executed immediately by calling the start method of the runner. After the task is completed, the execution result is uploaded to the control plane service.
[0082] In the embodiment of the present application, by using the performance analysis tool pprof that comes with the Go language, performance data including CPU usage, memory allocation, and lock allocation can be obtained, so as to comprehensively evaluate and analyze the performance of the program. These data can help developers understand the performance of the program in the use of various resources, and provide an important basis for optimizing program performance. By performing performance analysis when the program is running, the performance data of the program can be obtained in real time. This is very helpful for timely discovering and solving performance problems of the program during operation, and can avoid unexpected performance bottlenecks in the program in the production environment. Based on the obtained performance data, developers can perform in-depth performance tuning of the program. For example, according to the CPU usage, optimize the algorithm and data structure to reduce unnecessary calculations; optimize the memory management strategy according to the memory allocation to avoid memory leaks and unnecessary memory allocation; optimize the concurrency control strategy according to the lock allocation to improve concurrency performance. The data obtained by performance analysis can also be used for troubleshooting and diagnosis. When the program has performance degradation or abnormal behavior, the possible problem can be found by analyzing these data, so as to locate and solve potential faults more quickly. During the development process, the performance of the program can be tested and evaluated by performance analysis. This helps ensure that the developed programs have excellent performance in various scenarios and meet the needs of users.
[0083] In some optional implementations, the Go source code is compiled and enhanced to obtain modified code, including: dynamically linking a Setter function, where the Setter function is used to assign the initialized Tracer instance and / or Metrics instance to a global variable by dynamically linking during the execution of the executable file, so that the proxy module can use the Tracer instance and / or Metrics instance by calling the TracerAPI and / or Metrics API.
[0084] In the embodiment of the present application, by assigning Tracer instances and / or Metrics instances to global variables, the proxy module can easily access and call these instances anywhere. This avoids repeated API calls or other complex operations in the proxy module, and improves the efficiency and readability of the code. Dynamic linking makes it possible to use Tracer instances and / or Metrics instances on different operating systems and platforms. Even in different environments, only simple configuration and settings are required without modifying the underlying code.
[0085] In some optional implementations, during the execution of the executable file, it also includes: the proxy module assigns the initialized Tracer instance and / or Metrics instance to the global variable through the Setter function dynamically linked at compile time; the proxy module calls the global variable through the Tracer API and / or Metrics API to implement the call of the OpenTelemetry API.
[0086] In a specific embodiment, please refer to Figure 3 , Figure 3 The flowchart of the OpenTelemetry injection implementation steps provided in the embodiment of the present application includes the Tracer API and Metrics API of the proxy module. This part of the API implicitly calls the OpenTelemetry SDK and API through the linker mechanism, which specifically includes the following steps:
[0087] The agent module directly imports the OpenTelemetry API and SDK.
[0088] When the program is running, the agent module initializes the core modules, including OpenTelemetry's Tracer, through the init method using the parameters passed by the user.
[0089] When the program is running, the proxy module assigns the initialized Tracer to the global variable global_operator in the runtime module through the Setter function dynamically linked at compile time.
[0090] The Enhanced Method method that is identified and enhanced during program compilation inserts the enhanced functions Before Method and After Method in the method declaration (the function of the enhanced functions Before Method and After Method is to add some additional operations before and after the execution of the method). These two functions are called at runtime (when compiling the enhancement, part of the SDK source code in the proxy module will be copied to the mixed compilation working directory) The TracerAPI provided by the SDK in the proxy module, and finally the Tracer API of the SDK in the proxy module calls the global variable global_operator, thereby calling the underlying OpenTelemetry API.
[0091] The implementation of the indicator plug-in in this embodiment is also similar, and will not be repeated here.
[0092] Figure 5 A possible structure of an electronic device provided in an embodiment of the present application is shown. Figure 5 The electronic device includes: a processor 1, a memory 2 and a communication interface 3. These components are interconnected and communicate with each other through a communication bus 4 and / or other forms of connection mechanisms (not shown).
[0093] The memory 2 includes one or more (only one is shown in the figure), which may be, but not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The processor 1 and other possible components can access the memory 2 and read and / or write data therein.
[0094] The processor 1 includes one or more (only one is shown in the figure), which can be an integrated circuit chip with signal processing capabilities. The above-mentioned processor 1 can be a general-purpose processor, including a central processing unit (CPU), a micro control unit (MCU), a network processor (NP) or other conventional processors; it can also be a special-purpose processor, including a neural network processor (NPU), a graphics processor (GPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. In addition, when there are multiple processors 1, some of them can be general-purpose processors and the other part can be special-purpose processors.
[0095] The communication interface 3 includes one or more (only one is shown in the figure), which can be used to communicate directly or indirectly with other devices to exchange data. The communication interface 3 can include an interface for wired and / or wireless communication.
[0096] One or more computer program instructions may be stored in the memory 2, and the processor 1 may read and execute these computer program instructions to implement the method provided in the embodiment of the present application.
[0097] Understandably, Figure 5 The structure shown is for illustration only. The electronic device may also include Figure 5 More or fewer components as shown, or with Figure 5 Different structures are shown. Figure 5 The components shown in the figure can be implemented by hardware, software or a combination thereof. The electronic device may be a physical device, such as a PC, a laptop, a tablet computer, a mobile phone, a server, an embedded device, etc., or a virtual device, such as a virtual machine, a virtualized container, etc. Moreover, the electronic device is not limited to a single device, but may also be a combination of multiple devices or a cluster consisting of a large number of devices.
[0098] The present application also provides a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are read and executed by a computer processor, the method provided by the present application is executed. For example, the computer-readable storage medium can be implemented as Figure 5 Memory 2 in an electronic device.
[0099] An embodiment of the present application also provides a device for acquiring observability data of a Go source code, including: an import module, a compilation module, and a running module.
[0100] Among them, the introduction module is used to use the proxy module to introduce the OpenTelemetry API and SDK; the proxy module includes an API part and an implementation part; the compilation module is used to compile and enhance the business party's Go source code to obtain the modified code; the modified code is mixed with the Go source code to obtain an executable file; the running module is used to call the OpenTelemtry API using the proxy module during the running of the executable file, and initialize the Tracer instance and / or Metrics instance of OpenTelemetry, and use the initialized Tracer instance and / or Metrics instance to use the tracing data reporter to report observability data; observability data includes tracking data and / or metric data.
[0101] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0102] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0103] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0104] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0105] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for obtaining observability data of Go source code, characterized in that: include: Use the proxy module to introduce OpenTelemetry's API and SDK. The proxy module includes an API part and an implementation part. Compile and enhance the business side's Go source code to obtain the modified code; Compile the modified code together with the Go source code to obtain an executable file; During the running of the executable file, the proxy module is used to call the OpenTelemtry API, and the Tracer instance and / or Metrics instance of OpenTelemetry is initialized. The initialized Tracer instance and / or Metrics instance is used to use the tracing data reporter to report observability data; the observability data includes tracing data and / or metric data.
2. The method according to claim 1, characterized in that The compiling and enhancing the Go source code includes: Enhance the runtime package of the Go source code to allow plugin developers to store custom variables in the goroutine context; Enhance the agent core plugin to provide the ability to copy the agent module plugin directory, associate the enhanced content in the runtime package, and provide an initialization function for external calls; Enhance the program entry to provide the ability to call the initialization program; Enhance the plug-in to detect whether the module needs to be enhanced, detect third-party models introduced by the business side, and match the abstract syntax tree inside the module; Enhance metrics to provide the ability to inject metrics monitoring functionality into the API.
3. The method according to claim 2, characterized in that The observability data also includes log data; The compilation enhancement of the Go source code also includes: enhancing the logrus and zap log frameworks to achieve coupling between logs and observation data.
4. The method according to claim 1, characterized in that Initializing the Tracer instance and / or Metrics instance of OpenTelemetry includes: The Tracer instance and / or Metrics instance is initialized by calling the init method according to the parameters passed by the user; wherein the method in which the user passes the parameters includes implicitly passing through environment variables or configuration files.
5. The method according to claim 1, characterized in that During the execution of the executable file, the following steps are also included: By calling the performance analysis tool pprof provided by the Go language, performance analysis is performed to obtain performance data; the performance data includes CPU usage and / or memory allocation and / or lock allocation.
6. The method according to claim 1, characterized in that The Go source code is compiled and enhanced to obtain a modified code, including: A dynamically linked Setter function is used to assign the initialized Tracer instance and / or Metrics instance to a global variable by means of a dynamic link during the execution of the executable file, so that the proxy module can use the Tracer instance and / or Metrics instance by calling the Tracer API and / or Metrics API.
7. The method according to claim 6, characterized in that During the execution of the executable file, the following steps are also included: The proxy module assigns the initialized Tracer instance and / or Metrics instance to the global variable through the Setter function dynamically linked at compile time; The agent module calls global variables through the Tracer API and / or the Metrics API to call the OpenTelemetry API.
8. A Go source code observability data acquisition device, characterized in that: include: The import module is used to import the OpenTelemetry API and SDK using the proxy module. The proxy module includes an API part and an implementation part. A compilation module is used to compile and enhance the Go source code of the business party to obtain a modified code; the modified code is mixed and compiled with the Go source code to obtain an executable file; The running module is used to use the proxy module to call the OpenTelemtry API during the running of the executable file, and initialize the Tracer instance and / or Metrics instance of OpenTelemetry, and use the initialized Tracer instance and / or Metrics instance to use the tracing data reporter to report observability data; the observability data includes tracing data and / or metric data.
9. An electronic device, characterized in that: include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, the method according to any one of claims 1 to 7 is performed.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, which, when executed by a processor, executes the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Link determination method and device, equipment, medium and product
CN115865645A
Block chain network test method and related device
CN116455782A
Instrumentation method for realizing code vaccine and application test method based on code vaccine
CN116775040A
Data processing method and device
CN117076250A
Edge-Based Data Collection System for an Observability Pipeline System
US20230259438A1
