Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions contentcuration/contentcuration/utils/sentry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from django.conf import settings


def report_exception(exception=None):
def report_exception(exception=None, user=None, contexts=None):
if getattr(settings, "SENTRY_ACTIVE", False):
from sentry_sdk import capture_exception

capture_exception(exception)
scope_args = {
"contexts": contexts
}

if user and not user.is_anonymous:
scope_args["user"] = {
"email": user.email,
}

capture_exception(exception, **scope_args)
10 changes: 5 additions & 5 deletions contentcuration/contentcuration/viewsets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def create_from_changes(self, changes):
change.update({"errors": serializer.errors})
errors.append(change)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, change=change)
change["errors"] = [str(e)]
errors.append(change)

Expand Down Expand Up @@ -693,7 +693,7 @@ def delete_from_changes(self, changes):
# job done!
pass
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, change=change)
change["errors"] = [str(e)]
errors.append(change)
return errors
Expand Down Expand Up @@ -731,7 +731,7 @@ def update_from_changes(self, changes):
change.update({"errors": ValidationError("Not found").detail})
errors.append(change)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, change=change)
change["errors"] = [str(e)]
errors.append(change)
return errors
Expand Down Expand Up @@ -768,7 +768,7 @@ def create_from_changes(self, changes):
try:
self.perform_bulk_create(serializer)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, changes=changes)
for change in changes:
change["errors"] = [str(e)]
errors.extend(changes)
Expand Down Expand Up @@ -807,7 +807,7 @@ def update_from_changes(self, changes):
try:
self.perform_bulk_update(serializer)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, changes=changes)
for change in changes:
change["errors"] = [str(e)]
errors.extend(changes)
Expand Down
4 changes: 2 additions & 2 deletions contentcuration/contentcuration/viewsets/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def publish_from_changes(self, changes):
publish["key"], version_notes=publish.get("version_notes"), language=publish.get("language")
)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, change=publish)
publish["errors"] = [str(e)]
errors.append(publish)
return errors
Expand Down Expand Up @@ -518,7 +518,7 @@ def sync_from_changes(self, changes):
assessment_items=sync.get("assessment_items")
)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=self.request.user, change=sync)
sync["errors"] = [str(e)]
errors.append(sync)
return errors
Expand Down
2 changes: 1 addition & 1 deletion contentcuration/contentcuration/viewsets/sync/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def apply_changes(changes_queryset):
change.applied = True
changed_fields = ("applied",)
except Exception as e:
log_sync_exception(e)
log_sync_exception(e, user=change.created_by, change=change.serialize_to_change_dict())
change.errored = True
change.kwargs["errors"] = [str(e)]
change.save(update_fields=changed_fields)
13 changes: 11 additions & 2 deletions contentcuration/contentcuration/viewsets/sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,19 @@ def generate_publish_event(
return event


def log_sync_exception(e):
def log_sync_exception(e, user=None, change=None, changes=None):
# Capture exception and report, but allow sync
# to complete properly.
report_exception(e)

contexts = {}

if change is not None:
contexts["change"] = change

elif changes is not None:
contexts["changes"] = changes

report_exception(e, user=user, contexts=contexts)

# make sure we leave a record in the logs just in case.
logging.error(e)
72 changes: 31 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1605,57 +1605,47 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@sentry/browser@7.11.1":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.11.1.tgz#377d417e833ef54c78a93ef720a742bda5022625"
integrity sha512-k2XHuzPfnm8VJPK5eWd1+Y5VCgN42sLveb8Qxc3prb5PSL416NWMLZaoB7RMIhy430fKrSFiosnm6QDk2M6pbA==
dependencies:
"@sentry/core" "7.11.1"
"@sentry/types" "7.11.1"
"@sentry/utils" "7.11.1"
"@sentry/browser@7.19.0":
version "7.19.0"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.19.0.tgz#ce21544b843d5c4d5dcb9fe9b7ee31c5c4e91f42"
integrity sha512-dWi5VjEwiLb4ofata0UCLdTbXLD1uDUebe9rNSBkHZ3fHF4eap4ZJlu3dYePKB0CKZhZrjzbydimMhaMUNdnug==
dependencies:
"@sentry/core" "7.19.0"
"@sentry/types" "7.19.0"
"@sentry/utils" "7.19.0"
tslib "^1.9.3"

"@sentry/core@7.11.1":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.11.1.tgz#d68e796f3b6428aefd6086a1db00118df7a9a9e4"
integrity sha512-kaDSZ6VNuO4ZZdqUOOX6XM6x+kjo2bMnDQ3IJG51FPvVjr8lXYhXj1Ccxcot3pBYAIWPPby2+vNDOXllmXqoBA==
"@sentry/core@7.19.0":
version "7.19.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.19.0.tgz#74e0eaf4b9f42bb0290f4b3f3b0ea3e272dd693e"
integrity sha512-YF9cTBcAnO4R44092BJi5Wa2/EO02xn2ziCtmNgAVTN2LD31a/YVGxGBt/FDr4Y6yeuVehaqijVVvtpSmXrGJw==
dependencies:
"@sentry/hub" "7.11.1"
"@sentry/types" "7.11.1"
"@sentry/utils" "7.11.1"
"@sentry/types" "7.19.0"
"@sentry/utils" "7.19.0"
tslib "^1.9.3"

"@sentry/hub@7.11.1":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-7.11.1.tgz#1749b2b102ea1892ff388d65d66d3b402b393958"
integrity sha512-M6ClgdXdptS0lUBKB5KpXXe2qMQhsoiEN2pEGRI6+auqhfHCUQB1ZXsfjiOYexKC9fwx7TyFyZ9Jcaf2DTxEhw==
dependencies:
"@sentry/types" "7.11.1"
"@sentry/utils" "7.11.1"
tslib "^1.9.3"

"@sentry/types@7.11.1":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.11.1.tgz#06e2827f6ba37159c33644208a0453b86d25e232"
integrity sha512-gIEhOPxC2cjrxQ0+K2SFJ1P6e/an5osSxVc9OOtekN28eHtVsXFCLB8XVWeNQnS7N2VkrVrkqORMBz1kvIcvVQ==
"@sentry/types@7.19.0":
version "7.19.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.19.0.tgz#3ebb96670399b637a945fa499fa7436f7b930147"
integrity sha512-oGRAT6lfzoKrxO1mvxiSj0XHxWPd6Gd1wpPGuu6iJo03xgWDS+MIlD1h2unqL4N5fAzLjzmbC2D2lUw50Kn2pA==

"@sentry/utils@7.11.1":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.11.1.tgz#1635c5b223369d9428bc83c9b8908c9c3287ee10"
integrity sha512-tRVXNT5O9ilkV31pyHeTqA1PcPQfMV/2OR6yUYM4ah+QVISovC0f0ybhByuH5nYg6x/Gsnx1o7pc8L1GE3+O7A==
"@sentry/utils@7.19.0":
version "7.19.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.19.0.tgz#0e039fe57056074c3a5e47bd50d9cb4ac9a6e909"
integrity sha512-2L6lq+c9Ol2uiRxQDdcgoapmHJp24MhMN0gIkn2alSfMJ+ls6bGXzQHx6JAIdoOiwFQXRZHKL9ecfAc8O+vItA==
dependencies:
"@sentry/types" "7.11.1"
"@sentry/types" "7.19.0"
tslib "^1.9.3"

"@sentry/vue@^7.11.1":
version "7.11.1"
resolved "https://registry.yarnpkg.com/@sentry/vue/-/vue-7.11.1.tgz#dc3a1d4868a3400222053465dac154a9e30aedce"
integrity sha512-4RiaMbvGITpKpnzJBixCR874HjYCmK11yt9YRt/rwXE185TKCVyq54h+57l3680WgNz4MU9oI+PF6C/1E/LfXg==
dependencies:
"@sentry/browser" "7.11.1"
"@sentry/core" "7.11.1"
"@sentry/types" "7.11.1"
"@sentry/utils" "7.11.1"
version "7.19.0"
resolved "https://registry.yarnpkg.com/@sentry/vue/-/vue-7.19.0.tgz#3352eb1dac349045c71c522bf12770be310422c0"
integrity sha512-d8voF9B+Dqnn9YiTQaiaNUC7p0dq+UxMWjtVatC9YVR7efgQPyTbgTmw6N4yRmWtlD2Itaspwz7UNZdeCGQbHw==
dependencies:
"@sentry/browser" "7.19.0"
"@sentry/core" "7.19.0"
"@sentry/types" "7.19.0"
"@sentry/utils" "7.19.0"
tslib "^1.9.3"

"@sinclair/typebox@^0.24.1":
Expand Down