sanic-prometheus
sanic-prometheus copied to clipboard
AttributeError: 'types.SimpleNamespace' object has no attribute '__START_TIME__'
I'm facing this issue with latest sanic-prometheus. It happens when I accessed a non-existed page..
[ERROR] Exception occurred in one of response middleware handlers
Traceback (most recent call last):
File "/home/.../lib/python3.6/site-packages/sanic/app.py", line 977, in handle_request
request, response, request_name=name
File "/home/.../lib/python3.6/site-packages/sanic/app.py", line 1281, in _run_response_middleware
_response = await _response
File "/home/.../lib/python3.6/site-packages/sanic_prometheus/__init__.py", line 125, in before_response
metrics.after_request_handler(request, response, get_endpoint)
File "/home/.../lib/python3.6/site-packages/sanic_prometheus/metrics.py", line 56, in after_request_handler
lat = time.time() - request.ctx.__START_TIME__
AttributeError: 'types.SimpleNamespace' object has no attribute '__START_TIME__'
Running:
Ubuntu 20.04 Python 3.6.9 sanic 20.6.3 sanic-prometheus 0.2.1
I'm experiencing the same thing on sanic 20.12.1 and sanic-prometheus 0.2.1.
Hmmm... I'm 99% sure this happens because I have a request middleware that response early (it conditionally returns a 403 json response).
I think your request-middleware then does not add the START_TIME and then your response-middleware errors out.
(So my case is different, I'm not visiting a non-existent page.)
I'm experiencing the same thing on sanic 20.12.1 and sanic-prometheus 0.2.1.
Hmmm... I'm 99% sure this happens because I have a request middleware that response early (it conditionally returns a 403 json response).
I think your request-middleware then does not add the START_TIME and then your response-middleware errors out.
(So my case is different, I'm not visiting a non-existent page.)
I think that might be the case here. A PR to fix this would be awesome.
However, you should not assign lat = 0
or it will add 404 requests to metrics.