以OpenTelemetry方式接入 在监控Python应用之前,您需要通过客户端将应用数据上报至APM服务端。本文介绍如何通过OpenTelemetry Python SDK上报Python应用数据。 前提条件 完成vpce接入。 python版本不低于3.8。 接入步骤 1.下载所需包。 plaintext pip install flask pip install requests pip install opentelemetrydistro opentelemetryexporterotlp opentelemetrybootstrap a install 2.查看接入点信息。 应用列表的接入指引会根据您所在资源池提供“通过 HTTP 上报数据”和“通过 gRPC 上报数据”的ENDPOINT(天翼云vpc网络接入点)、鉴权TOKEN信息。 3.示例代码。 plaintext from flask import Flask import requests backendaddr ' app Flask(name) @app.route('/hello') def index(): r requests.get(backendaddr) return r.text app.run(host'0.0.0.0', port8070) 4.添加运行参数。 请将命令中的token和endpoint替换成第2步中获取的接入点信息。 使用http方式上报的启动命令。 plaintext opentelemetryinstrument tracesexporter otlpprotohttp,console metricsexporter none servicename resourceattributes host.name exporterotlpendpoint exporterotlpheaders xctgauthorization python app.py 使用grpc方式上报的启动命令。 plaintext opentelemetryinstrument tracesexporter otlpprotogrpc,console metricsexporter none servicename resourceattributes host.name exporterotlpendpoint exporterotlpheaders xctgauthorization python app.py 5.接入验证。 启动Python应用后,通过8070端口访问对应的接口,在APM控制台应用列表将展示接入的应用。 plaintext