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
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.
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
For Docker containers, you can configure environment variables in the environment directory of the docker-compose.yaml file.
Configure an endpoint and a token.
Configure the SkyWalking Python agent in the Python file.
from skywalking import agent, config
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>')
Configure a service name as the application identifier.
config.init(agent_name='<service name>')
Specify a protocol over which data is reported. SkyWalking supports gRPC.
### Specify gRPC as the protocol. config.init(agent_protocol='<protocol>')
Configure optional parameters based on your business requirements. For more information about the parameters, see Apache SkyWalking documentation.
Restart the application.
FAQ
What do I do if the message
Method not found: skywalking.v3.LogReportService/collect
appears?Set the
agent_log_reporter_active
parameter nested underconfig.init
toFalse
.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? You cannot reportmetrics
to the console. You can set theagent_meter_reporter_active
parameter nested underconfig.init
toFalse
.config.init(agent_meter_reporter_active=False)