All Products
Search
Document Center

Serverless App Engine:Install an agent for a Python application

Last Updated:Oct 22, 2025

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 monitoring data, such as application topology, call trace analysis, and SQL performance analysis. This topic describes how to manually install the ARMS agent for a Python application and deploy it to SAE.

Prerequisites

Usage notes

  • If the application is started by using Uvicorn, replace the command to install the agent.

    For example, if the following command is used to start your application:

    uvicorn -w 4 -b 0.0.0.0:8000 app:app

    Replace the command with the following:

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

    The aliyun-instrument command initializes the ARMS agent for Python and instruments data in a non-intrusive way.

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

    Example:

    from gevent import monkey
    monkey.patch_all()

    Run the following command to set the environment variable:

    GEVENT_ENABLE=true

Procedure

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

  2. Create a Docker image for the Python project or package the project into a ZIP file: If you deploy the application from an image, you must download and install the Python agent when you create the image. If you deploy the application from a code package, the system automatically downloads and installs the Python agent during deployment. You only need to start the application using the ARMS Python agent.

  3. Deploy the Python application: Deploy the Python application in the SAE console and enable application monitoring. If you deploy the application from a code package, you must also set the startup command to start the application using the ARMS Python agent.

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

1. Prepare the project

  1. Upload the project to your environment.

  2. Install the required environment to run and test the project. For more information, see Installing packages.

  3. Test the project locally to make sure that it runs as expected.

2. Create a Docker image or package the Python project into a ZIP file

Create a Docker image and push it to an image repository

  1. Create a Python image.

    This topic describes only the commands to download and install the agent, and to start the application using the ARMS Python agent.

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

    If you do not need to start the application using the Python agent, you must import the Python agent in the main entry file of the application, such as main.py, and then start the application.

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

Package the Python project into a ZIP file

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

3. Create a Python application

Create a Python application from an image

3.1 Create the application

This topic describes only the key steps. For more information, see Deploy an application from an image.

  1. On the Configure Image panel, set Technology Stack to Python and select an image version.

    xtP3K5ehBK

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

    qVjKh7KK96

  3. Click Create Application.

3.2 Test access

Test using the 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.

    oG7Zx8icdv

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

Test in Webshell

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

    Z3G4SkQoR7

  2. In the Actions column of the instance, click Webshell.

    4dI9DAwxpA

  3. On the Webshell page, enter curl 127.0.0.1:ContainerPort to test.

Create a Python application from a code package

3.1 Create the application

This topic describes only the key steps. For more information, see Deploy a Python application.

  1. On the Configure Code Package Deployment panel, set Technology Stack to Python. Then, in the Upload ZIP Package section, click the image icon to upload your ZIP package.

    Iye539HbsG

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

    1. In the Startup Command section, set the startup command.

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

      GZNwXgfjZm

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

      qVjKh7KK96

  3. Click Create Application.

3.2 Test access

Test using the 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.

    oG7Zx8icdv

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

Test in Webshell

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

    Z3G4SkQoR7

  2. In the Actions column of the instance, click Webshell.

    4dI9DAwxpA

  3. On the Webshell page, enter curl 127.0.0.1:ContainerPort to test.

4. View application monitoring data

View in the SAE console

Go to the Basic Information page for the application. In the navigation pane on the left, click Application Monitoring. On the Application Monitoring page, view the Monitoring Data.

Y3kM5Riwrv

View in the ARMS console

  1. Log on to the ARMS console.

  2. In the navigation pane on the left, choose Application Monitoring > Applications. In the top navigation bar, select the destination region.

    ZRS4rlkqyS

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

    p1fXmq3GtR

  4. On the monitoring details page, view the monitoring data.

    dq39ionBxZ