A method and device for obtaining observability data of Go source code
By compiling and enhancing the Go source code, the proxy module of OpenTelemetry is introduced, which solves the problem of automated instrumentation of Go observable data acquisition, realizes a non-invasive monitoring system, supports link tracking and monitoring indicators, and improves development efficiency and adaptability.
Patent Information
- Application Number
- CN202410797593.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2024-01-18
- Filing Date
- 2024-06-20
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2044-06-20
AI Technical Summary
In the prior art, the acquisition of observability data in Go language cannot automate instrumentation, and developers need to manually bury points to achieve monitoring, resulting in inefficiency and difficulty in scaling.
By introducing proxy modules, using OpenTelemetry's API and SDK, Go source code is compiled and enhanced, automatic insertion of monitoring system, and non-invasive upgrades are achieved through continuous integration/continuous delivery systems, supporting functions such as link tracking, monitoring indicators and performance analysis.
It realizes the non-invasive observability data acquisition of Go language, supports link tracking and monitoring indicators, improves development efficiency, reduces manual operations, and adapts to different environments and platforms.
Smart Images

Figure CN118672918B_ABST
Abstract
Description
[0001] This application claims priority to the patent application with application number CN202410070581.X, application date January 18, 2024, and patent name “A method and device for obtaining 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 uses a solution called instrumentation in business code. This solution is to launch different APM SDKs or agents for different languages. However, some development languages, such as Go and C, are difficult to automate instrumentation. Only SDK packages are provided for manual instrumentation, requiring developers to manually instrument business code to implement 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 in 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 Go source code, including:
[0006] Use the proxy module to introduce the OpenTelemetry API and SDK; the proxy module includes the API part and the 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 obtain an executable file;
[0009] During the execution of the executable file, the proxy module is used to call the OpenTelemtry API and initialize the OpenTelemetry Tracer instance and / or Metrics instance. 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 integrating with the compilation enhancement capabilities provided by Golang, business systems can be non-invasively integrated into the OpenTelemetry monitoring system. Compilation parameters are automatically embedded through the continuous integration / continuous delivery (CI / CD) system, without the business side being aware of them. Upgrades are also automatically completed by the CI / CD system. This embodiment implements non-invasive support for OpenTelemetry through a proxy module, thereby expanding the application of compilation enhancement in the observability field, supporting not only link tracing but also monitoring metrics.
[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] Enhancement plug-ins to detect whether modules need to be enhanced, detect third-party models introduced by business parties, and match the abstract syntax tree within 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, by enhancing the runtime package of the Go source code, allows plugin developers to store custom variables in the goroutine context. This allows developers to set and retrieve custom variables for specific goroutines at runtime, providing a more flexible plugin development experience. Proxy module plugin directory replication, by enhancing the proxy core plugin, provides the ability to replicate the proxy module plugin directory. This allows plugin developers to easily copy their plugin directories to the program's runtime directory, eliminating the hassle of manual copying and configuration. External initialization function calls provide a series of initialization functions for external calls, allowing developers to call these functions at the program entry point or other appropriate locations to complete plugin initialization. Module enhancement detection and abstract syntax tree (AST) application, by enhancing plugins to detect whether modules require enhancement, detect third-party models introduced by business parties, and match the module's internal abstract syntax tree, makes it easier for developers to apply ASTs for deeper code analysis and modification. Metrics monitoring injection, by enhancing metrics, provides API capabilities for injecting metrics monitoring functions, allowing developers to implement customized metrics monitoring within their programs, thereby better understanding 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 enhancements to the Go source code also include: enhancing the logrus and zap logging frameworks to achieve coupling between logs and observation data.
[0020] In the above technical solution, by coupling the logging framework with observation data, log information and observability data (such as metrics and tracing) can be displayed in the same context. This helps developers better understand the program's running status and quickly locate and resolve problems.
[0021] In some optional implementations, initializing an OpenTelemetry Tracer instance and / or a Metrics instance includes:
[0022] Initialize the Tracer instance and / or Metrics instance by calling the init method and using the parameters passed by the user. The user can pass 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 makes the initialization process more flexible and configurable. Users 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. Users 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 needs 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. Users only need to call the init method and pass the necessary parameters to complete the initialization of the instance without the need for manual tedious configuration and settings.
[0024] In some optional implementations, during the execution of the executable file, the following steps are further included:
[0025] By calling the performance profiling tool pprof provided by the Go language, performance profiling 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 Go language's native performance profiling tool, pprof, performance data can be obtained on multiple aspects, including CPU usage, memory allocation, and lock allocation, enabling a comprehensive evaluation and analysis of program performance. This data helps developers understand the program's performance in terms of resource usage, providing an important basis for optimizing program performance. By performing performance profiling during program execution, real-time performance data can be obtained. This is extremely helpful for promptly identifying and resolving performance issues during program execution, preventing unexpected performance bottlenecks in production environments. Based on this performance data, developers can conduct in-depth performance tuning of the program. For example, they can optimize algorithms and data structures based on CPU usage to reduce unnecessary computation; optimize memory management strategies based on memory allocation to avoid memory leaks and unnecessary memory allocation; and optimize concurrency control strategies based on lock allocation to improve concurrent performance. The data obtained from performance profiling can also be used for troubleshooting and diagnosis. When a program experiences performance degradation or abnormal behavior, analyzing this data can identify potential issues, allowing for faster locating and resolving potential problems. Performance profiling can be used to test and evaluate program performance during the development process. 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 modified code, including:
[0028] Dynamically link the Setter function. The Setter function is used to assign the initialized Tracer instance and / or Metrics instance to the global variable through 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 and / or Metrics instances to global variables, the agent module can easily access and call these instances from anywhere. This avoids repeated API calls or other complex operations within the agent module, improving code efficiency and readability. Dynamic linking makes it possible to use Tracer and / or Metrics instances across 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 further 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 Metrics API to call the OpenTelemetry API.
[0033] An embodiment of the present application provides a Go source code observability data acquisition device, comprising:
[0034] The import module is used to introduce the OpenTelemetry API and SDK using the proxy module. The proxy module includes the API part and the implementation part.
[0035] 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 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, 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, which stores a computer program. 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 following is a brief introduction to the drawings required for use in the embodiments of the present application. 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 relevant drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 A flowchart of the steps of a method for obtaining observability data of 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 OpenTelemetry injection implementation steps provided in the embodiment of this application;
[0043] Figure 4 A flowchart of the performance analysis steps supported by the proxy module provided in the embodiment of the present application;
[0044] Figure 5 A schematic diagram of a possible structure 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, let me introduce some terms involved in this application:
[0048] OpenTelemetry is an open source project for collecting, processing, exporting, and analyzing observable data from distributed systems, such as monitoring metrics, logs, and traces. The project aims 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, helping developers understand how requests propagate through distributed systems.
[0050] Performance metrics (Metrics): It can collect indicator data, such as latency, throughput, or custom business indicators. It is usually statistical data.
[0051] OpenTelemetry provides APIs and SDKs in multiple programming languages, such as Java, Python, Go, and JavaScript, to help application developers integrate with 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, providing detailed information about which parts of a program's execution consume the most time and / or resources. In the field of observability, profiling has become an important tool to complement 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 explain why. Profilers can drill down to the code level, revealing which functions or methods are taking up the most processing time. Through performance profiling, developers and operations teams can understand which parts of the code are using the most CPU, memory, I / O, and other resources. This is crucial for optimizing resource usage and controlling costs.
[0054] OpenTelemetry provides APIs and SDKs for integrating with applications. However, developers must incur significant effort to understand and use the tools and methods provided by OpenTelemetry, as well as select the appropriate SDK and version. In large enterprises, this integration approach is often inefficient, requiring developers from various business teams to perform significant duplication of effort. Furthermore, SDK version upgrades require the coordination of all teams.
[0055] OpenTelemetry currently provides an automatic tracing tool based on eBPF. However, this eBPF-based implementation has the following drawbacks: 1. It has relatively high requirements for kernel and Golang versions; 2. It has a significant performance loss on applications: executing eBPF programs requires frequent switching between kernel mode and user mode.
[0056] Apache SkyWalking Go uses compilation enhancement technology to trace Golang programs, but it only supports SkyWalking's proprietary protocol and is not compatible with the widely used OpenTelemetry and OpenTracing technology stacks. SkyWalking Go also does not support performance profiling.
[0057] Based on this, an embodiment of the present application provides a method for obtaining observability data of Go source code to implement non-invasive support for OpenTelemetry in the Go language, thereby obtaining a solution for observability data.
[0058] Please refer to Figure 1 , Figure 1 A flowchart of the steps of a method for obtaining observability data of 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 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; the observability data includes tracing data and / or metric data.
[0063] The compilation enhancement solution has certain limitations. For example, it cannot use new dependencies in third-party enhanced modules, and can only use the standard libraries and modules that the module already depends on. This makes it difficult to introduce modules similar to OpenTelemetry. Therefore, this embodiment requires importing the OpenTelemetry Go module into the proxy module and its submodules. In other words, Go does not allow the introduction of new dependent modules during the mixed compilation process. The purpose of this import is to provide a dependency tree foundation 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 this embodiment of the application, by connecting to the compilation enhancement capabilities provided by Golang, the business system can be non-invasively connected to the OpenTelemetry monitoring system. The compilation parameters are automatically embedded through the continuous integration / continuous delivery (CI / CD) system without the business side being aware of them. The upgrade actions can also be automatically completed by the CI / CD system. This embodiment achieves non-invasive support for OpenTelemetry through the proxy module, thereby expanding the application of compilation enhancement in the observability field, supporting not only the link tracking function, but also the expanded support for monitoring indicators.
[0066] In some optional implementations, please refer to Figure 2 , Figure 2 The schematic diagram of the process of compiling and enhancing Go source code provided in the embodiment of this 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 third-party models introduced by the business party, and match the abstract syntax tree within the module; the indicators are enhanced to provide the ability to inject the indicator monitoring function API.
[0068] The runtime package is a key package in the Go programming language standard library, responsible for handling runtime operations and underlying system management for Go programs. It provides functionality for interacting with the program's runtime state 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 to threads, the cost of creating and destroying them is much lower, and their scheduling is independent of threads. In the Go language, each concurrent execution unit is called a goroutine. We simply need to add the go keyword before the function call to make the function run as a coroutine. The concurrency design of the Go language is centered on goroutine. Compared to 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 implementing concurrent programming in the Go language.
[0070] Logrus is a structured, pluggable Go logging framework that is fully compatible with the official log library API and also provides custom plugin functionality. Enhancements to Logrus could include adding more plugins, such as optional log output formats like 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 an API, log encoding, and log writing. Enhancements to Zap may include adding more internal modules, optimizing encoding management, and improving writing performance.
[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 own plug-in directory to the program running directory, avoiding the trouble of manual copying and configuration. External initialization function call, provides 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 third-party models introduced by the business party, and matching the abstract syntax tree inside the module, so that developers can more easily apply AST, thereby performing more in-depth code analysis and modification. Indicator monitoring injection: By enhancing indicators and providing API capabilities to inject indicator monitoring functions, developers can implement customized indicator monitoring in their programs, thereby better understanding the program's operating status and performance. Overall, these compilation enhancements provide more flexible and powerful plugin development support, making it easier for developers to develop, configure, and deploy plugins.
[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 compiling and enhancing the Go source code further includes: enhancing the logrus and zap log frameworks to achieve coupling between logs and observation data.
[0075] In the embodiments of the present application, by coupling the logging framework with observation data, 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's 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. This ensures that even if compilation enhancement is not performed, the program will run without errors. During compilation, the package name is matched through the indicator plug-in, and the method logic is replaced. The modules referenced 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 them through environment variables or configuration files.
[0078] The init method is a special method in a 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 is automatically called when the object is created. When an object is created through a class (that is, when an object is created through a constructor), the system automatically calls the init method in the class and passes the single argument from the constructor to the init method. The purpose of the init method is to initialize the created object and is usually used to assign values to the object's properties.
[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 needs 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 the need for manual tedious 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 a background task. A scheduled task polls the control plane service to check for any performance profiling tasks that can be run. If a task is available, the profiling task is immediately executed by calling the runner's start method. After the task is completed, the execution results are uploaded to the control plane service.
[0082] In the embodiments of this application, by using the Go language's native performance profiling tool, pprof, performance data can be obtained on multiple aspects, including CPU usage, memory allocation, and lock allocation, enabling a comprehensive evaluation and analysis of program performance. This data can help developers understand the program's performance in terms of resource usage, providing an important basis for optimizing program performance. By performing performance profiling while the program is running, real-time performance data can be obtained. This is extremely helpful for promptly identifying and resolving performance issues during program execution, preventing unexpected performance bottlenecks in production environments. Based on the acquired performance data, developers can conduct in-depth performance tuning of the program. For example, they can optimize algorithms and data structures based on CPU usage to reduce unnecessary computation; optimize memory management strategies based on memory allocation to avoid memory leaks and unnecessary memory allocation; and optimize concurrency control strategies based on lock allocation to improve concurrency performance. The data obtained from performance profiling can also be used for troubleshooting and diagnosis. When a program experiences performance degradation or abnormal behavior, this data can be analyzed to identify potential issues, allowing for faster locating and resolving potential problems. During the development process, performance profiling can be used to test and evaluate program performance. 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 through dynamic 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 embodiments 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 from anywhere. This avoids repeatedly calling APIs or performing 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.
[0085] In some optional implementations, 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 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 this 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, specifically including the following steps:
[0087] The agent module directly introduces the OpenTelemetry API and SDK.
[0088] When the program runs, the agent module initializes the core modules, including OpenTelemetry's Tracer, through the parameters passed by the user through the init method.
[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 has the enhanced functions Before Method and After Method inserted into the method declaration (the enhanced functions Before Method and After Method 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 is copied to the mixed compilation working directory) The TracerAPI provided by the SDK in the proxy module is called. 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 the electronic device provided by the 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 can be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), 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 microcontroller 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 processing unit (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. Moreover, 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) interfaces, which can be used to communicate directly or indirectly with other devices to exchange data. The communication interface 3 can include interfaces 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 only for illustration, and the electronic device may also include Figure 5 More or fewer components than shown, or with Figure 5 Different structures are shown. Figure 5 The components shown in the figure can be implemented using hardware, software, or a combination thereof. The electronic device can be a physical device, such as a PC, laptop, tablet, mobile phone, server, embedded device, etc., or a virtual device, such as a virtual machine or virtualized container. Furthermore, the electronic device is not limited to a single device and can 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 having computer program instructions stored thereon. 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 obtaining observability data of 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 the API part and the 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 use the proxy module to call the OpenTelemtry API during the running of the executable file, and initialize the OpenTelemetry Tracer instance and / or Metrics instance, 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.
[0101] In the embodiments provided in this 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 interface, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0102] In addition, the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0103] Furthermore, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can 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 actual relationship or order between these entities or operations.
[0105] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, various modifications and variations of the present application are possible. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection 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 the OpenTelemetry API and SDK; the proxy module includes the API part and the 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 execution of the executable file, the OpenTelemetry API is called using the proxy module, 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; Compile and enhance the Go source code, including: 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; Enhancement plug-ins to detect whether modules need to be enhanced, detect third-party models introduced by business parties, and match the abstract syntax tree within the module; Enhance metrics to provide the ability to inject metrics monitoring functionality into the API.
2. The method according to claim 1, wherein 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.
3. The method according to claim 1, wherein Initializing the OpenTelemetry Tracer instance and / or Metrics instance includes: The Tracer instance and / or Metrics instance is initialized by calling the init method and according to the parameters passed by the user; wherein the way in which the user passes the parameters includes implicitly passing them through environment variables or configuration files.
4. The method according to claim 1, wherein During the execution of the executable file, the following steps are also included: By calling the performance profiling tool pprof provided by the Go language, performance profiling is performed to obtain performance data; the performance data includes CPU usage and / or memory allocation and / or lock allocation.
5. The method according to claim 1, wherein The Go source code is compiled and enhanced to obtain a modified code, including: Dynamically link the Setter function, which is used to assign the initialized Tracer instance and / or Metrics instance to the global variable by dynamic 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 Tracer API and / or Metrics API.
6. The method according to claim 5, wherein 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 Metrics API to call the OpenTelemetry API.
7. A device for obtaining observability data of Go source code, characterized in that: include: The import module is used to introduce the OpenTelemetry API and SDK using the proxy module. The proxy module includes the API part and the implementation part. The compilation module is used to compile and enhance the business party's Go source code to obtain modified code; the modified code is mixed and compiled with the Go source code to obtain an executable file; the compilation and enhancement of 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; Enhancement plug-ins to detect whether modules need to be enhanced, detect third-party models introduced by business parties, and match the abstract syntax tree within the module; Enhanced metrics to provide the ability to inject metrics monitoring functionality into the API; The running module is used to use the proxy module to call the OpenTelemetry API during the execution of the executable file, 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.
8. 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 6 is performed.
9. 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 6.
Citation Information
Patent Citations
Block chain network test method and related device
CN116455782A