tencent cloud

Feedback

Automatic Connecting Python Application for the TKE Environment (Recommended)

Last updated: 2024-06-19 16:31:30
    For Python applications deployed on TKE, APM offers automatic connection schemes, enabling automatic agent injection after the application is deployed to TKE, facilitating quick connection.
    Automatic connecting Python applications for the TKE environment will use the community OpenTelemetry-Python scheme for agent injection. For more information on OpenTelemetry-Python, see the community OpenTelemetry-Python project.

    Prerequisites

    See Supported Components and Frameworks by the OpenTelemetry-Python Scheme to ensure that your Python versions, dependency libraries, and frameworks are within the supported range of the agent. For dependency libraries and frameworks supported by automatic instrumentation, data reporting is completed upon successful connection without the need to modify the code. If automatic Event Tracking does not meet your scenario, or you need to add business layer tracing, use the OpenTelemetry API for Custom Event Tracking.

    Step 1: Install Operator.

    Install Operator in the TKE cluster, it's recommended to install Operator with one click on the APM console, for details see installing tencent-opentelemetry-operator.

    Step 2: Add annotation to workload.

    1. Log in to TKE console.
    2. Click Cluster to enter the corresponding TKE cluster.
    3. In Workload, locate the application that needs to connect with APM, click More, then click Edit YAML.
    4. In the Pod annotation where the application is located, add the following content, then click Complete to finish the connection.
    cloud.tencent.com/inject-python: "true"
    cloud.tencent.com/otel-service-name: my-app # Application name, processes that connect using the same application name are displayed in APM as multiple instances under the same application.
    # The application name can be up to 63 characters and can only contain lowercase letters, digits, and the separator (-), and it must start with a lowercase letter and end with a digit or lowercase letter.
    Note that this content needs to be added to spec.template.metadata.annotations, affecting the Pod's annotation, not the workload's annotation. You can see the following code snippet:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    labels:
    k8s-app: my-app
    name: my-app
    namespace: default
    spec:
    selector:
    matchLabels:
    k8s-app: my-app
    template:
    metadata:
    labels:
    k8s-app: my-app
    annotations:
    cloud.tencent.com/inject-python: "true" # Add it here.
    cloud.tencent.com/otel-service-name: my-app
    spec:
    containers:
    image: my-app:0.1
    name: my-app

    Connection Verification

    After an annotation is added to the workload, depending on the published policy, you can trigger the restart of the application Pod. The newly started Pod will automatically inject an agent and connect to the APM server to report monitoring data. The reported business system is the default business system of the Operator. In normal traffic cases, the connected applications will be displayed in APM > Application monitoring > Application list , and the connected application instances will be displayed in APM > Application monitoring > App details > Instance monitoring. Since there is a certain latency in the processing of observable data, if the applications or instances are not found in the console after connecting, wait about 30 seconds.

    Django Application Precautions

    If your application uses the Django framework, pay attention to the following points before connecting:
    1. It is recommended to deploy the service using uWSGI. For deployment methods, see through uWSGI Hosting Django Application. Starting directly through the python command may cause reporting failures.
    2. The introduction of OpenTelemetry-Python may result in Django applications no longer using the default configuration file. It is necessary to re-specify the configuration file through environment variables:
    export DJANGO_SETTINGS_MODULE=mysite.settings
    Or add environment variables through a YAML file:
    env:
    - name: DJANGO_SETTINGS_MODULE
    value: mysite.settings

    More Connection Configuration Items (Optional)

    At the Workload level, you can add more annotations to adjust the connect behaviors:
    Configuration Item
    Description
    cloud.tencent.com/apm-token
    Specify the Token for the APM business system. If this configuration item is not added, the Operator's configuration is used (corresponding to the Operator's env.APM_TOKEN field).
    cloud.tencent.com/python-instr-version
    Specify the Python agent version. If this configuration item is not added, the Operator's configuration is used (corresponding to the Operator's env.PYTHON_INSTR_VERSION field). The value can be latest (default) or a specific version number. For a list of specific version numbers, see Agent Version Information. It is not recommended to fill in this field unless necessary.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support