The Django insights middleware crashes in process_response when a middleware short-circuits when processing the request because the process_request hasn't be run.
For example, the CommonMiddleware will short-circuit to affix a missing trailing slash with a 301 Moved Permanently response if the client accesses /admin when /admin/ is the registered URL
MIDDLEWARE_CLASSES = [
# ...
'django.middleware.common.CommonMiddleware',
# ...
'applicationinsights.django.ApplicationInsightsMiddleware'
]
The reasonable solution is probably to check for the presence of the appinsights attribute in the process_response method. The method can submit the event without the duration field set, if the appinsights attribute is missing.
The Django insights middleware crashes in
process_responsewhen a middleware short-circuits when processing the request because theprocess_requesthasn't be run.For example, the
CommonMiddlewarewill short-circuit to affix a missing trailing slash with a 301 Moved Permanently response if the client accesses/adminwhen/admin/is the registered URLThe reasonable solution is probably to check for the presence of the
appinsightsattribute in theprocess_responsemethod. The method can submit the event without thedurationfield set, if theappinsightsattribute is missing.