fixup! 🔇(backend) silence expected 401 warnings on /me

This commit is contained in:
lebaudantoine
2026-09-08 19:07:44 +02:00
parent 9531a2daeb
commit a2f1aefac3
2 changed files with 17 additions and 7 deletions
+11 -7
View File
@@ -2,6 +2,8 @@
import logging
from django.conf import settings
class SilenceExpected401(logging.Filter):
"""Drop the expected 401 from anonymous hits on the /me endpoint.
@@ -11,11 +13,13 @@ class SilenceExpected401(logging.Filter):
"""
def filter(self, record):
"""Return False for a 401 on `/users/me`."""
if getattr(record, "status_code", None) == 401:
request = getattr(record, "request", None)
path = getattr(request, "path", "") or ""
if path.rstrip("/").endswith("/users/me"):
return False
"""Return False for a 401 on a silenced path, True otherwise."""
if getattr(record, "status_code", None) != 401:
return True
return True
request = getattr(record, "request", None)
path = getattr(request, "path", None)
if not path:
return True
return path not in settings.LOGGING_SILENCED_401_PATHS
+6
View File
@@ -1110,6 +1110,12 @@ class Base(Configuration):
environ_prefix=None,
)
LOGGING_SILENCED_401_PATHS = values.ListValue(
default=["/api/v1.0/users/me/"],
environ_name="LOGGING_SILENCED_401_PATHS",
environ_prefix=None,
)
# Logging
# We want to make it easy to log to console but by default we log production
# to Sentry and don't want to log to console.