您如何在开发环境中配置 Sentry raven 客户端以不发送异常并仍然工作?

How do you configure a Sentry raven client in a development environment to not send exceptions and still work?

我们是 运行 Django 服务器并使用 Sentry 捕获异常。当我们配置 Sentry 时,我们添加 RAVEN_CONFIG 我们不同的 settings.py 文件:

INSTALLED_APPS = (
    'raven.contrib.django.raven_compat'
)

RAVEN_CONFIG = {
    'dsn': 'https://*****@app.getsentry.com/PORT_NUMBER',
}

我们阅读 here that we can just use an empty string DSN property. Though when we run python manage.py raven test as depicted here 我们得到:

raven.exceptions.InvalidDsn: Unsupported Sentry DSN scheme:  ()

最好的解决方案是我们始终可以使用 Raven 客户端,并且设置文件将定义是否发送异常。

另一个要求是我们要使用Client模块并捕获异常。为此 we have to set 一些 DSN 值:

from raven import Client
client = Client('https://<key>:<secret>@app.getsentry.com/<project>')

所以不设置 DSN 值是不可能的

We read here that we can just use an empty string DSN property.

您不应将 DSN 设置为空字符串,而是在您的开发设置配置中 不要指定 DSN 设置 第一名:

RAVEN_CONFIG = {}

文档没有说您设置DSN值,只有一个示例如何设置它。

In [1]: from raven import Client

In [2]: client = Client()
Raven is not configured (logging is disabled). Please see the documentation for more information.

In [3]: client.captureMessage('hello')  # it's a noop - no error, no capture.

请务必注意,您应该将 None(或什么都不传递)作为 DSN 参数传递,而不是空字符串,否则会引发 InvalidDsn: Unsupported Sentry DSN scheme.

此外,如果您不喜欢日志中的 Raven is not configured (logging is disabled)...,您可以像这样将其静音:

>>> import logging
>>> logging.getLogger('raven').setLevel(logging.WARNING)