Integrate the open-source Elastic APM stack with Alibaba Cloud Elasticsearch to build an observability pipeline for your services and applications. This guide walks you through deploying a self-managed APM server on an Elastic Compute Service (ECS) instance, instrumenting a Go application with an APM agent, and visualizing the collected data in Kibana.
APM bridges the gap between infrastructure metrics and application-level behavior. While logs and metrics tell you what is happening at the infrastructure layer, APM tells you what is happening inside your application and how users experience it. Integrating APM into your stack lets you:
-
Identify which operations take the longest and why services stop responding
-
Map service dependencies and pinpoint bottlenecks in distributed request flows
-
Track real user experience in browsers and native clients
-
Generate SLA reports and trend analysis from the business perspective
Prerequisites
Before you begin, make sure that you have:
-
An Alibaba Cloud Elasticsearch V7.10 cluster. See Create an Alibaba Cloud Elasticsearch cluster.
-
An ECS instance running Linux. See Connect to a Linux instance by using a password or key.
-
Go installed on the ECS instance. This guide instruments a Go application using the Elastic APM Go agent.
How it works
-
The APM server receives trace data from APM agents running inside your applications.
-
The APM server forwards the data to your Alibaba Cloud Elasticsearch cluster.
-
Kibana reads the data from Elasticsearch and displays it in the APM UI under Observability.
Step 1: Build an APM server
Install the APM server
-
Connect to your ECS instance as a regular user. See Connect to a Linux instance by using a password or key.
-
Download the APM server package.
wget https://artifacts.elastic.co/downloads/apm-server/apm-server-7.10.2-linux-x86_64.tar.gz -
Extract the package.
tar -zxf apm-server-7.10.2-linux-x86_64.tar.gz
Configure the APM server
-
Go to the APM server directory.
cd apm-server-7.10.2-linux-x86_64/ -
Open the configuration file.
vim apm-server.yml -
Update the configuration with your Elasticsearch cluster details.
Parameter Description apm-server.hostThe address and port the APM server listens on. Format: <IP>:<port>. The value0.0.0.0:8200listens on all interfaces.output.elasticsearch.hostsThe endpoint of your Elasticsearch cluster. Use the internal endpoint if the ECS instance and the cluster are in the same virtual private cloud (VPC). If they are in different VPCs, use the public endpoint and configure a public IP allowlist. See View the basic information of a cluster and Configure a public or private IP address whitelist for an Elasticsearch cluster. output.elasticsearch.usernameThe username for Elasticsearch. The default is elastic. To use a custom account, create a role and grant it the required write permissions first. See Use the RBAC mechanism provided by Elasticsearch X-Pack to implement access control.output.elasticsearch.passwordThe password for the username above. The elasticaccount password is set when you create the cluster. To reset it, see Reset the access password for an Elasticsearch cluster.apm-server: host: "0.0.0.0:8200" output.elasticsearch: hosts: ["es-cn-*****.elasticsearch.aliyuncs.com:9200"] username: "elastic" password: "<your-password>"
Start the APM server
Run the following command to start the APM server in the background and redirect output to a log file.
nohup ./apm-server -e > apmserver.log 2>&1 &
The APM server starts, connects to Elasticsearch on the endpoint you specified, and exposes the agent API on port 8200. To verify that the server is running, check apmserver.log for a message confirming the connection to Elasticsearch and that the server is listening on port 8200.
Step 2: Configure an APM agent
This example uses the Elastic APM Go agent. This guide uses environment variables for initial setup.
This guide uses Go as an example. For other languages, install the corresponding Elastic APM agent. See Elastic APM agent documentation for the full list of supported languages and built-in modules.
Install the Go agent
-
Initialize a Go module for your project.
sudo go mod init demo -
Install the APM agent packages.
If you see a
golang.org xxxx: i/o timeouterror, your environment cannot reach golang.org. Change the Go module proxy to a reachable mirror before retrying.sudo go get go.elastic.co/apm sudo go get go.elastic.co/apm/module/apmhttp
Set APM agent environment variables
-
Open the shell profile file.
vim ~/.bash_profile -
Add the following environment variables and save the file.
Variable Default Description ELASTIC_APM_SERVICE_NAMEExecutable file name The name of your service. Allowed characters: letters, digits, hyphens ( -), underscores (_), and spaces.ELASTIC_APM_SERVER_URLhttp://localhost:8200The URL of the APM server. Set this to the address of the server you started in Step 1. ELASTIC_APM_SECRET_TOKEN_(none)_ The secret token required by the APM server. export ELASTIC_APM_SERVICE_NAME=zijian export ELASTIC_APM_SERVER_URL= export ELASTIC_APM_SECRET_TOKEN= -
Apply the configuration.
source ~/.bash_profile
Instrument your application
The Elastic APM Go agent provides built-in modules for popular frameworks (such as apmhttp) and a lower-level Tracer API for custom instrumentation. This example uses apmhttp to wrap a standard HTTP server.
-
Create the application file.
vim apm.go -
Add the following code and save the file.
package main import ( "net/http" "go.elastic.co/apm/module/apmhttp" ) func main() { mux := http.NewServeMux() http.ListenAndServe(":8080", apmhttp.Wrap(mux)) } -
Run the application.
sudo go run apm.goOnce the application is running, the APM agent begins sending trace data to the APM server, which forwards it to your Elasticsearch cluster.
Step 3: View APM data in Kibana
Enable automatic index creation
Alibaba Cloud Elasticsearch enforces index naming conventions. The APM onboarding index created automatically by the APM server does not conform to these conventions, so you must explicitly allow it.
-
Log in to the Kibana console. See Log on to the Kibana console.
This guide uses a V7.10 cluster. Login steps may differ for other Elasticsearch versions.
-
On the Kibana homepage, click Dev tools in the upper-right corner.
-
On the Console tab, run the following command. Replace
7.10.2with the version of the APM server you installed.PUT _cluster/settings { "persistent": { "action.auto_create_index":"+.*,+apm-7.10.2-onboarding-*,-*" } }
View monitored services
-
Click the
icon in the upper-left corner to expand the navigation pane. -
Under Observability, click APM.
-
On the Services tab, all services monitored by the APM agent are listed.

-
Click a service name to drill down into its traces, transactions, and performance data.
What's next
-
To use a different programming language, install the corresponding Elastic APM agent. For the full list of supported languages and their built-in modules, refer to the Elastic APM agent documentation.
-
To centrally manage agent configuration without redeploying, use the Kibana-based APM agent configuration under Observability > APM > Settings.
-
To control access to your Elasticsearch cluster, set up role-based access control. See Use the RBAC mechanism provided by Elasticsearch X-Pack to implement access control.