After you install the agent for a Go application, Application Real-Time Monitoring Service (ARMS) can start monitoring it. You can view monitoring data, such as application topology, call stacks, and SQL analysis. This topic describes how to manually install the agent for a Go application.
For applications deployed in a Kubernetes environment, do not manually install the agent. Instead, install the component to connect to ARMS. For more information, see Install the Go agent for Container Service for Kubernetes (ACK) and Container Compute Service (ACS) using the ack-onepilot component.
If you have any questions about using the Go agent, you can contact us through the DingTalk group. The group ID is 159215000379.
Prerequisites
Ensure that your compile-time environment can connect to the internet or an Alibaba Cloud internal network. The security group for the environment must allow outbound TCP traffic on ports 8080, 9990, 80, and 443.
Check your network environment. For more information, see Network configurations for Go application monitoring.
Check the operating system, architecture, Go version, and framework version of your compile-time environment. For more information, see Go components and frameworks supported by ARMS Application Monitoring.
Step 1: Compile the Golang application image
(Optional) If your project uses vendor mode for compilation or the compile-time parameters include
-mod=vendor, check the following:Check if the go.mod file contains the `google.golang.org/protobuf` dependency, either directly or indirectly. If not, see the following instructions:
Check if the compile-time parameters include
-mod=vendor. If not, add-mod=vendoraftergo build.
Use the
wgetcommand to download the compile-time tool instgo. Select the download address based on your compile-time environment and machine region.Note that instgo automatically updates at compile-time. Save instgo in a folder where you have modification permissions.
NoteInstgo is a compile-time tool provided by ARMS for Go applications. After you compile your Go project with instgo, ARMS can monitor your application.
The compile-time tool is the same for all regions. If your environment can access Object Storage Service (OSS) over the internet, you can use the internet download address for China (Hangzhou) for your operating system and architecture.
Grant executable permissions to the compile-time tool.
Linux/Mac
# Grant executable permissions chmod +x instgoWindows
No executable permissions are required for Windows.
Obtain the LicenseKey and configure compile-time parameters.
ImportantIf you skip this step, instgo enters dev mode and installs the latest version of the ARMS agent by default. To deploy your application in a production environment, you must configure the following parameters.
Obtain the LicenseKey by calling the DescribeTraceLicenseKey OpenAPI operation.
On the DescribeTraceLicenseKey page, click Debug. Select a region and click Initiate Call to obtain the LicenseKey.

After you obtain the LicenseKey, use the
setcommand to configure the compile-time parameters.instgo set --licenseKey=${YourLicenseKey}
Add `instgo` as a prefix to your original compile command and run the command.
instgo go build {arg1} {arg2} {arg3}If you use `go install` to compile the project, you can also add `instgo` as a prefix to the command.
Build the image using the binary file compiled in the previous step.
Step 2: Configure environment variables
After compilation, manually add the following environment variables for your Go application:
export ARMS_ENABLE=true export ARMS_APP_NAME=xxx # Application name. export ARMS_REGION_ID=xxx # The region ID of your Alibaba Cloud account. export ARMS_LICENSE_KEY=xxx # The LicenseKey obtained in Step 1.Alternatively, instead of using `export` to expose environment variables, you can specify them at compile-time using `ldflags`.
Replace
modulewith the module name from your go.mod file. The other parameters correspond to the environment variables listed above.instgo go build -ldflags " -X 'github.com/alibaba/loongsuite-go-agent/pkg/exporters.ArmsApmName=${appName}' -X 'github.com/alibaba/loongsuite-go-agent/pkg/exporters.ArmsEnable=true' -X 'github.com/alibaba/loongsuite-go-agent/pkg/exporters.LicenseKey=${licenseKey}' -X 'github.com/alibaba/loongsuite-go-agent/pkg/exporters.RegionId=${regionId}'"
(Optional) Docker installation reference
If you are using a Docker environment, you can modify your Dockerfile based on the following example.
### .....
ENV ARMS_ENABLE=true
ENV ARMS_APP_NAME={AppName}
ENV ARMS_REGION_ID={regionId}
ENV ARMS_LICENSE_KEY={licenseKey}
### Add your custom Dockerfile logic below.
### ......Verify the results
After about one minute, navigate to the page in the ARMS console. If your Go application is displayed on the page and monitoring data is reported, the agent is successfully installed.
