After you instrument your application with SkyWalking and report distributed tracing data to Managed Service for OpenTelemetry, Managed Service for OpenTelemetry starts to monitor your application. You can then view a range of monitoring data, such as application topology, traces, failed transactions, slow transactions, and SQL analysis. This topic describes how to use the SkyWalking Python Agent to enable auto-instrumentation and report application data.
Prerequisites
-
You have downloaded the Python agent for Apache SkyWalking. We recommend that you use the latest version.
-
You have added the SkyWalking Python agent to your Python project.
-
Background information
SkyWalking is a popular open source application performance monitoring (APM) tool for microservices, cloud-native, and container-based architectures, including Docker, Kubernetes, and Mesos. At its core, SkyWalking is a distributed tracing system.
skywalking-python is the official Python agent library for SkyWalking. You can integrate skywalking-python to monitor Python applications. It supports auto-instrumentation for many third-party libraries, such as Kafka, HTTP, AIOHTTP, Redis, and WebSockets.
Sample application
Sample application repository: SkyWalking Demo
This demo is a simple, Flask-based example that forwards requests and interacts with a MySQL database. The SkyWalking agent monitors the application and reports data.
Enable auto-instrumentation for a Python application
You can configure SkyWalking Python Agent parameters in your Python project files or as environment variables.
Configure parameters in code
Modify theconfig.init parameters in your Python project file. In the sample application, the corresponding files are proxy/TestProxy.py and controller/TestController.py.
from skywalking import config
config.init(ConfigurationName = ConfigurationValue)
Configure parameters as environment variables
Add the following content to your environment variable file and then restart your application for the changes to take effect.
export SW_AGENT_ConfigurationName=ConfigurationValue
For Docker container environments, you can configure environment variables under the environment option in the docker-compose.yaml file.
-
Configure the endpoint and token.
-
Import SkyWalking in your Python file.
from skywalking import agent, config -
Configure the endpoint and authentication token.
Replace
<endpoint>and<auth-token>with the endpoint and authentication token you obtained in the Prerequisites section.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>') -
Configure the data reporting protocol. The only supported protocol is gRPC.
### The only available reporting protocol is 'grpc'. config.init(agent_protocol='<protocol>') -
Configure other optional parameters as needed. For more information, see the Apache SkyWalking official documentation.
-
Restart the application.
FAQ
-
What do I do if the
Method not found: skywalking.v3.LogReportService/collecterror occurs when reporting data over gRPC?grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNIMPLEMENTED details = "Method not found: skywalking.v3.LogReportService/collect" debug_error_string = "UNKNOWN:Error received from peer {grpc_message:"Method not found: skywalking.v3.LogReportService/collect", grpc_status:12, created_time:"2023-07-05T15:58:00"}" >Set
agent_log_reporter_activetoFalsein theconfig.initcall.config.init(agent_log_reporter_active=False) -
What do I do if the
Method not found: skywalking.v3.MeterReportService/collecterror occurs when reporting data over gRPC?grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNIMPLEMENTED details = "Method not found: skywalking.v3.MeterReportService/collect" debug_error_string = "UNKNOWN:Error received from peer {grpc_message:"Method not found: skywalking.v3.MeterReportService/collect", grpc_status:12, created_time:"2023-07-05T16:00:00+08:00"}" >The console does not support
metricdata reporting. In theconfig.initcall, setagent_meter_reporter_activetoFalse.config.init(agent_meter_reporter_active=False)

