Reporting to Sentry all captured exceptions and enabling multiple environments

This commit is contained in:
Carlos Lopez 2020-07-19 16:40:33 -06:00
parent e82532aad8
commit fcb772c900
5 changed files with 8 additions and 4 deletions

View File

@ -15,7 +15,8 @@ TEST_UID = environ.get('TEST_UID', default="dhf8r")
ADMIN_UIDS = re.split(r',\s*', environ.get('ADMIN_UIDS', default="dhf8r,ajl2j,cah3us,cl3wf")) ADMIN_UIDS = re.split(r',\s*', environ.get('ADMIN_UIDS', default="dhf8r,ajl2j,cah3us,cl3wf"))
# Sentry flag # Sentry flag
ENABLE_SENTRY = environ.get('ENABLE_SENTRY', default="false") == "true" ENABLE_SENTRY = environ.get('ENABLE_SENTRY', default="false") == "true" # To be removed soon
SENTRY_ENVIRONMENT = environ.get('SENTRY_ENVIRONMENT', None)
# Add trailing slash to base path # Add trailing slash to base path
APPLICATION_ROOT = re.sub(r'//', '/', '/%s/' % environ.get('APPLICATION_ROOT', default="/").strip('/')) APPLICATION_ROOT = re.sub(r'//', '/', '/%s/' % environ.get('APPLICATION_ROOT', default="/").strip('/'))

View File

@ -52,8 +52,9 @@ origins_re = [r"^https?:\/\/%s(.*)" % o.replace('.', '\.') for o in app.config['
cors = CORS(connexion_app.app, origins=origins_re) cors = CORS(connexion_app.app, origins=origins_re)
# Sentry error handling # Sentry error handling
if app.config['ENABLE_SENTRY']: if app.config['SENTRY_ENVIRONMENT']:
sentry_sdk.init( sentry_sdk.init(
environment=app.config['SENTRY_ENVIRONMENT'],
dsn="https://25342ca4e2d443c6a5c49707d68e9f40@o401361.ingest.sentry.io/5260915", dsn="https://25342ca4e2d443c6a5c49707d68e9f40@o401361.ingest.sentry.io/5260915",
integrations=[FlaskIntegration()] integrations=[FlaskIntegration()]
) )

View File

@ -25,6 +25,7 @@ class ApiError(Exception):
instance.task_name = task.task_spec.description or "" instance.task_name = task.task_spec.description or ""
instance.file_name = task.workflow.spec.file or "" instance.file_name = task.workflow.spec.file or ""
instance.task_data = task.data instance.task_data = task.data
app.logger.error(message, exc_info=True)
return instance return instance
@classmethod @classmethod
@ -35,6 +36,7 @@ class ApiError(Exception):
instance.task_name = task_spec.description or "" instance.task_name = task_spec.description or ""
if task_spec._wf_spec: if task_spec._wf_spec:
instance.file_name = task_spec._wf_spec.file instance.file_name = task_spec._wf_spec.file
app.logger.error(message, exc_info=True)
return instance return instance
@classmethod @classmethod

View File

@ -376,7 +376,7 @@ class WorkflowService(object):
try: try:
task.title = spiff_task.workflow.script_engine.evaluate_expression(spiff_task, task.properties['display_name']) task.title = spiff_task.workflow.script_engine.evaluate_expression(spiff_task, task.properties['display_name'])
except Exception as e: except Exception as e:
app.logger.info("Failed to set title on task due to type error." + str(e)) app.logger.error("Failed to set title on task due to type error." + str(e), exc_info=True)
elif task.title and ' ' in task.title: elif task.title and ' ' in task.title:
task.title = task.title.partition(' ')[2] task.title = task.title.partition(' ')[2]
return task return task

View File

@ -136,4 +136,4 @@ class TestWorkflowService(BaseTest):
def test_dmn_evaluation_errors_in_oncomplete_raise_api_errors_during_validation(self): def test_dmn_evaluation_errors_in_oncomplete_raise_api_errors_during_validation(self):
workflow_spec_model = self.load_test_spec("decision_table_invalid") workflow_spec_model = self.load_test_spec("decision_table_invalid")
with self.assertRaises(ApiError): with self.assertRaises(ApiError):
WorkflowService.test_spec(workflow_spec_model.id) WorkflowService.test_spec(workflow_spec_model.id)