I have construct an REST API using flask, a lightweight WSGI web application framework. However, during the testing, some endpoints takes seconds to response. It may be a result of bad code, or just a network jitter. Therefor, I need to measuring the time elapse from the moment a request come in, to the point where the response is sent.
Flask (1.1.x) does not have a timestamp in the request object, thus the timestamp must be recorded manually. The global context ‘g’ provided by flask do the job well.