Add logging middleware to determine why our responses are bad.

This commit is contained in:
Diana Huang
2019-12-11 16:05:02 -05:00
parent 617e8519d9
commit 28ce0e6739
2 changed files with 26 additions and 0 deletions

View File

@@ -36,6 +36,28 @@ META_KEY_TO_CONTEXT_KEY = {
}
class ResponseLoggingMiddleware(object):
"""
A debugging middleware for the purpose of understanding what the current state of the response
is at this point in the stack.
"""
def process_response(self, _request, response):
"""
Logs the response at the current point in the middleware stack for debugging purposes.
"""
try:
log.info('Logging response for debugging purposes: %r', response)
log.info('Response container data: %r', response._container) # pylint: disable=protected-access
log.info('Container types: %r', [type(el) for el in response._container]) # pylint: disable=protected-access
except: # pylint: disable=bare-except
# If this causes an error, we don't want it to bubble up since this is just for logging.
log.exception('Error logging response object')
return response
class TrackMiddleware(object):
"""
Tracks all requests made, as well as setting up context for other server

View File

@@ -1443,6 +1443,10 @@ MIDDLEWARE_CLASSES = [
'openedx.core.djangoapps.header_control.middleware.HeaderControlMiddleware',
'lms.djangoapps.discussion.django_comment_client.middleware.AjaxExceptionMiddleware',
'django.middleware.common.CommonMiddleware',
# Debugging Middleware. Remove once Python 3 has been deployed.
'track.middleware.ResponseLoggingMiddleware',
'django.contrib.sites.middleware.CurrentSiteMiddleware',
'edx_rest_framework_extensions.auth.jwt.middleware.JwtAuthCookieMiddleware',