Ejemplo n.º 1
0
def handle_exception(exc_type, exc_value, exc_traceback):
    cl = raygunprovider.RaygunSender("paste_your_api_key_here")
    cl.set_version("1.3")
    cl.set_user({
        'identifier': 'example@email_or_user_id.com',
        'firstName': 'John',
        'fullName': 'John Smith',
        'email': 'example@email_or_user_id.com'
    })

    # If we're handling a request in a web server environment, we can send the HTTP request data
    headers = {
        "referer": "localhost",
        "user-Agent": "Mozilla"
    }

    request = {
        "headers": headers,
        "hostName": "localhost",
        "url": "/resource",
        "httpMethod": "GET",
        "ipAddress": "127.0.0.1",
        "queryString": None,
        "form": None,
        "rawData": None,
    }

    print(cl.send_exception(exc_info=(exc_type, exc_value, exc_traceback), "myclass", ["tag1", "tag2"], {"key1": 1111, "key2": 2222}, request))
Ejemplo n.º 2
0
    def __init__(self, get_response=None):
        self.get_response = get_response
        config = getattr(settings, 'RAYGUN4PY_CONFIG', {})
        apiKey = getattr(settings, 'RAYGUN4PY_API_KEY',
                         config.get('api_key', None))

        self.sender = raygunprovider.RaygunSender(apiKey, config=config)
Ejemplo n.º 3
0
    def create_dummy_message(self):
        self.sender = raygunprovider.RaygunSender('apikey')

        msg = raygunmsgs.RaygunMessageBuilder({}).new()
        errorMessage = raygunmsgs.RaygunErrorMessage(Exception, None, None, {})
        msg.set_exception_details(errorMessage)
        return msg.build()
Ejemplo n.º 4
0
def handle_exception(exc_type, exc_value, exc_traceback):
    cl = raygunprovider.RaygunSender(getenv("RAYGUN_TOKEN"))
    cl.send_exception(exc_info=(exc_type, exc_value, exc_traceback))
    if issubclass(exc_type, KeyboardInterrupt):
        sys.__excepthook__(exc_type, exc_value, exc_traceback)
        return

    logging.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
Ejemplo n.º 5
0
    def test_send_exception_with_exc_info(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise StandardError("Raygun4py manual sending test")
        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            httpResult = client.send_exception(exc_info=sys.exc_info())
Ejemplo n.º 6
0
    def test_sending_auto(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py3 exception (auto)")
        except Exception as e:
            httpResult = client.send_exception()

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 7
0
    def test_sending_exception(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py3 manual sending test")
        except Exception as e:
            httpResult = client.send_exception(exception=e)

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 8
0
    def test_python3_new_sending(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py3 Python3 send")
        except Exception as e:
            httpResult = client.send_exception(e)

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 9
0
def send_exception(exception, exc_info=None):
    """
    Function sends exception to selected provider.
    """
    if settings.RAYGUN4PY_API_KEY:
        provider = raygunprovider.RaygunSender(settings.RAYGUN4PY_API_KEY)
        provider.send_exception(exception, exc_info=exc_info)
    else:
        log.error(exception, exc_info=exc_info)
Ejemplo n.º 10
0
    def test_http_request(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py functional test - on_before_send")
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 11
0
    def test_send_exception_no_args(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py functional test - Py2 send_exception")
        except:
            httpResult = client.send_exception()

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 12
0
    def test_utf8_message(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("ΔΔΔΔ")
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 13
0
    def test_localvariables_multilevels(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            scope = 'parent'
            child()
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 14
0
    def test_localvariables(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            foo = 'bar'
            raise Exception("Raygun4py functional test - local variables")
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 15
0
    def test_sending(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise StandardError("Raygun4py manual sending test")
        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            httpResult = client.send(exc_type, exc_value, exc_traceback)

            self.assertEquals(httpResult[0], 202)
Ejemplo n.º 16
0
    def test_before_send_callback(self):
        client = raygunprovider.RaygunSender(self.apiKey)
        client.on_before_send(before_send_mutate_payload)

        try:
            raise Exception("Raygun4py functional test - on_before_send")
        except Exception as e:
            httpResult = client.send_exception(e, exc_info=sys.exc_info())

        self.assertEqual(httpResult[0], 202)
Ejemplo n.º 17
0
    def test_proxy(self):
        client = raygunprovider.RaygunSender(self.apiKey)
        client.set_proxy('127.0.0.1', 3128)

        try:
            raise Exception("Raygun4py functional test - Py2 set_proxy")
        except Exception as e:
            httpResult = client.send_exception(e, exc_info=sys.exc_info())

        self.assertEqual(httpResult[0], 202)
Ejemplo n.º 18
0
    def test_filter_keys_202(self):
        client = raygunprovider.RaygunSender(self.apiKey)
        client.filter_keys(['environment'])

        try:
            raise Exception("Raygun4py functional test - Py2 filter_keys")
        except Exception as e:
            httpResult = client.send_exception(e, exc_info=sys.exc_info())

        self.assertEqual(httpResult[0], 202)
Ejemplo n.º 19
0
    def test_ignore_exception(self):
        client = raygunprovider.RaygunSender(self.apiKey)
        client.ignore_exceptions(['CustomException'])

        try:
            raise CustomException("This test should not send an exception")
        except CustomException as e:
            httpResult = client.send_exception(e)

            self.assertEqual(httpResult, None)
Ejemplo n.º 20
0
    def test_before_send_callback_sets_none_cancels_send(self):
        client = raygunprovider.RaygunSender(self.apiKey)
        client.on_before_send(before_send_cancel_send)

        try:
            raise Exception("Raygun4py functional test - on_before_send")
        except Exception as e:
            result = client.send_exception(e, exc_info=sys.exc_info())

        self.assertIsNone(result)
Ejemplo n.º 21
0
    def test_send_exception_with_exc_info(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception(
                "Raygun4py functional test - Py2 send_exception with exc_info")
        except Exception as e:
            httpResult = client.send_exception(e, exc_info=sys.exc_info())

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 22
0
def send_exception(exception, exc_info=None):
    """
    Function sends exception to selected provider.
    """
    api_key = settings.RAYGUN4PY_CONFIG['api_key']
    if api_key:
        provider = raygunprovider.RaygunSender(api_key)
        provider.send_exception(exception, exc_info=exc_info)
    else:
        log.error(exception, exc_info=exc_info)
Ejemplo n.º 23
0
    def test_send_with_tags(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py manual sending test - tags")
        except:
            httpResult = client.send_exception(exc_info=sys.exc_info(),
                                               tags=["I am a tag"])

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 24
0
    def test_sending_exc_info(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise Exception("Raygun4py3 manual sending test")
        except:
            exc_info = sys.exc_info()
            httpResult = client.send_exception(exc_info=exc_info)

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 25
0
    def test_send_with_version(self):
        client = raygunprovider.RaygunSender(self.apiKey)
        client.set_version('v1.0.0')

        try:
            raise Exception("Raygun4py manual sending test - version")
        except:
            httpResult = client.send_exception(exc_info=sys.exc_info())

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 26
0
    def test_send_exception_subclass(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            raise CustomException(
                "Raygun4py functional test - Py2 send_exception with custom exception"
            )
        except CustomException as e:
            httpResult = client.send_exception(e)

            self.assertEqual(httpResult[0], 202)
Ejemplo n.º 27
0
    def test_localvariables_unicode(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        try:
            sigma = u'\u2211'
            raise Exception(
                "Raygun4py functional test - local variable - unicode")
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 28
0
    def test_bytestring_localvariable(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        byte_string = b'\x8d\x80\x92uK!M\xed'

        try:
            raise Exception("Raygun4py2: bytestring local variable")
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 29
0
    def test_utf8_localvariable(self):
        client = raygunprovider.RaygunSender(self.apiKey)

        the_variable = 'ᵫ'

        try:
            raise Exception("Raygun4py2: utf8 local variable")
        except Exception as e:
            result = client.send_exception(httpRequest={})

            self.assertEqual(result[0], 202)
Ejemplo n.º 30
0
async def bug_report(ctx, *, issue):
    """Allows users to file a bug report straight through John.
    This will raise a new raygun issue and can be dealt with that way. """
    client = raygunprovider.RaygunSender(raygun_key)
    httpResult = client.send_exception(
        exception=BugReport(message=issue, context=ctx))
    if 200 <= httpResult[0] <= 299:
        await ctx.send("Report filed, thank you!")
    else:
        await ctx.send(
            "Hmm, that didn't work. If the bug report failed, something is probaly very wrong, please @ a staff member!"
        )