From fcb772c90022ff79336d4fc43ef290e19406b2ca Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Sun, 19 Jul 2020 16:40:33 -0600 Subject: [PATCH] Reporting to Sentry all captured exceptions and enabling multiple environments --- config/default.py | 3 ++- crc/__init__.py | 3 ++- crc/api/common.py | 2 ++ crc/services/workflow_service.py | 2 +- tests/workflow/test_workflow_service.py | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config/default.py b/config/default.py index 5c8f8c51..b295bf4b 100644 --- a/config/default.py +++ b/config/default.py @@ -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")) # 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 APPLICATION_ROOT = re.sub(r'//', '/', '/%s/' % environ.get('APPLICATION_ROOT', default="/").strip('/')) diff --git a/crc/__init__.py b/crc/__init__.py index d56085d0..c3fff567 100644 --- a/crc/__init__.py +++ b/crc/__init__.py @@ -52,8 +52,9 @@ origins_re = [r"^https?:\/\/%s(.*)" % o.replace('.', '\.') for o in app.config[' cors = CORS(connexion_app.app, origins=origins_re) # Sentry error handling -if app.config['ENABLE_SENTRY']: +if app.config['SENTRY_ENVIRONMENT']: sentry_sdk.init( + environment=app.config['SENTRY_ENVIRONMENT'], dsn="https://25342ca4e2d443c6a5c49707d68e9f40@o401361.ingest.sentry.io/5260915", integrations=[FlaskIntegration()] ) diff --git a/crc/api/common.py b/crc/api/common.py index f8673a5b..cb527c73 100644 --- a/crc/api/common.py +++ b/crc/api/common.py @@ -25,6 +25,7 @@ class ApiError(Exception): instance.task_name = task.task_spec.description or "" instance.file_name = task.workflow.spec.file or "" instance.task_data = task.data + app.logger.error(message, exc_info=True) return instance @classmethod @@ -35,6 +36,7 @@ class ApiError(Exception): instance.task_name = task_spec.description or "" if task_spec._wf_spec: instance.file_name = task_spec._wf_spec.file + app.logger.error(message, exc_info=True) return instance @classmethod diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index c481a0a8..a2d31f36 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -376,7 +376,7 @@ class WorkflowService(object): try: task.title = spiff_task.workflow.script_engine.evaluate_expression(spiff_task, task.properties['display_name']) 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: task.title = task.title.partition(' ')[2] return task diff --git a/tests/workflow/test_workflow_service.py b/tests/workflow/test_workflow_service.py index f208eecb..d42601eb 100644 --- a/tests/workflow/test_workflow_service.py +++ b/tests/workflow/test_workflow_service.py @@ -136,4 +136,4 @@ class TestWorkflowService(BaseTest): def test_dmn_evaluation_errors_in_oncomplete_raise_api_errors_during_validation(self): workflow_spec_model = self.load_test_spec("decision_table_invalid") with self.assertRaises(ApiError): - WorkflowService.test_spec(workflow_spec_model.id) \ No newline at end of file + WorkflowService.test_spec(workflow_spec_model.id)