tencent cloud

Tencent Cloud Observability Platform

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Strengths
Basic Features
Basic Concepts
Use Cases
Use Limits
Purchase Guide
Tencent Cloud Product Monitoring
Application Performance Management
Mobile App Performance Monitoring
Real User Monitoring
Cloud Automated Testing
Prometheus Monitoring
Grafana
EventBridge
PTS
Quick Start
Monitoring Overview
Instance Group
Tencent Cloud Product Monitoring
Application Performance Management
Real User Monitoring
Cloud Automated Testing
Performance Testing Service
Prometheus Getting Started
Grafana
Dashboard Creation
EventBridge
Alarm Service
Cloud Product Monitoring
Tencent Cloud Service Metrics
Operation Guide
CVM Agents
Cloud Product Monitoring Integration with Grafana
Troubleshooting
Practical Tutorial
Application Performance Management
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Parameter Information
FAQs
Mobile App Performance Monitoring
Overview
Operation Guide
Access Guide
Practical Tutorial
Tencent Cloud Real User Monitoring
Product Introduction
Operation Guide
Connection Guide
FAQs
Cloud Automated Testing
Product Introduction
Operation Guide
FAQs
Performance Testing Service
Overview
Operation Guide
Practice Tutorial
JavaScript API List
FAQs
Prometheus Monitoring
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Terraform
FAQs
Grafana
Product Introduction
Operation Guide
Guide on Grafana Common Features
FAQs
Dashboard
Overview
Operation Guide
Alarm Management
Console Operation Guide
Troubleshooting
FAQs
EventBridge
Product Introduction
Operation Guide
Practical Tutorial
FAQs
Report Management
FAQs
General
Alarm Service
Concepts
Monitoring Charts
CVM Agents
Dynamic Alarm Threshold
CM Connection to Grafana
Documentation Guide
Related Agreements
Application Performance Management Service Level Agreement
APM Privacy Policy
APM Data Processing And Security Agreement
RUM Service Level Agreement
Mobile Performance Monitoring Service Level Agreement
Cloud Automated Testing Service Level Agreement
Prometheus Service Level Agreement
TCMG Service Level Agreements
PTS Service Level Agreement
PTS Use Limits
Cloud Monitor Service Level Agreement
API Documentation
History
Introduction
API Category
Making API Requests
Monitoring Data Query APIs
Alarm APIs
Legacy Alert APIs
Notification Template APIs
TMP APIs
Grafana Service APIs
Event Center APIs
TencentCloud Managed Service for Prometheus APIs
Monitoring APIs
Data Types
Error Codes
Glossary

Connecting Go Applications Using SkyWalking-Go

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-10-13 19:10:48
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, and click Application list > Access application.
3. In the Access application 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, connected applications will be displayed in Application Performance Monitoring > Application list. Click Application name/ID to Go to the application details page, then select Instance Analysis to view connected application instances. 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

On the basis of automatic event tracking, you can add custom event tracking using SkyWalking Toolkit.
Import related packages:
package main

import (
"github.com/apache/skywalking-go/toolkit/trace"
)
Obtain the TraceId and SpanId:
trace.GetTraceID()

trace.GetSpanID()
Creating and Terminating Span:
trace.CreateLocalSpan("testAddLog")

trace.StopSpan()
Add attribute to Span:
trace.AddLog(...string) // Add Log

trace.SetTag("key","value") // Add Tag
Create Event:
trace.AddEvent(trace.DebugEventType, "foo")
For more usage of Tracing API, see SkyWalking Official Code.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백