All Products
Search
Document Center

Serverless App Engine:Install an agent for a Python application

Last Updated:Jun 21, 2026

After you manually install the ARMS agent for a Python application and deploy the application to SAE, you can use ARMS to monitor the application. With ARMS, you can view various types of monitoring data, such as application topology, call trace analysis, and SQL performance analysis. This topic describes how to manually install the ARMS agent for an application and deploy the application to SAE.

Prerequisites

Python framework compatibility

Review these framework-specific requirements before you proceed.

uvicorn

If your application starts with uvicorn, choose one of the following approaches:

Approach A: Import the agent in code. Add this import statement to the first line of your uvicorn entry file:

from aliyun.opentelemetry.instrumentation.auto_instrumentation import sitecustomize

Approach B: Switch to gunicorn with the aliyun-instrument prefix. Replace your uvicorn command:

# Before
uvicorn app:app --workers 4 --port=9090 --host 0.0.0.0

# After
aliyun-instrument gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 app:app
Note

The aliyun-instrument prefix handles initialization and non-intrusive instrumentation of the ARMS Python agent.

uWSGI

If your application starts with uWSGI, see Install the Python agent for a Django or Flask project that starts with uWSGI.

gevent

If you use gevent coroutines, set the GEVENT_ENABLE environment variable to true.

For example, if your code contains:

from gevent import monkey
monkey.patch_all()

Set the following environment variable in your deployment:

GEVENT_ENABLE=true

Overview

  1. Prepare the project: This topic uses a demo project as an example.

  2. Build a Docker image or package the project: If you deploy the application using an image, you must install the Python agent during the image build process. If you deploy the application using a code package, the system automatically installs the agent. You only need to configure the startup command to launch the application with the ARMS agent.

  3. Deploy the Python application: Deploy the application in SAE and enable Application Monitoring. If you use a code package, you must also set the startup command to launch the application with the ARMS agent.

  4. View monitoring data: View the monitoring data generated by the application.

Step 1: Prepare the project

  1. Upload your project to your build environment.

  2. Install the required dependencies to test the project. For more information, see Installing packages.

  3. Test the project locally to ensure it runs correctly.

Step 2: Build a Docker image or package the project

Docker image

  1. Build the Python image.

    This section provides the commands to download, install, and start the application with the ARMS Python agent.

    ...
    # Download the agent installer from PyPI.
    RUN pip3 install aliyun-bootstrap
    # Install the Python agent by using aliyun-bootstrap.
    RUN aliyun-bootstrap -a install
    ...
    # Start the application by using the ARMS Python agent.
    CMD ["aliyun-instrument","python","main.py"]
    Note

    If you do not want to use the Python agent to start the application, you must import the agent in your application's main entry file, such as main.py, and then start the application.

    from aliyun.opentelemetry.instrumentation.auto_instrumentation import  sitecustomize
  2. Push the built Python image to Alibaba Cloud Container Registry (ACR). For more information, see Push and pull images (Enterprise Edition) or Push and pull images (Personal Edition).

ZIP package

Package your Python project into a ZIP file in your local environment. For more information, see Instructions for packaging a Python project into a ZIP file.

Step 3: Create the application

From image

Step 3.1: Create the application

This section covers only the key steps. For detailed instructions, see Deploy an application using an image.

  1. On the Specify Image panel, set Technology Stack Programming Language to Python and select your desired image version.

    Select the My Alibaba Cloud Images tab and Personal Edition of Container Registry. From the Select Image Version drop-down list, select python2.

  2. On the Advanced Settings page, in the Application Monitoring section, enable Application Monitoring.

    To use Application Monitoring with a custom image, you must first modify the image to install the Python agent during the build process. ARMS provides a free quota of 200 GB per month for SAE users.

  3. Click Create Application.

Step 3.2: Verify access

Public endpoint

  1. Add a public endpoint for the application. For more information, see Bind a CLB instance to an application and generate a public or internal endpoint.

    After configuration, the Public Endpoint section displays the bound CLB address, with the port set to 2222 and the protocol to HTTP.

  2. Copy the public endpoint and paste it into your browser to test it.

Webshell

  1. Go to the Basic Information page of the application and click the Instances tab.

  2. In the Actions column for the target instance, click Webshell.

  3. On the Webshell page, run the command curl 127.0.0.1:<container port> to test.

From code package

Step 3.1: Create the application

This section covers only the key steps. For detailed instructions, see Deploy a Python application.

  1. On the Configure Code Package-based Deployment panel, set Technology Stack Programming Language to Python. In the Upload ZIP Package section, click the image icon to upload your ZIP file.

    From the Python Environment drop-down list, select Python 3.9.15.

  2. On the Advanced Settings page, configure the following settings.

    1. In the Startup Command section, enter the following command.

      aliyun-instrument python main.py
      # Start the application by using the ARMS Python agent. main.py is the main entry file in this example.

      Select /bin/sh as the command type.

    2. In the Application Monitoring section, enable Application Monitoring.

  3. Click Create Application.

Step 3.2: Verify access

Public endpoint

  1. Add a public endpoint for the application. For more information, see Bind a CLB instance to an application and generate a public or internal endpoint.

  2. Copy the public endpoint and paste it into your browser to test it.

Webshell

  1. Go to the Basic Information page of the application and click the Instances tab.

  2. In the Actions column for the target instance, click Webshell.

  3. On the Webshell page, run the command curl 127.0.0.1:<container port> to test.

Step 4: View monitoring data

SAE console

Go to the Basic Information page of your application. In the left-side navigation pane, click Application Monitoring. On the Application Monitoring page, you can view the Monitoring Data.

The Application Overview tab displays four core metric cards: Requests, Errors, Avg. Response Time, and Instances, complete with day-over-day and week-over-week comparisons. The tab also features a time-series trend chart and lists the top five rankings for requests, errors, average response time, and peak CPU utilization.

ARMS console

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, choose Application Monitoring > Application List. In the top navigation bar, select the target region.

    On the Applications page, you can see the connected applications and their key monitoring metrics, such as requests per second, error rate, and average response time. This confirms your application is connected to Application Monitoring.

  3. On the Application List page, search for your application and click its name.

  4. View the application's monitoring data on the details page.

    dq39ionBxZ