All Products
Search
Document Center

Managed Service for OpenTelemetry:Use SkyWalking to report Python application data

Last Updated:Sep 23, 2024

Before you can view the trace data of your application, you must use a client to report the trace data to Managed Service for OpenTelemetry. This topic describes how to use SkyWalking SDK for Python to report Python application data.

Prerequisites

  • The Python agent of Apache SkyWalking is downloaded. We recommend that you download the latest version of the Python agent.

  • SkyWalking-Python is referenced in a Python project.

Prerequisites

To obtain the endpoint of SkyWalking, perform the following steps:

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, click Cluster Configurations. On the page that appears, click the Access point information tab.

  3. In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.

  4. Set the Client parameter to SkyWalking.

    Obtain the endpoint of SkyWalking in the Related Information column of the table in the lower part.

    SkyWalking接入点信息

    Note

    If your application is deployed in an Alibaba Cloud production environment, use the VPC endpoint. Otherwise, use the public endpoint.

Background information

SkyWalking is a popular application performance monitoring (APM) service developed in China. SkyWalking is designed for microservices, cloud-native architectures, and containers, such as Docker, Kubernetes, and Mesos. SkyWalking is also a distributed tracing system.

SkyWalking-Python is the official Python agent repository of SkyWalking. You can use SkyWalking-Python to monitor Python applications. You can use SkyWalking-Python to automatically instrument third-party repositories such as Kafka, AIOHTTP, Redis, and WebSockets.

The following table describes the third-party repositories that can be monitored by using SkyWalking-Python.

Repository

Python version - Repository version

Plug-in

aiohttp

3.7 or later - 3.7.*

sw_aiohttp

aioredis

3.7 or later - 2.0.*

sw_aioredis

aiormq

3.7 or later - 6.3 and 6.4

sw_aiormq

amqp

3.7 or later - 2.6.1

sw_amqp

asyncpg

3.7 or later - 0.25.0

sw_asyncpg

bottle

3.7 or later - 0.12.23

sw_bottle

celery

3.7 or later - 5.1

sw_celery

confluent_kafka

3.7 or later - 1.5.0, 1.7.0, and 1.8.2

sw_confluent_kafka

django

3.7 or later - 3.2

sw_django

elasticsearch

3.7 or later - 7.13, 7.14, and 7.15

sw_elasticsearch

hug

3.11 or later - Not supported

3.10 or later - 2.5 and 2.6

3.7 or later - 2.4.1, 2.5, and 2.6

sw_falcon

fastapi

3.7 or later - 0.89.* and 0.88.*

sw_fastapi

flask

3.7 or later - 2.0

sw_flask

happybase

3.7 or later - 1.2.0

sw_happybase

http_server

3.7 or later - *

sw_http_server

werkzeug

3.7 or later - 1.0.1 and 2.0

sw_http_server

httpx

3.7 or later - 0.23.* and 0.22.*

sw_httpx

kafka-python

3.7 or later - 2.0

sw_kafka

loguru

3.7 or later - 0.6.0 and 0.7.0

sw_loguru

mysqlclient

3.7 or later - 2.1.*

sw_mysqlclient

neo4j

3.7 or later - 5.*

sw_neo4j

psycopg[binary]

3.11 or later - 3.1.*

3.7 or later - 3.0.18 and 3.1.*

sw_psycopg

psycopg2-binary

3.10 or later - Not supported

3.7 or later - 2.9

sw_psycopg2

pymongo

3.7 or later - 3.11.*

sw_pymongo

pymysql

3.7 or later - 1.0

sw_pymysql

pyramid

3.7 or later - 1.10 and 2.0

sw_pyramid

pika

3.7 or later - 1.2

sw_rabbitmq

redis

3.7 or later - 3.5.* and 4.5.1

sw_redis

requests

3.7 or later - 2.26 and 2.25

sw_requests

sanic

3.10 or later - Not supported

3.7 or later - 20.12

sw_sanic

tornado

3.7 or later - 6.0 and 6.1

sw_tornado

urllib3

3.7 or later - 1.26 and 1.25

sw_urllib3

urllib_request

3.7 or later - *

sw_urllib_request

websockets

3.7 or later - 10.3 and 10.4

sw_websockets

Sample code

For more information about the sample code repository, see skywalking demo at GitHub.

The sample code implements simple routing and forwarding of an HTTP request based on the Flask framework and performs operations on a MySQL database based on the request. After the data is reported to Managed Service for OpenTelemetry, you can view the cross-process trace and the monitoring data of the MySQL database call.

Use SkyWalking to automatically instrument a Python application

You can configure the parameters of the SkyWalking Python agent directly in a Python project or by defining environment variables.

Configure the parameters of the SkyWalking Python agent in a Python project

Modify the config.init parameters in the Python project file. In this sample code, the proxy/TestProxy.py and controller/TestController.py files are used.

from skywalking import config
config.init(ConfigurationName = ConfigurationValue)

Configure the parameters of the SkyWalking Python agent by defining environment variables

Add the following content to the environment variable file and refresh the file to make the modified file take effect:

export SW_AGENT_ConfigurationName=ConfigurationValue
Note

For Docker containers, you can configure environment variables in the environment directory of the docker-compose.yaml file.

  1. Configure an endpoint and a token.

    1. Configure the SkyWalking Python agent in the Python file.

      from skywalking import agent, config
    2. Configure the endpoint and the token.

      Replace <endpoint> and <auth-token> with the endpoint and authentication token obtained in the prerequisites.

      config.init(agent_collector_backend_services='<endpoint>',
                  agent_authentication='<auth-token>')
  2. Configure a service name as the application identifier.

    config.init(agent_name='<service name>')
  3. Specify a protocol over which data is reported. SkyWalking supports gRPC.

    ### Specify gRPC as the protocol. 
    config.init(agent_protocol='<protocol>')
  4. Configure optional parameters based on your business requirements. For more information about the parameters, see Apache SkyWalking documentation.

  5. Restart the application.

FAQ

  • What do I do if the message Method not found: skywalking.v3.LogReportService/collect appears?image.png

    Set the agent_log_reporter_active parameter nested under config.init to False.

    config.init(agent_log_reporter_active=False)
  • What do I do if the message Method not found: skywalking.v3.MeterReportService/collect appears when I report data over gRPC? image.pngYou cannot report metrics to the console. You can set the agent_meter_reporter_active parameter nested under config.init to False.

    config.init(agent_meter_reporter_active=False)

References

Official website of Apache SkyWalking