tencent cloud

Feedback

Connecting Go Applications Using SkyWalking-Go

Last updated: 2024-06-19 16:31:30
    SkyWalking Go is a performance monitoring scheme for Go applications provided by the SkyWalking community. It allows Go applications to connect to APM without altering business code. For more information on SkyWalking Go, see the Project Documentation. SkyWalking Go supports automatic Event Tracking for commonly used Go dependency libraries and frameworks, including Gin, GORM, gRPC, etc. For other libraries and frameworks supporting automatic Event Tracking, see the Complete List provided by the SkyWalking community.

    Demo Applications

    With the following demo codes, you can start the simplest HTTP service:
    package main
    
    import (
    "net/http"
    )
    func main() {
    http.HandleFunc("/hello", func(writer http.ResponseWriter, request *http.Request) {
    writer.Write([]byte("Hello World from skywalking-go-agent"))
    })
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
    panic(err)
    }
    }

    Preliminary steps: Get the connect point and Token.

    1. Log in to the TCOP console.
    2. In the left menu column, select Application Performance Management > Application monitoring, and click Application list > Access application.
    3. In the Data access drawer that pops up on the right, click the Go language.
    4. On the Access Go application page, select the Region and Business System you want to connect.
    5. Choose the Access protocol type as SkyWalking.
    6. Reporting method Choose your desired reporting method, and obtain your Access Point and Token.
    Note:
    Private network reporting: Using this reporting method, your service needs to run in the Tencent Cloud VPC. Through VPC connecting directly, you can avoid the security risks of public network communication and save on reporting traffic overhead.
    Public network reporting: If your service is deployed locally or in non-Tencent Cloud VPC, you can report data in this method. However, it involves security risks in public network communication and incurs reporting traffic fees.

    Connecting Go Applications

    Step 1. Download the Agent.

    Go to the SkyWalking Download Page, in the Go Agent section, click Distribution to download the tar format of the Agent packet, with the file name suffix as tgz.
    After the packet is extracted, you obtain the binary files under the bin directory. Choose the binary file that matches your operating system as the Agent file. For example, in the Linux system, the Agent file is skywalking-go-agent-0.4.0-linux-amd64.

    Step 2: Install the Agent.

    SkyWalking Go provides 2 methods to install the Agent, you can choose either method:

    Agent Injection Method

    If you do not need to customize Event Tracking in the code, you can choose the Agent injection method. Execute the command as follows:
    /path/to/agent -inject /path/to/your/project [-all]
    Here, /path/to/agent is the Agent file obtained in step 1, /path/to/your/project is the Go project root directory.

    Code Dependency Method

    Run the following command to obtain the required dependencies:
    go get github.com/apache/skywalking-go
    Include the dependency in main:
    import _ "github.com/apache/skywalking-go"

    Step 3: Modify the configuration for connecting APM.

    Obtain the configuration file template from the community's default configuration file, and save it as a text file, which can be named config.yaml.
    Modify the configuration file, at least the following 3 items need to be configured:
    agent:
    service_name: "<serviceName>" # Replace <serviceName> with the application name.
    reporter:
    grpc:
    backend_service: "<endpoint>" # Replace <endpoint> with the reporting address.
    authentication: "<token>" # Replace <token> with the business system Token.
    The corresponding field descriptions are as follows:
    <serviceName>: Application name. Multiple application processes connecting with the same serviceName are displayed as multiple instances under the same application in APM. The application name can be up to 63 characters and can only contain lowercase letters, digits, and the separator (-), and it must start with a lowercase letter and end with a digit or lowercase letter.
    <token>: The business system Token obtained in the preliminary steps.
    <endpoint>: The connect point obtained in the preliminary steps.

    Step 4: Compile projects based on SkyWalking-Go.

    When you compile the Go project, add the following parameters:
    -toolexec="/path/to/agent" -config /path/to/config.yaml -a
    Where, /path/to/agent is the Agent file obtained in step 1, /path/to/config.yaml is the configuration file obtained in step 3.
    Assuming the compiled output is named test, the complete command is:
    go build -toolexec='/path/to/agent -config /path/to/config.yaml' -a -o test .

    Connection Verification

    After you start the Go application, access the corresponding API through port 8080, for example, https://localhost:8080/hello, the application reports the HTTP request-related link data to APM. In normal traffic cases, the connected application will displayed in APM > Application monitoring > Application list and the connected application instances will be displayed in APM > Application monitoring > App details > Instance monitoring. Since there is a certain latency in the processing of observable data, if the application or instance does not appear in the console after connecting, wait for about 30 seconds.

    Custom Link Event Tracking

    When automatic Event Tracking does not meet your needs, or you need to add business layer instrumentation, see the community's Tracing API Documentation and add custom link instrumentation in the code.
    
    
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support