【问题标题】:Can I route Luigi pipeline errors to Sentry?我可以将 Luigi 管道错误路由到 Sentry 吗?
【发布时间】:2016-11-16 21:46:37
【问题描述】:

我的团队使用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

【问题讨论】:

    标签: python sentry luigi


    【解决方案1】:

    我认为如果您声明 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 仅适用于 python 3+ as explained in this answer。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多