From 856fe445b0b85c70ddbd41339174da8b3473c9ee Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 11 Dec 2020 16:26:03 -0500 Subject: [PATCH] Added user.uid to ApiError and Sentry logging --- crc/api/common.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crc/api/common.py b/crc/api/common.py index e2b13b9a..78cbc018 100644 --- a/crc/api/common.py +++ b/crc/api/common.py @@ -4,6 +4,8 @@ from flask import g from crc import ma, app +import sentry_sdk + class ApiError(Exception): def __init__(self, code, message, status_code=400, @@ -16,6 +18,13 @@ class ApiError(Exception): self.file_name = file_name or "" # OPTIONAL: The file that caused the error. self.tag = tag or "" # OPTIONAL: The XML Tag that caused the issue. self.task_data = task_data or "" # OPTIONAL: A snapshot of data connected to the task when error ocurred. + if hasattr(g,'user'): + user = g.user.uid + else: + user = 'Unknown' + self.task_user = user + # This is for sentry logging into Slack + sentry_sdk.set_context("User", {'user': user}) Exception.__init__(self, self.message) @classmethod @@ -59,7 +68,7 @@ class ApiError(Exception): class ApiErrorSchema(ma.Schema): class Meta: fields = ("code", "message", "workflow_name", "file_name", "task_name", "task_id", - "task_data") + "task_data", "task_user") @app.errorhandler(ApiError)