我正在使用 Docker 在计算引擎上运行 Django。我想知道当应用程序遇到像云运行这样的错误时,如何检查错误报告中的错误。
我正在研究如何在 Python 中设置错误报告。https://github.com/googleapis/python-error-reporting/tree/main/samples/snippets/fluent_on_compute
查看此示例,我似乎需要引发异常并运行report (traceback.format_exc ())
以使用错误报告。
def simulate_error():
fluent.sender.setup('myapp', host='localhost', port=24224)
def report(ex):
data = {}
data['message'] = '{0}'.format(ex)
data['serviceContext'] = {'service': 'myapp'}
# ... add more metadata
fluent.event.Event('errors', data)
# report exception data using:
try:
# simulate calling a method that's not defined
raise NameError
except Exception:
report(traceback.format_exc())
当我运行 Django 时,除了使用try: execpt
.
如何在错误报告中显示此类错误?
请让我知道是否有任何好的方法。谢谢你。