After you install the probe for a Golang application, Cloud Monitor 2.0 starts monitoring the application. You can view monitoring data such as application topology, call traces, and SQL analysis. This topic describes how to manually install the probe for a Go application.
Manual probe installation is not recommended for applications that are deployed in a Kubernetes environment. Instead, install the probe using a component. For more information, see Install the Go probe for Container Service for Kubernetes (ACK) and Container Compute Service (ACS) using the ack-onepilot component.
If you have any questions when you use the Golang probe, contact us through the DingTalk group. The group number is 35568145.
Before you begin
Make sure the environment where the application resides is connected to Alibaba Cloud over the Internet or an internal network, and the security group of the environment allows outbound traffic for TCP ports 8080, 9990, 80, and 443.
Check your network configurations.
Check your build.
Step 1: Compile the Golang application image
If your project repository is managed by go mod vendor, ensure your go.mod file includes the google.golang.org/protobuf dependency (either direct or indirect) and add the -mod=vendor flag to your build command.
If your project repository is not managed by go mod vendor, skip the preceding steps.
Method 1 (recommended): Manually build the Golang application image
Use the
wgetcommand to download the instgo compile tool. Select a download address based on your compile-time environment and the region where your build machine is located.Note that instgo automatically updates itself during compilation. Save instgo to a directory where the compile user has modification permissions.
NoteInstgo is a compile tool provided by Cloud Monitor 2.0 for Golang applications. After you compile your Golang project using instgo, Cloud Monitor 2.0 can monitor your Golang application.
The compile tools available for download in different regions are identical. If your environment can access Object Storage Service (OSS) over the public internet, you can use the internet address for the China (Hangzhou) region to obtain the compile tool for your operating system and architecture.
Add executable permissions to instgo.
Linux/Darwin
# Grant the permissions. chmod +x instgoWindows
In Windows, you do not need to grant permissions.
Use the binary file compiled in the previous step to build the image.
Prefix the
go buildorgo installcommand withinstgoto build your project. Example:instgo go build {arg1} {arg2} {arg3}Build an image using the binary file that you compiled in the previous step.
During initial application builds, the ARMS agent is downloaded to
/opt(Windows:C:\ProgramData) by default. If you lack directory permissions, use either of the following:instgo set --cacheDir="./"to set the cache directory to your current working directorysudo -Eto build with required permissionsWindows users must run build commands with administrator permissions.
Forcefully stopping or killing the build may leave residual files. Clean them up if any.
Method 2: Non-intrusively build the Golang application image
This method is supported only for Go 1.23 and earlier.
To non-intrusively build a Golang application image, replace the base image in the Golang binary file build stage with an ARMS compile image.
ARMS provides compile images for the AMD64 and ARM64 architectures on Alpine Linux and Debian Linux.
For example, the following Dockerfile is typically used to build a Golang application image using Docker multi-stage builds:
# stage 1
FROM golang:1.22-alpine3.19 as builder
RUN --mount=type=ssh \
go build -v -buildmode=pie -ldflags "-linkmode external -extldflags -static" \
-o /workspace/demo
# stage 2
FROM alpine
COPY --from=builder /workspace/demo /demo
# Specify the default startup command.
CMD ["/demo"]The sample Dockerfile is divided into two stages:
The first stage builds the Golang binary file.
The second stage copies the binary file from the first stage to the runtime image to build the runtime image for the Golang application.
Replace the base image in the Golang binary file build stage with the ARMS compile image. The other commands can remain the same. The following code shows the modified Dockerfile:
# stage 1
# Replace the base image with the ARMS compile image. The other commands remain the same.
# Replace the image with the one for your region as needed.
FROM registry-cn-hangzhou.ack.aliyuncs.com/acs/golangbuilder-alpine-linux-amd64:0.0.1 as builder
RUN --mount=type=ssh \
go build -v -buildmode=pie -ldflags "-linkmode external -extldflags -static" \
-o /workspace/demo
# stage 2
FROM alpine
COPY --from=builder /workspace/demo /demo
# Specify the default startup command.
CMD ["/demo"]Step 2: Configure environment variables
After compilation, add the following environment variables for the Go application:
export ARMS_ENABLE=true export ARMS_APP_NAME=xxx # The application name. export ARMS_WORKSPACE=xxx # Replace xxx with the name of your workspace. export ARMS_REGION_ID=xxx # The region ID. export ARMS_LICENSE_KEY=xxx # The license key obtained in Step 1.In addition to exposing environment variables using the export command, you can also specify the environment variables using ldflags at compile-time.
Replace
modulewith the module name that is configured in the go.mod file. For information about other parameters, see the environment variables.instgo go build -ldflags " -X '${module}/otel_pkgdep/exporters.ArmsApmName=${appName}' -X '${module}/otel_pkgdep/exporters.ArmsEnable=true' -X '${module}/otel_pkgdep/exporters.LicenseKey=${licenseKey}' -X '${module}/otel_pkgdep/exporters.RegionId=${regionId}'"
(Optional) Docker environment installation reference
For Docker environments, you can refer to the following example to modify your Dockerfile.
### .....
ENV ARMS_ENABLE=true
ENV ARMS_APP_NAME={AppName}
ENV ARMS_WORKSPACE={workspace}
ENV ARMS_REGION_ID={regionId}
ENV ARMS_LICENSE_KEY={licenseKey}
### Add your custom Dockerfile logic below.
### ......View monitoring details
Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, choose .
On the Application List page, you can view the connected applications. Click an application name to view its detailed monitoring data.