How to use the bugsnag.notification.Notification function in bugsnag

To help you get started, we’ve selected a few bugsnag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bugsnag / bugsnag-python / tests / test_path_encoding.py View on Github external
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()
        notification = Notification(
            Exception("oops"),
            config,
            RequestConfiguration.get_instance()
        )

        bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(
            notification
        )

        self.assertEqual(
            'http://localhost/hello/world',
            notification.meta_data['request']['url']
        )
github bugsnag / bugsnag-python / tests / test_sessiontracker.py View on Github external
def test_session_tracker_sets_details_from_config(self):
        client = Client(
            auto_capture_sessions=True,
            session_endpoint=self.server.url,
            asynchronous=False
        )
        client.session_tracker.start_session()
        client.session_tracker.send_sessions()
        json_body = self.server.received[0]['json_body']
        # Notifier properties
        notifier = json_body['notifier']
        self.assertTrue('name' in notifier)
        self.assertEqual(notifier['name'], Notification.NOTIFIER_NAME)
        self.assertTrue('url' in notifier)
        self.assertEqual(notifier['url'], Notification.NOTIFIER_URL)
        self.assertTrue('version' in notifier)
        notifier_version = package_version('bugsnag') or 'unknown'
        self.assertEqual(notifier['version'], notifier_version)
        # App properties
        app = json_body['app']
        self.assertTrue('releaseStage' in app)
        self.assertEqual(app['releaseStage'],
                         client.configuration.get('release_stage'))
        self.assertTrue('version' in app)
        self.assertEqual(app['version'],
                         client.configuration.get('app_version'))
        # Device properties
        device = json_body['device']
        self.assertTrue('hostname' in device)
github bugsnag / bugsnag-python / tests / test_notification.py View on Github external
def test_code_at_start_of_file(self):

        config = Configuration()
        notification = Notification(fixtures.start_of_file[1], config, {},
                                    traceback=fixtures.start_of_file[2])

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual(
            {'1': '# flake8: noqa',
             '2': 'try:',
             '3': '    import sys; raise Exception("start")',
             '4': 'except Exception: start_of_file = sys.exc_info()',
             '5': '# 4',
             '6': '# 5',
             '7': '# 6'}, code)
github bugsnag / bugsnag-python / tests / test_notification.py View on Github external
def test_device_data(self):
        """
            It should include device data
        """
        config = Configuration()
        config.hostname = 'test_host_name'
        config.runtime_versions = {'python': '9.9.9'}
        notification = Notification(Exception("oops"), config, {})

        payload = json.loads(notification._payload())

        device = payload['events'][0]['device']
        self.assertEqual('test_host_name', device['hostname'])
        self.assertEqual('9.9.9', device['runtimeVersions']['python'])
github bugsnag / bugsnag-python / tests / test_notification.py View on Github external
def test_code(self):
        """
            It should include code
        """
        config = Configuration()
        line = inspect.currentframe().f_lineno + 1
        notification = Notification(Exception("oops"), config, {})

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        lvl = "        "
        self.assertEqual(code[str(line - 3)], lvl + "\"\"\"")
        self.assertEqual(code[str(line - 2)], lvl + "config = Configuration()")
        self.assertEqual(code[str(line - 1)],
                         lvl + "line = inspect.currentframe().f_lineno + 1")
        self.assertEqual(
            code[str(line)],
            lvl +
            "notification = Notification(Exception(\"oops\"), config, {})"
            )
        self.assertEqual(code[str(line + 1)], "")
        self.assertEqual(code[str(line + 2)],
github bugsnag / bugsnag-python / tests / test_notification.py View on Github external
def test_sanitize(self):
        """
            It should sanitize request data
        """
        config = Configuration()
        notification = Notification(Exception("oops"), config, {},
                                    request={"params": {"password": "secret"}})

        notification.add_tab("request", {"arguments": {"password": "secret"}})

        payload = json.loads(notification._payload())
        request = payload['events'][0]['metaData']['request']
        self.assertEqual(request['arguments']['password'], '[FILTERED]')
        self.assertEqual(request['params']['password'], '[FILTERED]')
github bugsnag / bugsnag-python / bugsnag / sessiontracker.py View on Github external
return

        if not self.config.api_key:
            bugsnag.logger.debug("Not delivering due to an invalid api_key")
            return

        if not self.config.should_notify:
            bugsnag.logger.debug("Not delivering due to release_stages")
            return

        notifier_version = package_version('bugsnag') or 'unknown'

        payload = {
            'notifier': {
                'name': Notification.NOTIFIER_NAME,
                'url': Notification.NOTIFIER_URL,
                'version': notifier_version
            },
            'device': FilterDict({
                'hostname': self.config.get('hostname'),
                'runtimeVersions': self.config.get('runtime_versions')
            }),
            'app': {
                'releaseStage': self.config.get('release_stage'),
                'version': self.config.get('app_version')
            },
            'sessionCounts': sessions
        }

        try:
            filters = self.config.params_filters
            encoder = SanitizingJSONEncoder(separators=(',', ':'),
github bugsnag / bugsnag-python / bugsnag / client.py View on Github external
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)
github bugsnag / bugsnag-python / bugsnag / client.py View on Github external
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)