def _configure_error_handler(): handler = None if BUGSNAG_API_KEY: client = bugsnag.Client(api_key=BUGSNAG_API_KEY) handler = client.log_handler() handler.setLevel(logging.ERROR) if SENTRY_DSN: handler = SentryHandler(SENTRY_DSN) handler.setLevel(logging.ERROR) return handler
def test_internal_middleware_can_change_severity_reason(self): client = bugsnag.Client(endpoint=self.server.url, api_key='tomatoes', notify_release_stages=['dev'], release_stage='dev', asynchronous=False) def severity_reason_callback(event): event.severity_reason['type'] = 'testReason' internal_middleware = client.configuration.internal_middleware internal_middleware.before_notify(severity_reason_callback) client.notify(ScaryException('unexpected failover')) json_body = self.server.received[0]['json_body'] event = json_body['events'][0] self.assertEqual(event['severityReason']['type'], 'testReason')
def test_internal_middleware_changes_severity(self): client = bugsnag.Client(use_ssl=False, endpoint=self.server.address, api_key='tomatoes', notify_release_stages=['dev'], release_stage='dev', asynchronous=False) def severity_callback(notification): notification.severity = 'info' internal_middleware = client.configuration.internal_middleware internal_middleware.before_notify(severity_callback) client.notify(ScaryException('unexpected failover')) json_body = self.server.received[0]['json_body'] event = json_body['events'][0] self.assertEqual(event['severity'], 'info') self.assertEqual(event['severityReason']['type'], 'handledException')
def test_middleware_stack_order(self): client = bugsnag.Client(endpoint=self.server.url, api_key='tomatoes', notify_release_stages=['dev'], release_stage='dev', asynchronous=False) def first_callback(event): event.metadata['test']['array'].append(1) def second_callback(event): event.metadata['test']['array'].append(2) client.configuration.middleware.before_notify(second_callback) client.configuration.internal_middleware.before_notify(first_callback) client.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])
def tearDown(self): bugsnag.legacy.default_client.uninstall_sys_hook() client = bugsnag.Client() client.configuration.api_key = 'some key' bugsnag.legacy.default_client = client bugsnag.legacy.configuration = client.configuration
def tearDown(self): client = bugsnag.Client() client.configuration.api_key = 'some key' bugsnag.legacy.default_client = client bugsnag.legacy.configuration = client.configuration
api = hug.API(__name__) api.http.add_middleware(hug.middleware.CORSMiddleware( api, allow_origins=['*'], max_age=600)) # since base excuse image is fixed, this values are also constant IMAGE_WIDTH = 413 # Y text coordinates WHO_TEXT_Y = 12 LEGIT_TEXT_Y = 38 WHY_TEXT_Y = 85 WHAT_TEXT_Y = 222 dir_path = os.path.dirname(os.path.realpath(__file__)) bugsnag_client = bugsnag.Client(api_key=os.environ.get('BUGSNAG_KEY')) @bugsnag_client.capture @hug.get( versions=1, examples=[ 'who=programmer&why=my%20code%20is%20compiling&what=compiling', 'who=serverless%20dev&why=my%20function%20is%20uploading&what=uploading', 'who=devops&why=my%20docker%20image%20is%20building&what=docker' ] ) def excuse(request, response, who: hug.types.text='', why: hug.types.text='', what: hug.types.text='') -> dict: """ API view that returns JSON with url to rendered image or errors if there were any.