0

I'm using Rollbar for error tracking for my Django Application. For some reason, I'm getting errors from my localhost (in development).

Settings.py:

import rollbar
import os

THUMBNAIL_DEBUG = False
DEBUG = False
TEMPLATE_DEBUG = False

ROLLBAR = {
        'access_token': '****',
        'environment': 'development' if DEBUG else 'production',
        'root': BASE_DIR,
        'class': 'rollbar.logger.RollbarHandler'
    }

rollbar.init(**ROLLBAR)

Settings_Dev.py:

from settings import *

DEBUG = True
TEMPLATE_DEBUG = True
THUMBNAIL_DEBUG = True

I use settings_dev.py for my local development environment.

3 Answers3

2

I usually create three settings files. The first one is for base settings that apply to both development and production. The other two import everything from base and add extras.

So for your case, you can have settings_base.py:

THUMBNAIL_DEBUG = False
DEBUG = False
TEMPLATE_DEBUG = False

And for settings_production.py:

from settings_production import *

ROLLBAR = {
        'access_token': '****',
        'environment': 'development' if DEBUG else 'production',
        'root': BASE_DIR,
        'class': 'rollbar.logger.RollbarHandler'
    }

rollbar.init(**ROLLBAR)

This way Rollbar will only be enabled in production.

JPG
  • 82,442
  • 19
  • 127
  • 206
kichik
  • 33,220
  • 7
  • 94
  • 114
0

Nowadays it seems that you can use the "enabled" setting:

ROLLBAR = {
    'access_token': '****',
    'environment': 'development' if DEBUG else 'production',
    'root': BASE_DIR,
    'class': 'rollbar.logger.RollbarHandler',
    'enabled': not DEBUG,
}
damd
  • 6,116
  • 7
  • 48
  • 77
0

This answer isn't Django-specific, but it provides three separate ways in which to disable rollbar:

Via a payload handler

Add a payload handler to ignore all payloads to rollbar.

import rollbar

def _payload_handler_to_disable_rollbar(payload, **kw) -> bool:
    return False

rollbar.events.add_payload_handler(_payload_handler_to_disable_rollbar)

If using pytest, define the above in ./confest.py in the function pytest_sessionstart as per this answer.

Via monkeypatching

Monkeypatch rollbar.report_exc_info to disable it.

import rollbar

def _disabled_rollbar_report_exc_info(*_args, **_kwargs) -> None:
    pass

rollbar.report_exc_info = _disabled_rollbar_report_exc_info

If using pytest, define the above in ./confest.py in the function pytest_sessionstart as per this answer.

Via /etc/hosts

Update /etc/hosts to block api.rollbar.com.

$ sudo echo '127.0.0.1 api.rollbar.com' >> /etc/hosts
$ sudo dscacheutil -flushcache  # On Mac to flush the DNS cache.
Asclepius
  • 57,944
  • 17
  • 167
  • 143