tom-draper / api-analytics

Lightweight monitoring and analytics for API frameworks.
https://apianalytics.dev
MIT License
179 stars 26 forks source link

KeyError: 'HTTP_USER_AGENT' #27

Closed neurogen-dev closed 10 months ago

neurogen-dev commented 10 months ago
Oct 26 23:19:55 Neurohost python3[2273106]: KeyError: 'HTTP_USER_AGENT'
Oct 26 23:19:55 Neurohost python3[2273106]: During handling of the above exception, another exception occurred:
Oct 26 23:19:55 Neurohost python3[2273106]: Traceback (most recent call last):
Oct 26 23:19:55 Neurohost python3[2273106]:   File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 891, in finalize_request
Oct 26 23:19:55 Neurohost python3[2273106]:     response = self.process_response(response)
Oct 26 23:19:55 Neurohost python3[2273106]:   File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1267, in process_response
Oct 26 23:19:55 Neurohost python3[2273106]:     response = self.ensure_sync(func)(response)
Oct 26 23:19:55 Neurohost python3[2273106]:   File "/usr/local/lib/python3.10/dist-packages/api_analytics/flask.py", line 24, in on_finish
Oct 26 23:19:55 Neurohost python3[2273106]:     'user_agent': request.headers['user-agent'],
Oct 26 23:19:55 Neurohost python3[2273106]:   File "/usr/local/lib/python3.10/dist-packages/werkzeug/datastructures/headers.py", line 493, in __getitem__
Oct 26 23:19:55 Neurohost python3[2273106]:     return self.environ[f"HTTP_{key}"]
Oct 26 23:19:55 Neurohost python3[2273106]: KeyError: 'HTTP_USER_AGENT'

In my server logs I see this error very often. If I disable analytics - the error disappears, everything works as it should.

tom-draper commented 10 months ago

Thanks for raising this, updating your analytics package to 1.1.7 should solve the issue!