From 243b0519afc0af759b2728bfcfcd110fbf4653c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Thu, 11 Jul 2024 13:05:56 +0200 Subject: [PATCH] improve logging --- src/apps/users/adapters.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/apps/users/adapters.py b/src/apps/users/adapters.py index ddfa9a0..7175b05 100644 --- a/src/apps/users/adapters.py +++ b/src/apps/users/adapters.py @@ -1,5 +1,5 @@ -from __future__ import annotations - +import logging +import traceback from typing import Self from allauth.account.adapter import DefaultAccountAdapter @@ -8,6 +8,16 @@ from django.http import HttpRequest +def report(e): + logging.error(str(e)) + try: + from sentry_sdk import capture_exception + + capture_exception(e) + except Exception: + logging.error(traceback.format_exc()) + + class AccountAdapter(DefaultAccountAdapter): def is_open_for_signup(self: Self, request: HttpRequest) -> bool: return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) @@ -18,5 +28,14 @@ class SocialAccountAdapter(DefaultSocialAccountAdapter): just for debugging obscure integration exceptions """ - def authentication_error(self, *args, **kwargs): - print(args, kwargs) + def on_authentication_error( + self: Self, request, provider, error=None, exception=None, extra_context=None + ): + report(exception) + return super().on_authentication_error( + request, + provider, + error=error, + exception=exception, + extra_context=extra_context, + )