我能把Luigi管道错误路由到Sentry吗?

2024-05-23 09:36:23 发布

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

我的团队使用Sentry来跟踪错误,因此我不希望使用Luigi的内置电子邮件功能将所有报告保存在一个地方。在

我现在是这样设置的,它似乎完全跳过了哨兵:

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

Tags: name功能clientifmain电子邮件报告地方
1条回答
网友
1楼 · 发布于 2024-05-23 09:36:23

我想如果你申报一个callback to the failure event并在那里做哨兵追踪的事情,那应该是可能的:

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()

注意注意e.traceback只能在python3+as explained in this answer上工作。在

相关问题 更多 >

    热门问题