Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

fix: send raven calls to event loop #388

Merged
merged 1 commit into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions autopush/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import raven
from eliot import (add_destination, fields,
Logger, MessageType)
from twisted.internet import reactor
from twisted.python.log import textFromEventDict, startLoggingWithObserver

HOSTNAME = socket.getfqdn()
Expand All @@ -41,8 +42,11 @@ def __init__(self):
def raven_log(self, event):
"""Log out twisted exception failures to Raven"""
f = event['failure']
self.raven_client.captureException(
(f.type, f.value, f.getTracebackObject()))
# Throw back to event loop
reactor.callFromThread(
self.raven_client.captureException,
(f.type, f.value, f.getTracebackObject())
)

def __call__(self, msg):
"""Called to log out messages"""
Expand Down
13 changes: 12 additions & 1 deletion autopush/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from mock import Mock, patch
from nose.tools import eq_, ok_
from twisted.internet import reactor
from twisted.internet.defer import Deferred
from twisted.python import log, failure

from autopush.logging import setup_logging
Expand All @@ -28,8 +30,17 @@ def test_sentry_logging(self):

log.err(failure.Failure(Exception("eek")))
self.flushLoggedErrors()
eq_(len(self.mock_client.mock_calls), 1)
d = Deferred()

def check():
if len(self.mock_client.mock_calls):
eq_(len(self.mock_client.mock_calls), 1)
d.callback(True)
else: # pragma: nocover
reactor.callLater(0, check)
del os.environ["SENTRY_DSN"]
reactor.callLater(0, check)
return d


class EliotLogTestCase(twisted.trial.unittest.TestCase):
Expand Down