diff --git a/openedx/core/djangoapps/monitoring_utils/middleware.py b/openedx/core/djangoapps/monitoring_utils/middleware.py index bfa864d9af..9db1006813 100644 --- a/openedx/core/djangoapps/monitoring_utils/middleware.py +++ b/openedx/core/djangoapps/monitoring_utils/middleware.py @@ -10,6 +10,13 @@ request handlers which do not record custom metrics. """ import logging +from uuid import uuid4 + +import psutil + +import request_cache +from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace + log = logging.getLogger(__name__) try: import newrelic.agent @@ -17,10 +24,6 @@ except ImportError: log.warning("Unable to load NewRelic agent module") newrelic = None # pylint: disable=invalid-name -import psutil -import request_cache -from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace - REQUEST_CACHE_KEY = 'monitoring_custom_metrics' WAFFLE_NAMESPACE = 'monitoring_utils' @@ -83,9 +86,11 @@ class MonitoringMemoryMiddleware(object): Middleware for monitoring memory usage. """ memory_data_key = u'memory_data' + guid_key = u'guid_key' def process_request(self, request): if self._is_enabled(): + self._cache[self.guid_key] = unicode(uuid4()) log_prefix = self._log_prefix(u"Before", request) self._cache[self.memory_data_key] = self._memory_data(log_prefix) @@ -109,7 +114,7 @@ class MonitoringMemoryMiddleware(object): """ Returns a formatted prefix for logging for the given request. """ - return u"{} request '{} {}'".format(prefix, request.method, request.path) + return u"{} request '{} {} {}'".format(prefix, request.method, request.path, self._cache[self.guid_key]) def _memory_data(self, log_prefix): """