使用pyinstrument lib可以在发生异常时获取异常数据吗?

2024-06-06 14:25:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想对用Python编写的分布式服务进行审计和监视,但想获得一个库,让我能够控制如何以及在何处保存结果。。。我找到了pyinstrument,它几乎满足了我的需要。
在我的flaskREST API中,我试图手动引发一个异常,以查看是否可以在跟踪结果中检查它,并查看它提供了多少有关此异常的信息,它似乎只显示堆栈跟踪中的几个步骤。
它只是说发生了一个错误,我是不是遗漏了什么

以下是我正在使用的配置:

@app.before_request
def before_request():
    g.profiler = Profiler()
    g.profiler.start()

@app.after_request
def after_request(response):
    if not hasattr(g, "profiler"):
        return response
    g.profiler.stop()
    output_html = g.profiler.output_html()
    return make_response(output_html)

Tags: apiappoutputreturnresponserequestdefhtml