Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions rollbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def wrap(*args, **kwargs):
return func(*args, **kwargs)
return wrap


try:
from tornado.gen import coroutine as tornado_coroutine
from tornado.httpclient import AsyncHTTPClient as TornadoAsyncHTTPClient
Expand All @@ -102,7 +103,7 @@ def wrap(*args, **kwargs):
import treq
from twisted.python import log as twisted_log

def log_handler(event):
def twisted_log_observer(event):
"""
Default uncaught error handler
"""
Expand All @@ -119,11 +120,6 @@ def log_handler(event):
report_exc_info((err.type, err.value, err.getTracebackObject()))
except:
log.exception('Error while reporting to Rollbar')

# Add Rollbar as a log handler which will report uncaught errors
twisted_log.addObserver(log_handler)


except ImportError:
treq = None

Expand Down Expand Up @@ -302,8 +298,12 @@ def init(access_token, environment='production', **kw):
if SETTINGS.get('allow_logging_basic_config'):
logging.basicConfig()

if SETTINGS.get('handler') == 'agent':
handler = SETTINGS.get('handler')
if handler == 'agent':
agent_log = _create_agent_log()
elif handler == 'twisted' and treq:
# Add Rollbar as a Twisted Observer which will report uncaught errors
twisted_log.addObserver(twisted_log_observer)

# We will perform these transforms in order:
# 1. Serialize the payload to be all python built-in objects
Expand Down Expand Up @@ -448,7 +448,7 @@ def send_payload(payload, access_token):
_send_payload_appengine(payload_str, access_token)
elif handler == 'twisted':
if treq is None:
log.error('Unable to find Treq')
log.error('treq and twisted are required for the twisted handler')
return
_send_payload_twisted(payload_str, access_token)
else:
Expand Down Expand Up @@ -1193,7 +1193,7 @@ def _build_server_data():
# argv does not always exist in embedded python environments
argv = getattr(sys, 'argv', None)
if argv:
server_data['argv'] = argv
server_data['argv'] = argv

for key in ['branch', 'root']:
if SETTINGS.get(key):
Expand Down