skywalking对接python

发布时间 2023-12-19 15:53:44作者: 少年老余

1.官网:https://skywalking.apache.org/docs/skywalking-python/next/readme/

2.安装

pip install "apache-skywalking"

3.集成到flask,启动服务

from flask import Flask, request, render_template
from upload_file_to_s3 import uploads3 , get_md5
from skywalking import agent, config
app = Flask(__name__)

@app.route('/s3file')
def index():
    return render_template('file_upload.html')

@app.route('/s3file/file_upload', methods=['POST'])
def file_upload():
    file = request.files.get('file')
    filepath='C:\\Users\\LX\\Desktop\\'
    if file:
        file.save( filepath + file.filename)

        upload_result=uploads3.upload(filepath,file.filename)
        md5=get_md5.get_file_md5(filepath,file.filename)

        if upload_result  == 1:
            return '文件上传成功,路径: https://***:11443/pub/'+file.filename + "  md5值:" + md5
        else:
            return  '文件上传失败,请联系管理员'
    else:
        return '上传失败,未选择文件'



if __name__ == '__main__':
    app.run(port=8002,host='0.0.0.0',debug=True)

#导入skywalking python
config.init(agent_collector_backend_services='11.0.1.134:11800', agent_name='python-test', agent_instance_name='your-instance-name or <generated uuid>')
config.flask_collect_http_params = True
#排除一些不想纳入跟踪的组件
#config.disable_plugins = ['sw_http_server', 'sw_urllib_request','sw_django','sw_tornado','sw_urllib3','sw_sanic','sw_aiohttp','sw_pyramid']
agent.start()

 

4.观察skywalking ui