def testExclusionViewPath(self): try: Message.objects.get(pk=1341324) except: get_client().create_from_exception() last = Message.objects.get() self.assertEquals(last.view, 'sentry.tests.tests.testExclusionViewPath')
def testAlternateDatabase(self): conf.DATABASE_USING = 'default' try: Message.objects.get(id=999999979) except Message.DoesNotExist, exc: get_client().create_from_exception()
def testThrashing(self): conf.THRASHING_LIMIT = 10 conf.THRASHING_TIMEOUT = 60 Message.objects.all().delete() GroupedMessage.objects.all().delete() for i in range(0, 50): get_client().create_from_text('hi') self.assertEquals(Message.objects.count(), conf.THRASHING_LIMIT)
def testBestGuessView(self): conf.EXCLUDE_PATHS = ['sentry.tests.tests'] try: Message.objects.get(pk=1341324) except: get_client().create_from_exception() last = Message.objects.get() self.assertEquals(last.view, 'sentry.tests.tests.testBestGuessView') conf.EXCLUDE_PATHS = []
def testNoThrashing(self): prev = conf.THRASHING_LIMIT conf.THRASHING_LIMIT = 0 Message.objects.all().delete() GroupedMessage.objects.all().delete() for i in range(0, 50): get_client().create_from_text('hi') self.assertEquals(Message.objects.count(), 50) conf.THRASHING_LIMIT = prev
def sentry_exception_handler(request=None, **kwargs): try: exc_type, exc_value, exc_traceback = sys.exc_info() if app.config['DEBUG'] or getattr(exc_type, 'skip_sentry', False): return if transaction.is_dirty(): transaction.rollback() extra = dict( request=request, ) message_id = get_client().create_from_exception(**extra) if request: # attach the sentry object to the request request.sentry = { 'id': message_id, } except Exception, exc: try: logger.exception(u'Unable to process log entry: %s' % (exc,)) except Exception, exc: warnings.warn(u'Unable to process log entry: %s' % (exc,))
def testCreateFromRecordNoneExcInfo(self): # sys.exc_info can return (None, None, None) if no exception is being # handled anywhere on the stack. See: # http://docs.python.org/library/sys.html#sys.exc_info client = get_client() record = logging.LogRecord( 'foo', logging.INFO, pathname=None, lineno=None, msg='test', args=(), exc_info=(None, None, None), ) message = client.create_from_record(record) self.assertEquals('test', message.message)
def test_get_client(self): from sentry.client.log import LoggingSentryClient self.assertEquals(get_client().__class__, SentryClient) self.assertEquals(get_client(), get_client()) conf.CLIENT = 'sentry.client.log.LoggingSentryClient' self.assertEquals(get_client().__class__, LoggingSentryClient) self.assertEquals(get_client(), get_client()) conf.CLIENT = 'sentry.client.base.SentryClient'
def test_simple(self): client = get_client('sentry.client.logging.LoggingSentryClient') _foo = {'': None} class handler(logging.Handler): def emit(self, record): _foo[''] = record logger = client.logger logger.addHandler(handler()) event_id = client.capture('Message', message='hello world') self.assertRaises(Event.DoesNotExist, Event.objects.get, event_id) self.assertEquals(_foo[''].getMessage(), 'hello world') self.assertEquals(_foo[''].levelno, client.default_level)
def test_logging_client(self): conf.CLIENT = 'sentry.client.log.LoggingSentryClient' client = get_client() _foo = {'': None} class handler(logging.Handler): def emit(self, record): _foo[''] = record logger = client.logger logger.addHandler(handler()) self.assertRaises(Exception, self.client.get, reverse('sentry-raise-exc')) self.assertEquals(_foo[''].getMessage(), 'view exception') self.assertEquals(_foo[''].levelno, client.default_level) self.assertEquals(_foo[''].class_name, 'Exception')
def testCorrectUnicode(self): self.setUpHandler() cnt = Message.objects.count() value = 'רונית מגן'.decode('utf-8') error = get_client().create_from_text(value) self.assertEquals(Message.objects.count(), cnt+1) self.assertEquals(error.message, value) logging.info(value) self.assertEquals(Message.objects.count(), cnt+2) x = TestModel.objects.create(data={'value': value}) logging.warn(x) self.assertEquals(Message.objects.count(), cnt+3) try: raise SyntaxMessage(value) except Exception, exc: logging.exception(exc) logging.info('test', exc_info=sys.exc_info())
def test_celery_client(self): from sentry.client.celery import CelerySentryClient self.assertEquals(get_client().__class__, SentryClient) self.assertEquals(get_client(), get_client()) conf.CLIENT = 'sentry.client.celery.CelerySentryClient' self.assertEquals(get_client().__class__, CelerySentryClient) self.assertEquals(get_client(), get_client()) self.assertRaises(Exception, self.client.get, reverse('sentry-raise-exc')) message = GroupedMessage.objects.get() self.assertEqual(message.class_name, 'Exception') self.assertEqual(message.message, 'view exception') conf.CLIENT = 'sentry.client.base.SentryClient'
# self.assertEquals(last.level, logging.ERROR) # self.assertEquals(last.message, 'foo') def testAPI(self): try: Message.objects.get(id=999999989) except Message.DoesNotExist, exc: error = get_client().create_from_exception() self.assertTrue(error.data.get('__sentry__', {}).get('exc')) else: self.fail('Unable to create `Message` entry.') try: Message.objects.get(id=999999989) except Message.DoesNotExist, exc: error = get_client().create_from_exception() self.assertTrue(error.data.get('__sentry__', {}).get('exc')) else: self.fail('Unable to create `Message` entry.') self.assertEquals(Message.objects.count(), 2) self.assertEquals(GroupedMessage.objects.count(), 2) last = Message.objects.all().order_by('-id')[0:1].get() self.assertEquals(last.logger, 'root') self.assertEquals(last.class_name, 'DoesNotExist') self.assertEquals(last.level, logging.ERROR) self.assertEquals(last.message, smart_unicode(exc)) get_client().create_from_text('This is an error', level=logging.DEBUG) self.assertEquals(Message.objects.count(), 3)
app = Flask(__name__) # OK CONTINUE WORKING from flaskext.babel import Babel from sentry.client import get_client from sentry.db import get_backend # Build configuration app.config.from_object('sentry.conf.SentryConfig') app.config.from_envvar('SENTRY_SETTINGS', silent=True) # Load configured datastore app.db = get_backend(app) # Load configured client app.client = get_client(app) # Flask-Babel (internationalization) app.babel = Babel(app) # Shortcuts to be exported for API capture = app.client.capture # Import views/templatetags to ensure registration import sentry.web.api import sentry.web.templatetags import sentry.web.views
def testLongURLs(self): # Fix: #6 solves URLs > 200 characters error = get_client().create_from_text('hello world', url='a'*210) self.assertEquals(error.url, 'a'*200) self.assertEquals(error.data['url'], 'a'*210)
def testAPI(self): try: Message.objects.get(id=999999989) except Message.DoesNotExist, exc: error = get_client().create_from_exception() self.assertTrue(error.data.get('__sentry__', {}).get('exc'))