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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Replace exception logger function with logger.exception #37

Merged
merged 1 commit into from Aug 16, 2022

Conversation

sondrelg
Copy link
Contributor

@sondrelg sondrelg commented Aug 16, 2022

This PR tweaks the way errors are logged, to include more metadata.

I didn't spend a lot of time crafting the logger messages, so suggestions for better ones are very welcome 馃檪

Motivation

We use Sentry for errors, and saq currently logs job exceptions in a way that's slightly too generic for Sentry. Since the plaintext dump of a traceback is logged without any extra information, all errors raised by saq are bundled together. Moreover, there is a size limit to log message length in Sentry, so we're not even receiving the full tracebacks (see screenshot at the bottom of the comment below).

image

Using logger.exception or logger.error(..., exc_info=True) (they're the same thing), we're able to get proper Sentry events, containing the complete traceback plus "breadcrumbs"

image

@sondrelg sondrelg marked this pull request as draft August 16, 2022 08:53
@sondrelg
Copy link
Contributor Author

sondrelg commented Aug 16, 2022

To test, I created his task function to run. Once on the latest release, and once with the fork:

def bad_function(ctx):
    raise ValueError('I fail now beep boop')

Here is the Sentry event produced with latest saq release:

image

In case you can't tell, this page actually has zero references to the actual error 馃槢

And here is the Sentry event produced with the fork branch:

image

The second one could also use some extra information, but at least now we get the code that raised the exception in focus, rather than have it maybe be included in the traceback plaintext dump.

Another thing to mention is that Sentry's logging integration cuts off long log messages, so the plaintext dump (for us) gets chopped in half hehe

image

@sondrelg sondrelg marked this pull request as ready for review August 16, 2022 09:25
@tobymao
Copy link
Owner

tobymao commented Aug 16, 2022

what is the result in the command line?

Copy link
Collaborator

@barakalon barakalon left a comment

Choose a reason for hiding this comment

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

Sweet.

I'm pretty sure the stream handler dumps the exception info properly.

@tobymao
Copy link
Owner

tobymao commented Aug 16, 2022

thanks @barakalon

and thanks @sondrelg for the PR

@tobymao tobymao merged commit 604faf1 into tobymao:master Aug 16, 2022
@sondrelg sondrelg deleted the exception-logging branch August 16, 2022 18:34
@sondrelg sondrelg restored the exception-logging branch August 16, 2022 18:34
@sondrelg sondrelg deleted the exception-logging branch August 16, 2022 18:34
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.

None yet

3 participants