How to use bugsnag - 10 common examples

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 Axtell / Axtell / app / notifications / webpush.py View on Github external
# then we'll report the error
    if r.status_code == 410:
        # Code of 410 means the user has unsubscribed from notifs. This means we
        # must remove the device
        PushDevice.query.\
            filter_by(endpoint=endpoint).\
            delete()

        db.session.commit()
    elif r.status_code // 100 != 2:
        try:
            rejection_response = r.text
        except:
            rejection_response = 'Error reading rejection response'

        if bugsnag.configuration.api_key is not None:
            bugsnag.notify(
                Exception("Web Push dispatch error"),
                meta_data={
                    'webpush_request': {
                        'endpoint': f'{endpoint_url.scheme}://{endpoint_url.netloc}',
                        'status_code': r.status_code
                    },
                    'webpush_response': {
                        'response': rejection_response
                    }
                }
            )

        server.logger.error(f'Notification (Web Push) rejected {notification.uuid} -> {endpoint_url.netloc}:\n{rejection_response}')
github bugsnag / bugsnag-python / tests / integrations / test_flask.py View on Github external
def test_flask_intergration_includes_middleware_severity(self):
        app = Flask("bugsnag")

        @app.route("/test")
        def test():
            raise SentinelError("oops")

        handle_exceptions(app)
        app.test_client().get("/test")

        self.assertEqual(1, len(self.server.received))
        payload = self.server.received[0]['json_body']
        event = payload['events'][0]
        self.assertTrue(event['unhandled'])
        self.assertEqual(event['severityReason'], {
            "type": "unhandledExceptionMiddleware",
            "attributes": {
                "framework": "Flask"
            }
github bugsnag / bugsnag-python / tests / test_handlers.py View on Github external
def setUp(self):
        super(HandlersTest, self).setUp()
        bugsnag.configure(use_ssl=False,
                          endpoint=self.server.address,
                          api_key='tomatoes',
                          notify_release_stages=['dev'],
                          release_stage='dev',
                          asynchronous=False)
        bugsnag.logger.setLevel(logging.INFO)
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_notify_configured_api_key(self):
        bugsnag.notify(ScaryException('unexpected failover'))
        headers = self.server.received[0]['headers']
        self.assertEqual('tomatoes', headers['Bugsnag-Api-Key'])
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_notify_recursive_metadata_array(self):
        a = ['foo', 'bar']
        a.append(a)
        bugsnag.add_metadata_tab('a', {'b': a})
        bugsnag.notify(ScaryException('unexpected failover'))
        json_body = self.server.received[0]['json_body']
        event = json_body['events'][0]
        self.assertEqual(['foo', 'bar', '[RECURSIVE]'],
                         event['metaData']['a']['b'])
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_notify_override_metadata_sections(self):
        bugsnag.add_metadata_tab('food', {'beans': 3, 'corn': 'purple'})
        bugsnag.notify(ScaryException('unexpected failover'),
                       meta_data={'food': {'beans': 5},
                                  'skills': {'spear': 6}})
        json_body = self.server.received[0]['json_body']
        event = json_body['events'][0]
        self.assertEqual(6, event['metaData']['skills']['spear'])
        self.assertEqual('purple', event['metaData']['food']['corn'])
        self.assertEqual(5, event['metaData']['food']['beans'])
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_notify_device_filter(self):
        bugsnag.configure(params_filters=['hostname'])
        bugsnag.notify(ScaryException('unexpected failover'))
        json_body = self.server.received[0]['json_body']
        event = json_body['events'][0]
        self.assertEqual('[FILTERED]', event['device']['hostname'])
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_notify_recursive_metadata_dict(self):
        a = {'foo': 'bar'}
        a['baz'] = a
        bugsnag.add_metadata_tab('a', a)
        bugsnag.notify(ScaryException('unexpected failover'))
        json_body = self.server.received[0]['json_body']
        event = json_body['events'][0]
        self.assertEqual('bar', event['metaData']['a']['foo'])
        self.assertEqual('[RECURSIVE]', event['metaData']['a']['baz']['baz'])
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_middleware_stack_order_legacy(self):
        def first_callback(notification):
            notification.meta_data['test']['array'].append(1)

        def second_callback(notification):
            notification.meta_data['test']['array'].append(2)

        # Add a regular callback function
        bugsnag.before_notify(second_callback)

        # Simulate an internal middleware
        bugsnag.legacy.configuration.internal_middleware.before_notify(
                first_callback)

        bugsnag.notify(ScaryException('unexpected failover'),
                       test={'array': []})
        json_body = self.server.received[0]['json_body']
        event = json_body['events'][0]

        self.assertEqual(event['metaData']['test']['array'], [1, 2])
github bugsnag / bugsnag-python / tests / test_notify.py View on Github external
def test_notify_override_user(self):
        bugsnag.notify(ScaryException('unexpected failover'),
                       user={'name': 'bob',
                             'email': 'mcbob@example.com',
                             'id': '542347329'})
        json_body = self.server.received[0]['json_body']
        event = json_body['events'][0]
        self.assertEqual('bob', event['user']['name'])
        self.assertEqual('542347329', event['user']['id'])
        self.assertEqual('mcbob@example.com', event['user']['email'])