2016-11-16 48 views
1

我的團隊使用Sentry來跟蹤錯誤,所以我寧願不使用Luigi的內置電子郵件功能將所有報告保留在一個地方。我可以將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 

回答

2

我認爲,如果你聲明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只會在蟒蛇3+ as explained in this answer工作。