def notify(exception, **options):
    """
    Notify bugsnag of an exception.
    """
    try:
        if isinstance(exception, (list, tuple)):
            # Exception tuples, eg. from sys.exc_info
            if "traceback" not in options:
                options["traceback"] = exception[2]

            Notification(exception[1], configuration,
                         RequestConfiguration.get_instance(),
                         **options).deliver()
        else:
            # Exception objects
            Notification(exception, configuration,
                         RequestConfiguration.get_instance(),
                         **options).deliver()
    except Exception:
        try:
            log("Notification failed")
            print((traceback.format_exc()))
        except Exception:
            print(("[BUGSNAG] error in exception handler"))
            print((traceback.format_exc()))
示例#2
0
def notify(exception, **options):
    """
    Notify bugsnag of an exception.
    """
    if isinstance(exception, (list, tuple)):
        # Exception tuples, eg. from sys.exc_info
        if not "traceback" in options:
            options["traceback"] = exception[2]

        Notification(exception[1], configuration,
                     RequestConfiguration.get_instance(), **options).deliver()
    else:
        # Exception objects
        Notification(exception, configuration,
                     RequestConfiguration.get_instance(), **options).deliver()
示例#3
0
    def notify(self, exception: BaseException, asynchronous=None, **options):
        """
        Notify bugsnag of an exception.

        >>> client.notify(Exception('Example'))  # doctest: +SKIP
        """

        event = Event(exception, self.configuration,
                      RequestConfiguration.get_instance(), **options)
        self.deliver(event, asynchronous=asynchronous)
示例#4
0
def add_metadata_tab(tab_name, data):
    """
    Add metaData to the tab

    bugsnag.add_metadata_tab("user", {"id": "1", "name": "Conrad"})
    """
    meta_data = RequestConfiguration.get_instance().meta_data
    if tab_name not in meta_data:
        meta_data[tab_name] = {}

    meta_data[tab_name].update(data)
示例#5
0
def add_metadata_tab(tab_name, data):
    """
    Add metaData to the tab

    bugsnag.add_metadata_tab("user", {"id": "1", "name": "Conrad"})
    """
    meta_data = RequestConfiguration.get_instance().meta_data
    if tab_name not in meta_data:
        meta_data[tab_name] = {}

    meta_data[tab_name].update(data)
示例#6
0
    def notify(self, exception, asynchronous=None, **options):
        """
        Notify bugsnag of an exception.

        >>> client.notify(Exception('Example'))
        """

        notification = Notification(exception, self.configuration,
                                    RequestConfiguration.get_instance(),
                                    **options)
        self.deliver(notification, asynchronous=asynchronous)
示例#7
0
    def notify(self, exception, **options):
        """
        Notify bugsnag of an exception.

        >>> client.notify(Exception('Example'))
        """

        notification = Notification(exception, self.configuration,
                                    RequestConfiguration.get_instance(),
                                    **options)
        self.deliver(notification)
示例#8
0
    async def test_async_task_metadata(self):
        bugsnag.configure_request(wins={'total': 3, 'last': 2})

        async def coro():
            bugsnag.configure_request(wins={'total': 1, 'last': 1})

        asyncio.ensure_future(coro())
        data = RequestConfiguration.get_instance().wins

        assert data['total'] == 3
        assert data['last'] == 2
示例#9
0
    def notify_exc_info(self, exc_type, exc_value, traceback,
                        asynchronous=None, **options):
        """
        Notify bugsnag of an exception via exc_info.

        >>> client.notify_exc_info(*sys.exc_info())  # doctest: +SKIP
        """

        exception = exc_value
        options['traceback'] = traceback
        event = Event(exception, self.configuration,
                      RequestConfiguration.get_instance(), **options)
        self.deliver(event, asynchronous=asynchronous)
示例#10
0
    def notify_exc_info(self, exc_type, exc_value, traceback, **options):
        """
        Notify bugsnag of an exception via exc_info.

        >>> client.notify_exc_info(*sys.exc_info())
        """

        exception = exc_value
        options['traceback'] = traceback
        notification = Notification(exception, self.configuration,
                                    RequestConfiguration.get_instance(),
                                    **options)
        self.deliver(notification)
示例#11
0
    def notify_exc_info(self, exc_type, exc_value, traceback, **options):
        """
        Notify bugsnag of an exception via exc_info.

        >>> client.notify_exc_info(*sys.exc_info())
        """

        exception = exc_value
        options['traceback'] = traceback
        notification = Notification(exception, self.configuration,
                                    RequestConfiguration.get_instance(),
                                    **options)
        self.deliver(notification)
示例#12
0
def notify(exception, **options):
    """
    Notify bugsnag of an exception.
    """
    try:
        if isinstance(exception, (list, tuple)):
            # Exception tuples, eg. from sys.exc_info
            if not "traceback" in options:
                options["traceback"] = exception[2]

            Notification(exception[1], configuration,
                        RequestConfiguration.get_instance(), **options).deliver()
        else:
            # Exception objects
            Notification(exception, configuration,
                        RequestConfiguration.get_instance(), **options).deliver()
    except Exception:
        try:
            log("Notification failed")
            print((traceback.format_exc()))
        except Exception:
            print(("[BUGSNAG] error in exception handler"))
            print((traceback.format_exc()))
    def test_path_supports_ascii_characters(self):
        import bugsnag.wsgi.middleware

        environ = self.environ.copy()
        environ['PATH_INFO'] = '/hello/world'

        bugsnag.configure_request(wsgi_environ=environ)

        config = Configuration()
        event = Event(Exception("oops"), config,
                      RequestConfiguration.get_instance())

        bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(event)

        self.assertEqual('http://localhost/hello/world',
                         event.metadata['request']['url'])
    def test_path_supports_non_ascii_characters(self):
        import bugsnag.wsgi.middleware

        environ = self.environ.copy()
        environ['PATH_INFO'] = '/ôßłガ'

        config = Configuration()
        event = Event(Exception("oops"), config,
                      RequestConfiguration.get_instance())

        bugsnag.configure_request(wsgi_environ=environ)

        bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(event)

        # You can validate this by using "encodeURIComponent" in a browser.
        self.assertEqual('http://localhost/%C3%B4%C3%9F%C5%82%E3%82%AC',
                         event.metadata['request']['url'])
    def test_path_supports_emoji(self):
        import bugsnag.wsgi.middleware

        environ = self.environ.copy()
        environ['PATH_INFO'] = '/😇'

        config = Configuration()
        notification = Notification(Exception("oops"), config,
                                    RequestConfiguration.get_instance())

        bugsnag.configure_request(wsgi_environ=environ)

        bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(
            notification)

        # You can validate this by using "encodeURIComponent" in a browser.
        self.assertEqual('http://localhost/%F0%9F%98%87',
                         notification.meta_data['request']['url'])
    def test_wrongly_encoded_url_should_not_raise(self):
        import bugsnag.wsgi.middleware

        environ = self.environ.copy()
        environ['PATH_INFO'] = '/%83'

        bugsnag.configure_request(wsgi_environ=environ)

        config = Configuration()
        event = Event(Exception("oops"), config,
                      RequestConfiguration.get_instance())

        bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(event)

        # We have to use "urllib.parse.quote" here because the exact output
        # differs on different Python versions because of how they handle
        # invalid encoding sequences
        self.assertEqual('http://localhost/%s' % quote('%83'),
                         event.metadata['request']['url'])
示例#17
0
def configure_request(**options):
    """
    Configure the Bugsnag notifier per-request settings.
    """
    RequestConfiguration.get_instance().configure(**options)
示例#18
0
def configure_request(**options):
    """
    Configure the Bugsnag notifier per-request settings.
    """
    RequestConfiguration.get_instance().configure(**options)
示例#19
0
 async def slow_crash():
     bugsnag.configure_request(local_data={'apples': 1})
     await asyncio.sleep(1)
     data = RequestConfiguration.get_instance().local_data
     assert data['apples'] == 1