mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-28 09:59:59 -04:00
This solves two problems - it makes our response times more accurate as it means we start measuring the response time earlier (otherwise we aren't recording the time spent by `csrf` and `login_manager`s `before_request` functions - is a temporary fix for a bug in the gds python metrics library as explained below. Currently, when a request comes in it goes through various `before_request` functions. Currently it goes through the function introduced by the csrf client and then the one introduced by the metrics client. If an exception is thrown by the csrf.before_request function then we do not run the `metrics.before_request` function. This would happen in the case that a CSRF token is invalid and then the main body of the request would not process but then all `teardown_request` functions will run. When the `metrics.teardown_request` function runs it looks for `g._gds_metrics_start_time`, however this attribute is not availble on the flask global object as it was not created as the `metrics.before_request` function that creates it did not run. This then throws an `AttributeError` and results in a 500 for the user. The short term solution for this (initing metrics before csrf) means that `_gds_metrics_start_time` will be set before csrf is at risk of throwing an exception. A separate PR will be put into the gds metrics python library to remove the risk of an `AttributeError` and instead to log a warning instead of throwing an uncaught exception.