Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add logger configuration to allow prod exception handling #466

Merged
merged 1 commit into from
Jan 17, 2022

Conversation

AetherUnbound
Copy link
Contributor

Description

This PR adds some additional logging configuration to enable exception logging in production. Currently, when an exception or error occurs, we get unhelpful logs that look like this:

2022-01-07T13:06:57.964-08:00	Internal Server Error: /v1/audio/
2022-01-07T13:06:57.965-08:00	Internal Server Error: /v1/audio/
2022-01-07T13:06:57.984-08:00	Internal Server Error: /v1/audio/
2022-01-07T13:06:57.985-08:00	Internal Server Error: /v1/audio/

The above errors are HTTP 500 errors, but we aren't able to see any information about what is actually failing. The logging configuration in this PR ensures that:

  1. Intentional logging within the service gets bubbled up appropriately
  2. Django logging in general is set to WARNING in production
  3. Exceptions are bubbled up to the logs appropriately in production

This does not mean that users will see the debug view that Django provides in production. When we have DEBUG=False, all of that will be correctly hidden. This just makes it easier for us to troubleshoot production problems (particularly ones we can't replicate locally!).

I've used this config previously with great success! We also have the option to set up admin emails down the line where we'll receive an email on server errors. I think for a project of this size, that might be inadvisable and we would want a different way of aggregating/reporting errors.

Testing Instructions

Note that these steps are not to be committed and are only intended to replicate a production setup locally

  1. Set DJANGO_DEBUG_ENABLED=False in api/env.docker
  2. Set the condition on line 54 of settings.py from if DEBUG: to if True:
  3. Add an exception under the healthcheck view in api/catalog/api/views/health_views.py (I just added raise ValueError("Whoops!") above line 17)
  4. just up
  5. just logs web
  6. Visit localhost:8000/healthcheck in your browser

If you follow these steps and are on main, you should receive an HTTP 500 error page and there should be nothing printed out in the logs (or at least not an exception). However if these steps are done on this branch, you should still receive the same generic HTTP 500 page in the browser, but the logs should contain the full exception traceback.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@AetherUnbound AetherUnbound requested a review from a team as a code owner January 7, 2022 23:38
@AetherUnbound AetherUnbound added ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🟧 priority: high Stalls work on the project or its dependents labels Jan 7, 2022
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

Should be really helpful!
Thank you for the detailed description and testing instructions, it's really interesting to read.

@AetherUnbound
Copy link
Contributor Author

Ugh, this is suffering the same hanging issue as I tried to address in #421 :/ I'll need to investigate this a bit more

@AetherUnbound AetherUnbound force-pushed the feature/prod-exception-logging branch from 3ef62be to 61b3a00 Compare January 10, 2022 18:52
Comment on lines +5 to +6
# Filter out health checks from the logs, they're verbose and happen frequently
return not ("GET /healthcheck" in record.getMessage() and record.status_code == 200)
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

Looks nice! @rbadillap I just want to point out that you were an assigned reviewer here; in the future just throw a comment on someone else's PR if your not able to review in within a day or two and we'll assign someone else. Thanks!

@AetherUnbound AetherUnbound merged commit 6a65899 into main Jan 17, 2022
@AetherUnbound AetherUnbound deleted the feature/prod-exception-logging branch January 17, 2022 17:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟧 priority: high Stalls work on the project or its dependents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants