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

16,153

Solution 1

Documentation didn't say you have to set DSN value, there's just an example how to set it.

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.

It's important to note that you should pass None (or nothing at all) as DSN parameter and not empty string, otherwise it raises InvalidDsn: Unsupported Sentry DSN scheme.

Also, if you don't like that Raven is not configured (logging is disabled)... in your logs, you can mute it like so:

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

Solution 2

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

You should not be setting DSN to an empty string, but instead in your development settings configuration don't specify the DSN setting in the first place:

RAVEN_CONFIG = {}
Share:
16,153

Related videos on Youtube

Agam Rafaeli
Author by

Agam Rafaeli

You say potato, I say let's blow this joint

Updated on June 04, 2022

Comments

  • Agam Rafaeli
    Agam Rafaeli almost 2 years

    We are running a Django server and using Sentry to capture exceptions. When we configure Sentry we add RAVEN_CONFIG our different settings.py files:

    INSTALLED_APPS = (
        'raven.contrib.django.raven_compat'
    )
    
    RAVEN_CONFIG = {
        'dsn': 'https://*****@app.getsentry.com/PORT_NUMBER',
    }
    

    We read here that we can just use an empty string DSN property. Though when we run python manage.py raven test as depicted here we get:

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

    The best solution would be that we could always use a Raven client and the settings file would define whether exceptions are sent or not.

    Another requirement is that we would like to use the Client module and capture exceptions. For this we have to set some DSN value:

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

    So not setting a DSN value isn't possible

  • Agam Rafaeli
    Agam Rafaeli about 8 years
    Editted the question to explain why this isn't possible. TL;DR - we would like to use the python raven Client module which requires a DSN on initialization
  • Steve
    Steve about 5 years
    I thought the "and still work" part of the question meant sending the Sentry info somewhere (like the logs, for example). Is there a way to get it to log what it would have sent, instead of the entirely unhelpful "not configured" message (which it could log once at startup)?
  • TheRealFakeNews
    TheRealFakeNews over 4 years
    Just FYI: your config might not allow white space, so just do RAVEN_CONFIG={}