Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IN 1035 - log unhandled exceptions #41

Merged
merged 2 commits into from
Aug 27, 2024
Merged

Conversation

ghukill
Copy link
Contributor

@ghukill ghukill commented Aug 26, 2024

Purpose and background context

A recent Sentry event indicates that an unhandled exception was encountered during Submission.submit(), but does not provide any details about the underlying exception encountered.

The error handling in submit() is pretty intricate, where sub-methods called will handle exceptions and raise custom exceptions like ItemCreateError, ItemPostError, etc. When these are encountered, there is logic in place to handle them.

But when an exception occurs that is not gracefully handled by this method, formerly only the following message was logged, but without any traceback or information about the actual exception encountered:

"Unexpected exception, aborting DSpace Submission Service processing"

This PR changes this from logger.error to logger.exception which will also log the associated, underlying exception to Cloudwatch and Sentry. In this way, we can understand what happened in this situation.

As noted in the associated Jira ticket, this is in support of some future work to better rollback any operations performed in Dspace and/or manage SQS queues. Work will continue for this, but this intermediate PR at least begins to log unhandled exceptions in a way that supports retroactive debugging and understanding.

How can a reviewer manually see the effects of these changes?

The newly created test test_submit_dspace_unknown_api_error_logs_exception_and_raises_error demonstrates this behavior.

Instead of a request to DSpace returning an HTTP response that itself indicates any errors, the request to collection handle "0000/collection04" is mocked to throw a requests.exceptions.RequestException immediately. Because there is not response, there is nothing to parse and report.

This test demonstrates that while we still don't have entirely graceful handling of unhandled exceptions during Submission.submit() (e.g. managing the SQS queue depending on what happened), we at least have logged the actual, underlying exception in a way that allows us to better react to the error.

Includes new or updated dependencies?

NO

Changes expectations for external applications?

NO

What are the relevant tickets?

Developer

  • All new ENV is documented in README
  • All new ENV has been added to staging and production environments
  • All related Jira tickets are linked in commit message(s)

Code Reviewer

  • The commit message is clear and follows our guidelines
    (not just this pull request message)
  • There are appropriate tests covering any new functionality
  • The documentation has been updated or is unnecessary
  • The changes have been verified
  • New dependencies are appropriate or there were no changes

Why these changes are being introduced:

Sentry recently reported, 'Unexpected exception, aborting DSpace
Submission Service processing', which is a prepared logging statement as
part of Submission.submit().  This suggests that a totally unhandled
exception was encountered during submit work.  While somewhat helpful,
this does not give us insight into the underlying exception that caused
it in Sentry or Cloudwatch.

How this addresses that need:
* Changes logger.error to logger.exception to log the underlying
Exception to Sentry with a full traceback
* Though we may still need work to rollback actions taken,
or manage the SQS queue based on an unhandled exception,
this change will provide more information in these situations

Side effects of this change:
* Unhandled exceptions will be fully logged to Sentry

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/IN-1035
Copy link
Contributor

@ehanson8 ehanson8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ghukill ghukill merged commit 35f7622 into main Aug 27, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants