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

Suggestion: optional rich tracebacks #6

Open
alexmojaki opened this issue Sep 22, 2022 · 4 comments
Open

Suggestion: optional rich tracebacks #6

alexmojaki opened this issue Sep 22, 2022 · 4 comments

Comments

@alexmojaki
Copy link
Contributor

Currently an unhandled exception just shows the standard plain Python traceback. It can be helpful for debugging to show more information, and the dependencies are already there. One method is this:

    log = get_logger()

    def excepthook(*exc_info):
        log.exception("Uncaught exception", exc_info=exc_info)

    sys.excepthook = excepthook

However this doesn't work on its own, and a helpful warning explains why:

/code/.venv/lib/python3.10/site-packages/structlog/dev.py:421: UserWarning: Remove `format_exc_info` from your processor chain if you want pretty exceptions.

Indeed, removing that processor gives nice rich tracebacks:

Screenshot from 2022-09-22 14-51-17

I'm not familiar with structlog, maybe there's a better official way to do this. I also don't know the motivation for having format_exc_info and the consequences of removing it.

An alternative, more direct approach:

rich.traceback.install(show_locals=True)

This has pretty much the same effect, but it's not logging, and maybe that's a problem.

None of this should be the default behaviour as the tracebacks are huge and annoying when you don't want them, but maybe it could be enabled by a new env var in settings.py or some kind of verbose/debug CLI argument.

@lslunis
Copy link
Collaborator

lslunis commented Sep 23, 2022

We're not actually using the structured logging for anything, so this is probably the way to go. I'll determine priority next week once the upcoming ICE release is done.

@smithjessk
Copy link
Contributor

I'm happy to take this on if people think this is still valuable :)

@lslunis
Copy link
Collaborator

lslunis commented Jan 31, 2023

Seems worthwhile, what do you think @alexmojaki ?

@alexmojaki
Copy link
Contributor Author

Sure, why not.

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

No branches or pull requests

3 participants