def test_raven_method(self):
        def exception_call2(a, b, c):
            return a + b + c / (a - b)

        def exception_call1(x, y):
            return exception_call2(y, x, 42)

        try:
            exception_call1(5, 5)
        except:
            self.client.raven('some message')

        eq_(1, len(self.client.sender.msgs))

        msg = json.loads(self.client.sender.msgs[0])

        rc = RavenClient()
        sentry_fields = rc.decode(msg['payload'])
        eq_(sentry_fields['culprit'], 'test_metlog in exception_call2')
        eq_(len(sentry_fields['sentry.interfaces.Stacktrace']['frames']), 3)
        eq_(sentry_fields['extra']['msg'], 'some message')

        eq_(msg['logger'], '')
        eq_(msg['fields']['msg'], 'some message')
        eq_(msg['type'], 'sentry')
        eq_(msg['severity'], SEVERITY.ERROR)
        eq_(msg['fields']['dsn'], self.dsn)
    def test_raven_method(self):
        def exception_call2(a, b, c):
            return a + b + c / (a - b)

        def exception_call1(x, y):
            return exception_call2(y, x, 42)

        try:
            exception_call1(5, 5)
        except:
            self.client.raven('some message')

        eq_(1, len(self.client.sender.msgs))

        msg = json.loads(self.client.sender.msgs[0])

        rc = RavenClient()
        sentry_fields = rc.decode(msg['payload'])
        eq_(sentry_fields['culprit'], 'test_metlog in exception_call2')
        eq_(len(sentry_fields['sentry.interfaces.Stacktrace']['frames']), 3)
        eq_(sentry_fields['extra']['msg'], 'some message')

        eq_(msg['logger'], '')
        eq_(msg['fields']['msg'], 'some message')
        eq_(msg['type'], 'sentry')
        eq_(msg['severity'], SEVERITY.ERROR)
        eq_(msg['fields']['dsn'], self.dsn)
    def test_capture_stack(self):

        ###
        def exception_call2(a, b, c):
            return a + b + c / (a - b)

        @capture_stack
        def exception_call1(x, y):
            return exception_call2(y, x, 42)
        ###

        msgs = []
        try:
            exception_call1(5, 5)
        except:
            msgs = [json.loads(m) for m in self.client.sender.msgs]

        # There should be 1 exception
        eq_(len(msgs), 1)

        # We should have a culprit of exception_call2
        event = msgs[0]

        rc = RavenClient()
        sentry_fields = rc.decode(event['payload'])

        eq_(sentry_fields['culprit'],
            'test_metlog in exception_call2')

        frames = sentry_fields['sentry.interfaces.Stacktrace']['frames']
        culprit_frame = [f for f in frames \
                            if f['function'] == 'exception_call2'][0]
        # Check for the variables that cause the divide by zero
        eq_(culprit_frame['vars']['a'],
            culprit_frame['vars']['b'],
            5)

        eq_(event['severity'], SEVERITY.ERROR)
Esempio n. 4
0
def test_plugins_config():
    cfg_txt = """
    [metlog]
    sender_class = metlog.senders.DebugCaptureSender

    [metlog_plugin_raven]
    provider=metlog_raven.raven_plugin:config_plugin
    """
    from metlog.config import client_from_text_config
    import json

    client = client_from_text_config(cfg_txt, 'metlog')

    def exception_call2(a, b, c):
        return a + b + c / (a - b)

    def exception_call1(x, y):
        return exception_call2(y, x, 42)

    try:
        exception_call1(5, 5)
    except:
        client.raven('some message')

    eq_(1, len(client.sender.msgs))

    msg = json.loads(client.sender.msgs[0])

    rc = RavenClient()
    sentry_fields = rc.decode(msg['payload'])
    eq_(sentry_fields['culprit'], 'test_metlog.exception_call2')
    eq_(len(sentry_fields['sentry.interfaces.Stacktrace']['frames']), 3)
    eq_(sentry_fields['extra']['msg'], 'some message')

    eq_(msg['logger'], '')
    eq_(msg['fields']['msg'], 'some message')
    eq_(msg['type'], 'sentry')
    eq_(msg['severity'], SEVERITY.ERROR)
    def test_capture_stack(self):

        ###
        def exception_call2(a, b, c):
            return a + b + c / (a - b)

        @capture_stack
        def exception_call1(x, y):
            return exception_call2(y, x, 42)

        ###

        msgs = []
        try:
            exception_call1(5, 5)
        except:
            msgs = [json.loads(m) for m in self.client.sender.msgs]

        # There should be 1 exception
        eq_(len(msgs), 1)

        # We should have a culprit of exception_call2
        event = msgs[0]

        rc = RavenClient()
        sentry_fields = rc.decode(event['payload'])

        eq_(sentry_fields['culprit'], 'test_metlog in exception_call2')

        frames = sentry_fields['sentry.interfaces.Stacktrace']['frames']
        culprit_frame = [f for f in frames \
                            if f['function'] == 'exception_call2'][0]
        # Check for the variables that cause the divide by zero
        eq_(culprit_frame['vars']['a'], culprit_frame['vars']['b'], 5)

        eq_(event['severity'], SEVERITY.ERROR)