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

404 page causes KeyError: '__START_TIME__' #35

Open
optroodt opened this issue Jun 10, 2020 · 1 comment
Open

404 page causes KeyError: '__START_TIME__' #35

optroodt opened this issue Jun 10, 2020 · 1 comment

Comments

@optroodt
Copy link
Contributor

When you reach a 404, it looks like the before_request_handler is not called and thus triggers the following error in the after_request_handler:

[2020-06-10 15:13:42 +0200] [17655] [ERROR] Exception occurred in one of response middleware handlers
Traceback (most recent call last):
  File "/Users/optroodt/venvs/<snip>/lib/python3.7/site-packages/sanic/app.py", line 1017, in handle_request
    request, response, request_name=name
  File "/Users/optroodt/venvs/<snip>/lib/python3.7/site-packages/sanic/app.py", line 1315, in _run_response_middleware
    _response = await _response
  File "/Users/optroodt/venvs/<snip>/lib/python3.7/site-packages/sanic_prometheus/__init__.py", line 125, in before_response
    metrics.after_request_handler(request, response, get_endpoint)
  File "/Users/optroodt/venvs/<snip>/lib/python3.7/site-packages/sanic_prometheus/metrics.py", line 56, in after_request_handler
    lat = time.time() - request['__START_TIME__']
  File "/Users/optroodt/venvs/<snip>/lib/python3.7/site-packages/sanic/request.py", line 143, in __getitem__
    return self.ctx.__dict__[key]
KeyError: '__START_TIME__'

Running:

  • MacOS 10.14.6 (Yes, I should upgrade :D)
  • Python 3.7.7,
  • sanic 19.12.2
  • sanic-prometheus 0.2.0
@Arvind2222
Copy link
Contributor

#33

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