wu-sheng commented on code in PR #13: URL: https://github.com/apache/skywalking-go/pull/13#discussion_r1174983222
########## docs/en/development-and-contribution/development-guide.md: ########## @@ -0,0 +1,333 @@ +# Plugin Development Guide + +This documentation introduces how developers can create a plugin. + +All plugins must follow these steps: + +1. **Create a new plugin module**: Create a new project in the specified directory and import the plugin API module. +2. **Define the enhancement object**: Define the description for the plugin. +3. **Invoke the plugin API**: Call the API provided by the core to complete the core invocation. +4. **Import the plugin module**: Import the plugin into the management module for users to use. + +## Create a new plugin module + +The plugin must create a new module, which is currently stored in the project's [plugins directory](../../../plugins). + +Plugins can import the following two modules: + +1. **Agent core**: This module provides all the dependencies needed for the plugin, including the plugin API, enhancement declaration objects, etc. +Agent core plugin should be `github.com/apache/skywalking-go/plugins/core` and replaced by the relative location. +2. **Framework to be enhanced**: Import the framework you wish to enhance. + +Note: Plugins should not import and use other unrelated modules, as this may cause compilation issues for users. If certain tools are needed, they should be provided by the agent core. + +## Define the enhancement object + +In the root directory of the project, **create a new go file** to define the basic information of the plugin. +The basic information includes the following methods, corresponding to the [Instrument interface](../../../plugins/core/instrument/declare.go): + +1. **Name**: The name of the plugin. Please keep this name consistent with the newly created project name. The reason will be explained later. +2. **Base Package**: Declare which package this plugin intercepts. For example, if you want to intercept gin, you can write: "github.com/gin-gonic/gin". +3. **Version Checker**: This method passes the version number to the enhancement object to verify whether the specified version of the framework is supported. If not, the enhancement program will not be executed. +4. **Points**: A plugin can define one or more enhancement points. This will be explained in more detail in the following sections. +5. **File System**: Use `//go:embed *` in the current file to import all files in this module, which will be used for file copying during the mixed compilation process. + +Note: Please declare `//skywalking:nocopy` at any position in this file to indicate that the file would not be copied. This file is only used for guidance during hybrid compilation. +Also, this file involves the use of the `embed` package, and if the target framework does not import the package `embed`, a compilation error may occur. + +### Instrument Point + +Instrument points are used to enhance methods and struct in the current package. They mainly include the following information: Review Comment: ```suggestion Instrument points are used to declare that which methods and structs in the current package should be instrumented. They mainly include the following information: ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
