From f34606f8a4282078f037061d65d473bc4f20a1c1 Mon Sep 17 00:00:00 2001 From: Manjinder Singh <49171515+jinder1s@users.noreply.github.com> Date: Tue, 14 Sep 2021 08:31:36 -0400 Subject: [PATCH] feat: adding monitoring to CookieNameChange middleware (#28730) * feat: adding monitoring to CookieNameChange middleware Adding custom attribute: cookie.change_name if cookie.change_name in transaction and equal 0, cookie with alternate name is detected and deleted if cookie.change_name in transaction and equal 1, cookie with current name not in request and added --- openedx/core/djangoapps/cookie_metadata/middleware.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openedx/core/djangoapps/cookie_metadata/middleware.py b/openedx/core/djangoapps/cookie_metadata/middleware.py index 587f7c5455..6ebc8cbd8b 100644 --- a/openedx/core/djangoapps/cookie_metadata/middleware.py +++ b/openedx/core/djangoapps/cookie_metadata/middleware.py @@ -1,6 +1,8 @@ """Middleware to change name of an incoming cookie""" from django.conf import settings +from edx_django_utils.monitoring import set_custom_attribute + class CookieNameChange: """Changes name of an incoming cookie""" @@ -78,12 +80,19 @@ class CookieNameChange: alt_cookie_in_request = True alt_cookie_value = request.COOKIES[expand_settings["alternate"]] del request.COOKIES[expand_settings["alternate"]] + # Adding custom attribute: cookie.change_name + # if cookie.change_name in transaction and equal 0, + # cookie with alternate name was detected and deleted + # if cookie.change_name in transaction and equal 1, + # cookie with current name was added + set_custom_attribute("cookie.change_name", 0) if ( expand_settings["current"] not in request.COOKIES and alt_cookie_in_request ): request.COOKIES[expand_settings["current"]] = alt_cookie_value + set_custom_attribute("cookie.change_name", 1) response = self.get_response(request) return response