lamby / django-slack

Slack integration for Django, using the templating engine to generate messages
https://django-slack.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
241 stars 57 forks source link

Custom ExceptionReporter #100

Open errrken opened 3 years ago

errrken commented 3 years ago

Thanks for a great library.

It would be great if one could provide a custom ExceptionReporter. For example, I do not want to send data like settings and request_meta when exceptions happens. Right now I do:

class CustomExceptionReporter(debug.ExceptionReporter):

    def get_traceback_data(self):
        data = super().get_traceback_data()
        data.pop('settings', None)
        data.pop('request_meta', None)
        return data

and then override all of SlackExceptionHandler emit method just to change the ExceptionReporter class.

EDIT (lamby): Adding Markdown

lamby commented 3 years ago

Just to confirm, an ExceptionReporter that sends a message to Slack?

errrken commented 3 years ago

@lamby Yes, so here: https://github.com/lamby/django-slack/blob/9da57a889a6b943ae454c64e046ea76c19b4302c/django_slack/log.py#L52 it uses Django's ExceptionReporter.

So like a setting SLACK_EXCEPTION_REPORTER or something where you can reference your own if you want to (like my CustomExceptionReporter above). My aim is to filter out unnecessary sensitive data like request metadata etc when an exception occurs and posting to slack.

Or maybe there is a better way?

lamby commented 3 years ago

Not sure why you would need a SLACK_EXCEPTION_REPORTER setting to do that. Could you not subclass django_slack.log.SlackExceptionHandler (and modify its behaviour as you wish) and then configure your settings.LOGGING to point to that version instead? I think I might be missing something here, though; it's been a long time since I used this exception handler.