tom-draper / api-analytics

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

KeyError: 'user-agent' #26

Closed zubairbaqai closed 1 year ago

zubairbaqai commented 1 year ago

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi result = await app( # type: ignore[func-returns-value] File "/usr/local/lib/python3.10/dist-packages/uvicorn/middleware/proxy_headers.py", line 84, in call return await self.app(scope, receive, send) File "/usr/local/lib/python3.10/dist-packages/fastapi/applications.py", line 1115, in call await super().call(scope, receive, send) File "/usr/local/lib/python3.10/dist-packages/starlette/applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.10/dist-packages/starlette/middleware/errors.py", line 184, in call raise exc File "/usr/local/lib/python3.10/dist-packages/starlette/middleware/errors.py", line 162, in call await self.app(scope, receive, _send) File "/usr/local/lib/python3.10/dist-packages/starlette/middleware/base.py", line 108, in call response = await self.dispatch_func(request, call_next) File "/usr/local/lib/python3.10/dist-packages/api_analytics/fastapi.py", line 25, in dispatch 'user_agent': request.headers['user-agent'], File "/usr/local/lib/python3.10/dist-packages/starlette/datastructures.py", line 568, in getitem raise KeyError(key) KeyError: 'user-agent'

i tried integrating this on my FastAPI, and this is what i am getting when utilizing this on AWS environment.

tom-draper commented 1 year ago

Thanks for letting me know, updating the fastapi-analytics package to 1.1.5 should fix the issue!