fly*_*zai 3 python sentry luigi
我的团队用于Sentry跟踪错误,因此我不希望使用 Luigi 的内置电子邮件功能将所有报告保存在一个地方。
这就是我目前的设置方式,它似乎完全跳过了 Sentry:
if __name__ == '__main__':
try:
luigi.run()
except Exception as e:
client = Client(
***
)
client.captureException(tags={
sys.argv[0]
})
logger.critical('Error occurred: {e}'.format(e=e))
raise
Run Code Online (Sandbox Code Playgroud)
我认为如果您声明对失败事件的回调并在那里执行哨兵跟踪工作,那应该是可能的:
import luigi
@luigi.Task.event_handler(luigi.Event.FAILURE)
def mourn_failure(task, exception):
client = Client(
***
)
# we also include extra context for the current task
client.captureException(
(type(e), e.message, e.traceback),
extra=dict(task=repr(task))
)
logger.critical('Error occurred: {e}'.format(e=exception))
if __name__ == '__main__':
luigi.run()
Run Code Online (Sandbox Code Playgroud)
注意,e.traceback仅适用于本答案中所述的python 3+ 。
| 归档时间: |
|
| 查看次数: |
487 次 |
| 最近记录: |