Configure logging of user info in Django
With GDPR coming up soon it would be really useful to be able to configure the type of user info we log in the Django client. Ideally we should be able to disable logging ip address, username and email via a setting.
Yes! Seems like this has been hardcoded in https://github.com/getsentry/raven-python/blob/master/raven/contrib/django/client.py#L158-L186, so guess the way to go is to override this method? But how do I use a modified version of the DjangoClient class?
Update: Seems like one can set the SENTRY_CLIENT setting. https://github.com/getsentry/raven-python/blob/master/raven/contrib/django/models.py#L115 will try and report back :)
Yes, that worked!
Here is the new client class:
from raven.contrib.django.client import DjangoClient
class GDPRCompliantDjangoClient(DjangoClient):
def get_user_info(self, request):
user_info = {}
user = getattr(request, 'user', None)
if user is None:
return user_info
authenticated = user.is_authenticated
if not authenticated:
return user_info
user_info['id'] = user.pk
user_info['username'] = user.username
return user_info
and I've just set the following setting:
SENTRY_CLIENT = 'path.to.GDPRCompliantDjangoClient'
Nice stuff! I didnt realise you could configure the client in that way. I think this is an acceptable solution.
Will be changing how some of the stuff is handled by default soon, but yes, you can configure your own django client.