Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions portal/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ class AppsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "portal"
verbose_name = "Studio Portal"

def ready(self):
"""
This function is used to register the signal handlers.

See
`Django documentation <https://docs.djangoproject.com/en/4.2/ref/applications/#django.apps.AppConfig.ready>`_
for more information.
"""
import portal.signals
8 changes: 8 additions & 0 deletions portal/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import structlog
from django.dispatch import receiver
from django_structlog.signals import bind_extra_request_metadata


@receiver(bind_extra_request_metadata)
def remove_ip_address(sender, request, logger, **kwargs):
structlog.contextvars.bind_contextvars(ip=None)
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Signal handlers for bind_extra_request_metadata should return a dict of metadata (e.g., return {"ip": None}) instead of only binding contextvars, otherwise the ip field may not be removed as intended.

Suggested change
structlog.contextvars.bind_contextvars(ip=None)
return {"ip": None}

Copilot uses AI. Check for mistakes.
1 change: 1 addition & 0 deletions studio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = os.getenv("DEBUG", default="False").lower() in ("true", "1", "t")
DEVELOP_LOGS_ENABLED = DEBUG


# Since this file is only used for development, we can have this set to all hosts.
Expand Down
2 changes: 1 addition & 1 deletion studio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_logger(name: str) -> Any:
When DEBUG = True, then we return the standard logger,
otherwise, the structlog.
"""
if settings.DEBUG:
if settings.DEVELOP_LOGS_ENABLED:
return logging.getLogger(name)
else:
return structlog.getLogger(name)
Expand Down