Note:
OpenTelemetry is a collection of tools, APIs, and SDKs used to detect, generate, collect, and export telemetry data (metrics, logs, and traces) to help users analyze the performance and behavior of the software. For more information about OpenTelemetry, please refer to the OpenTelemetry official website. The OpenTelemetry community is active, with rapid technological change, extensive compatibility with mainstream programming languages, components, and frameworks, making its link-tracing capability for cloud-native microservices and container architectures widely popular.
The OpenTelemetry compilation enhancement solution is based on the community opentelemetry-go-auto-instrumentation project for further development. With this solution, Go applications can access Application Performance Management (APM) without modifying the business code. This solution provides automatic event tracking support for commonly used Go dependency libraries and frameworks, including Gin, GORM, and gRPC. For other dependency libraries and frameworks that support automatic event tracking, please see the complete list. Prerequisites
Go version 1.23 or higher.
Operation Steps
Step 1. Getting the Access Point and Token
2. Select APM > Application list in the left menu bar, then click Access application.
3. In the Application application drawer frame that pops up on the right, click the Go language.
4. On the Access Go application page, select the Region and Business System.
5. Select OpenTelemetry as Access protocol type.
6. Select your preferred Reporting method, and obtain your Access Point and Token.
Note:
Report over private network: This reporting method requires your service to run in the Tencent Cloud VPC. The direct connectivity through VPC helps avoid the security risks of public network communication and saves costs on reporting traffic.
Report over public network: 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.
Step 2: Download Tool
Step 3: Lock the Version of OpenTelemetry Related SDK (Optional)
To avoid compilation errors caused by upstream OpenTelemetry SDK version updates, manually lock its version, for example, version v1.35.0:
go mod edit -require=go.opentelemetry.io/otel@v1.35.0
go mod edit -require=go.opentelemetry.io/otel/sdk@v1.35.0
go mod edit -require=go.opentelemetry.io/otel/trace@v1.35.0
go mod edit -require=go.opentelemetry.io/otel/metric@v1.35.0
Step 4: Compile the Application
Grant execution permission to the tool.
Add the otel prefix to the Go compilation command to complete the application compilation. For example, the go build ... command will be modified to ./otel go build ....
Step 5: Add Environment Variable
Add the following environment variables to the Go application's runtime environment, then start the application:
OTEL_EXPORTER_OTLP_ENDPOINT=<endpoint> \\
OTEL_SERVICE_NAME=<serviceName> \\
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \\
OTEL_TRACES_EXPORTER=otlp \\
OTEL_RESOURCE_ATTRIBUTES=token=<token>,host.name=<hostName> \\
./app
The corresponding field descriptions are as follows. Replace based on the actual situation.
<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 contain up to 63 characters, can only contain lowercase letters, digits, and the separator "-", and must start with a lowercase letter and end with a digit or lowercase letter.
<token>: business system Token obtained in preliminary steps.
<hostName>: The hostname of this instance, which is the unique identifier of the application instance. It can usually be set to the IP address of the application instance.
<endpoint>: The access point obtained in the previous step. Note that you must add the http://prefix.
Access Verification
After completing the integration steps, the Go application will report monitoring data to the APM server. In normal traffic cases, the connected application will be displayed in Application Performance Monitoring > Application list. Click Application name/ID to enter the application details page, and then select Instance Analysis to view the connected application instance. Since there is latency in the processing of observable data, please wait about 30 seconds if the application or instance does not appear in the console after connecting. Custom Event Tracking Enhancement
When the automatic event tracking scope of the compilation enhancement solution does not meet your scenarios, or you need to add business layer event tracking, you can refer to Accessing the Go Application Through the OpenTelemetry SDK (Recommended) to perform custom event tracking enhancement based on the OpenTelemetry SDK. Custom event tracking enhancement supplements the compilation enhancement solution. Both share the same trace context and will not cause conflict.