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

Post Django errors to Github #3322

Merged
merged 2 commits into from Sep 18, 2017
Merged

Post Django errors to Github #3322

merged 2 commits into from Sep 18, 2017

Conversation

richaagarwal
Copy link
Contributor

@richaagarwal richaagarwal commented Sep 8, 2017

  • Adds a logging handler to intercept any logging statements of level ERROR
  • Posts them to Github Enterprise as issues, as we are doing with Jenkins failures and New Relic incidents

@@ -0,0 +1,14 @@
import logging
Copy link
Member

Choose a reason for hiding this comment

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

I think the naming of the post_django_errors.py file might want to be more consistent with other logging handler module names since it's just a Python logging handler, not Django-specific.


def emit(self, record):
GithubAlert({}).post(
title=record.message[:30],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Truncating to 30 characters isn't ideal but I'm not sure how else to do this for now. Curious to see it in action before optimizing this.

@richaagarwal
Copy link
Contributor Author

@willbarton Ready for review again

Copy link
Member

@chosak chosak left a comment

Choose a reason for hiding this comment

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

I worry about introducing a dependence on the GitHub API as part of the logging flow. See additional higher-level thoughts at GHE#1162.


class CFGovErrorHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this __init__ necessary, if it all it does is call the base class?

""" Test that calling CFGOVErrorHandler.emit
makes a GithubAlert post with the right parameters
"""
message = ('Internal Server Error: /tést-page/'
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to define this as a unicode string, e.g. u'/tést-page/' vs '/tést-page/'? Might be nice to have a from __future__ import unicode_literals here.

@@ -41,6 +41,10 @@
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
'db': {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if you want to test this config, but one way of doing it might be to use the built-in django.test.utils.patch_logger as demonstrated here.

Copy link
Member

@chosak chosak left a comment

Choose a reason for hiding this comment

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

Withdrawing my hold on this after internal discussion.

@richaagarwal
Copy link
Contributor Author

I'm merging this @willbarton. We can iterate!

@richaagarwal richaagarwal merged commit 7633dab into master Sep 18, 2017
@richaagarwal richaagarwal deleted the post-django-errors branch September 18, 2017 21:49
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