tencent cloud

Tencent Cloud Observability Platform

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Strengths
Basic Features
Basic Concepts
Use Cases
Use Limits
Purchase Guide
Tencent Cloud Product Monitoring
Application Performance Management
Mobile App Performance Monitoring
Real User Monitoring
Cloud Automated Testing
Prometheus Monitoring
Grafana
EventBridge
PTS
Quick Start
Monitoring Overview
Instance Group
Tencent Cloud Product Monitoring
Application Performance Management
Real User Monitoring
Cloud Automated Testing
Performance Testing Service
Prometheus Getting Started
Grafana
Dashboard Creation
EventBridge
Alarm Service
Cloud Product Monitoring
Tencent Cloud Service Metrics
Operation Guide
CVM Agents
Cloud Product Monitoring Integration with Grafana
Troubleshooting
Practical Tutorial
Application Performance Management
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Parameter Information
FAQs
Mobile App Performance Monitoring
Overview
Operation Guide
Access Guide
Practical Tutorial
Tencent Cloud Real User Monitoring
Product Introduction
Operation Guide
Connection Guide
FAQs
Cloud Automated Testing
Product Introduction
Operation Guide
FAQs
Performance Testing Service
Overview
Operation Guide
Practice Tutorial
JavaScript API List
FAQs
Prometheus Monitoring
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Terraform
FAQs
Grafana
Product Introduction
Operation Guide
Guide on Grafana Common Features
FAQs
Dashboard
Overview
Operation Guide
Alarm Management
Console Operation Guide
Troubleshooting
FAQs
EventBridge
Product Introduction
Operation Guide
Practical Tutorial
FAQs
Report Management
FAQs
General
Alarm Service
Concepts
Monitoring Charts
CVM Agents
Dynamic Alarm Threshold
CM Connection to Grafana
Documentation Guide
Related Agreements
Application Performance Management Service Level Agreement
APM Privacy Policy
APM Data Processing And Security Agreement
RUM Service Level Agreement
Mobile Performance Monitoring Service Level Agreement
Cloud Automated Testing Service Level Agreement
Prometheus Service Level Agreement
TCMG Service Level Agreements
PTS Service Level Agreement
PTS Use Limits
Cloud Monitor Service Level Agreement
API Documentation
History
Introduction
API Category
Making API Requests
Monitoring Data Query APIs
Alarm APIs
Legacy Alert APIs
Notification Template APIs
TMP APIs
Grafana Service APIs
Event Center APIs
TencentCloud Managed Service for Prometheus APIs
Monitoring APIs
Data Types
Error Codes
Glossary

Access of Python Applications via SkyWalking

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-03-04 22:02:22
This document describes how to report data from a Python application via SkyWalking.

Prerequisites

Python applications are of Python version 3.7 or later, so that automatic instrumentation and reporting via SkyWalking can be achieved.
Currently, gRPC is used for reporting by default.
For details of the components that currently support automatic event tracking, see Frameworks Supported by Python Agent.

Directions

Step 1. Getting the Access Point and Token

1. Log in to the TCOP console.
2. In the left sidebar, select Application Performance Management, and then click Application list > Access application.
3. On the page that pops up on the right, select the Python language.
4. On the Access Python Application page, select the Region and Business System.
5. Select SkyWalking as Access protocol type.
6. Select a Reporting method through which you want to report data, and obtain your Access Point and Token.
Note:
Report over private network: This reporting method requires your service to run in the Tencent Cloud VPC. The direct connection through VPC can help avoid the security risks of public network communication and save costs on reporting traffic.
Report over public network: If your service is deployed locally or in a non-Tencent Cloud VPC, you can report data in this method. However, it involves security risks in public network communication and incurs reporting traffic fees.

Step 2: Installing SkyWalking Agent-Related Dependencies

pip install apache-skywalking
# This library is used in the current demo.
pip install tornado

Step 3: Modifying Startup Code

from skywalking import agent, config
config.init(
# Replace with the access point obtained in Step 1.
agent_collector_backend_services='ap-guangzhou.apm.tencentcs.com:11800',
agent_name='python-skywalking', # Customize the application name here.
agent_authentication="xxxxxxxxxxxxxx", # Replace with the token obtained in Step 1.
agent_logging_level="INFO")
agent.start()

The complete demo code is as follows:

import time
import tornado.ioloop
import tornado.web


class MainHandler(tornado.web.RequestHandler):
def get(self):
print("call")
self.write("Hello, world")


class SleepHandler(tornado.web.RequestHandler):
def get(self):
print("call sleep")
time.sleep(0.1)
self.write("sleep 0.1s")


def make_app():
return tornado.web.Application([
(r"/test", MainHandler),
(r"/sleep", SleepHandler),
])


if __name__ == "__main__":
from skywalking import agent, config
config.init(agent_collector_backend_services=''{access point}', # Replace with the access point obtained in Step 1.
agent_name='python-skywalking',
agent_authentication='{token}', # Replace with the token obtained in Step 1.
agent_logging_level='INFO')
agent.start()
app = make_app()
port = 9008
app.listen(port)
print("server in %s" % port)
tornado.ioloop.IOLoop.current().start()


Step 4: Accessing Through Multiple Threads

This step is optional. After completing the above 3 steps, you can view the reported data in the TCOP console, in APM > Application list. If you want to achieve access through multiple threads, you can use the tornado package. Note that the SkyWalking Agent needs to be started after the fork process starts.

Introducing the tornado Dependency

pip install tornado

The complete demo code is as follows:

import time
import os
import tornado.ioloop
import tornado.web
from tornado.httpserver import HTTPServer


class MainHandler(tornado.web.RequestHandler):
def get(self):
print("call")
self.write("Hello, world")


class Sleep01Handler(tornado.web.RequestHandler):
def get(self):
print("call sleep")
time.sleep(0.1)
self.write("sleep 0.1s")


def make_app():
return tornado.web.Application([
(r"/test", MainHandler),
(r"/sleep", Sleep01Handler),
])


if __name__ == "__main__":
from skywalking import agent, config
config.init(agent_collector_backend_services='{access point}', # Replace with the access point obtained in Step 1.
agent_name='python-skywalking-multi',
agent_authentication='{token}', # Replace with the token obtained in Step 1.
agent_logging_level='INFO')
app = make_app()
port = 9009
num_processes = 4
sockets = tornado.netutil.bind_sockets(port)
tornado.process.fork_processes(num_processes)
# For multi-process usage, start the agent after the fork process starts.
agent.start()
pid = os.getpid()
print("Current process ID:%d" % pid)
server = HTTPServer(app)
server.add_sockets(sockets)
print("server in %s" % port)
tornado.ioloop.IOLoop.current().start()



Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan