Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'types.SimpleNamespace' object has no attribute '__START_TIME__' #37

Open
vtdat opened this issue Jan 25, 2021 · 2 comments

Comments

@vtdat
Copy link

vtdat commented Jan 25, 2021

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

erikcw added a commit to erikcw/sanic-prometheus that referenced this issue Feb 4, 2021
@dhensen
Copy link

dhensen commented Feb 6, 2021

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.)

@vtdat
Copy link
Author

vtdat commented Feb 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants