Sentry只显示:无错误

问题描述:

我想用Sentry + Raven检测独立Python脚本中的错误。
我试图配置它并raven test ...正在工作。
后来我把这个在脚本的顶部:Sentry只显示<unknown>:无错误

from raven import Client 
client = Client('http://[email protected]/1') 
client.captureException() 

的异常后产生于这样的:

import django 
django.setup() 
from django.conf import settings 

而且我希望看到这个错误的实际堆栈:

ImportError: Could not import settings 'settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'settings' 

但我在哨兵看到的全部是

Useless message

这是完全没用的。

我该如何改变这个以获得正常的回溯?

您误会了client.captureException()的工作原理,它不是配置参数。您可以使用它,当你捕获异常,这将捕获的异常类型和消息:

try: 
    f = open('oogah-boogah.txt') 
except IOError: 
    client.captureException() 
    # do something here 

为了捕捉可能在一个代码块中产生任何异常,您可以使用capture_exceptions

@client.capture_exceptions 
def load_django(): 
    import django 
    django.setup() 
    from django.conf import settings 

Yes you're right, but is there a way to catch an exception not wrapping a block of code in a try-except. I can see the error in a terminal, can I see it in Sentry?

有一个默认的异常处理 - 在未捕获的异常,这种默认的处理程序将其捕获并显示异常。这是你在终端上看到的。

生成此输出的函数是sys.excepthook,默认情况下它将输出到stderr

所以,为了让你赶上所有例外全球范围内,你必须创建一个全球性的异常处理程序或您自己的函数映射到sys.excepthook

我强烈建议不要这样做,但因为你不知道它可能有什么其他副作用。

+0

是的你是对的,但是有没有办法在try-except中捕获一个不包含代码块的异常。我可以在终端看到错误,我可以在Sentry中看到它吗? – Sergey 2014-09-02 10:54:56