KeyError: 'auto_session_tracking' in version 1.5.5
See original GitHub issueEnvironment
Python 3.10.2 sentry-sdk=1.5.5 fastapi==0.73.0
All packages
aiojobs==1.0.0 aiomysql==0.0.22 anyio==3.5.0 asgiref==3.5.0 async-timeout==4.0.2 attrs==21.4.0 Brotli==1.0.9 cached-property==1.5.2 certifi==2021.10.8 charset-normalizer==2.0.11 click==8.0.3 coverage==6.3.1 dnspython==2.2.0 email-validator==1.1.3 envparse==0.2.0 execnet==1.9.0 fastapi==0.73.0 fastapi-utils==0.2.1 fastnumbers==3.2.1 fluent-logger==0.10.0 greenlet==1.1.2 h11==0.12.0 httpcore==0.14.7 httpx==0.22.0 idna==3.3 iniconfig==1.1.1 isodate==0.6.1 jmespath==0.10.0 lxml==4.7.1 motor==2.5.1 msgpack==1.0.3 mysqlclient==2.1.0 natsort==8.1.0 packaging==21.3 pep517==0.12.0 pip-tools==6.5.1 platformdirs==2.5.0 pluggy==1.0.0 py==1.11.0 pydantic==1.9.0 pymongo==3.12.3 PyMySQL==0.9.3 pyparsing==3.0.7 pytest==7.0.1 pytest-asyncio==0.18.1 pytest-cov==3.0.0 pytest-forked==1.4.0 pytest-xdist==2.5.0 python-snappy==0.6.0 pytz==2021.3 PyYAML==6.0 requests==2.27.1 requests-file==1.5.1 requests-toolbelt==0.9.1 rfc3986==1.5.0 sentry-sdk==1.5.5 six==1.16.0 sniffio==1.2.0 SQLAlchemy==1.4.31 starlette==0.17.1 tomli==2.0.1 typing_extensions==4.0.1 ujson==5.1.0 urllib3==1.26.8 uvicorn==0.17.4 uvloop==0.16.0 zeep==4.1.0 zstandard==0.17.0
- test_sentry.py
# -*- codong: utf-8 -*-
from fastapi import FastAPI
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from starlette.testclient import TestClient
def test_sentry():
app = FastAPI()
@app.get("/")
async def index():
return 'Ok'
asgi_app = SentryAsgiMiddleware(app)
with TestClient(app=asgi_app) as client:
rsp = client.get('/')
assert rsp.status_code == 200
- pytest test_sentry
- test_sentry.py F [100%]
Expected Result
test_sentry Ok
Actual Result
FAILED
def is_auto_session_tracking_enabled(hub=None):
# type: (Optional[sentry_sdk.Hub]) -> bool
"""Utility function to find out if session tracking is enabled."""
if hub is None:
hub = sentry_sdk.Hub.current
should_track = hub.scope._force_auto_session_tracking
if should_track is None:
client_options = hub.client.options if hub.client else {}
> should_track = client_options["auto_session_tracking"]
E KeyError: 'auto_session_tracking'
pytest out
test_sentry.py:6 (test_sentry)
def test_sentry():
app = FastAPI()
@app.get("/")
async def index():
return 'Ok'
asgi_app = SentryAsgiMiddleware(app)
> with TestClient(app=asgi_app) as client:
tests/test_sentry.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/starlette/testclient.py:524: in __enter__
portal.call(self.wait_startup)
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/anyio/from_thread.py:240: in call
return cast(T_Retval, self.start_task_soon(func, *args).result())
/home/tonal/.pyenv/versions/3.10.2/lib/python3.10/concurrent/futures/_base.py:446: in result
return self.__get_result()
/home/tonal/.pyenv/versions/3.10.2/lib/python3.10/concurrent/futures/_base.py:391: in __get_result
raise self._exception
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/anyio/from_thread.py:187: in _call_func
retval = await retval
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/starlette/testclient.py:553: in wait_startup
message = await receive()
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/starlette/testclient.py:550: in receive
self.task.result()
/home/tonal/.pyenv/versions/3.10.2/lib/python3.10/concurrent/futures/_base.py:439: in result
return self.__get_result()
/home/tonal/.pyenv/versions/3.10.2/lib/python3.10/concurrent/futures/_base.py:391: in __get_result
raise self._exception
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/anyio/from_thread.py:187: in _call_func
retval = await retval
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/starlette/testclient.py:540: in lifespan
await self.app(scope, self.stream_receive.receive, self.stream_send.send)
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:107: in _run_asgi3
return await self._run_app(scope, lambda: self.app(scope, receive, send))
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:123: in _run_app
with auto_session_tracking(hub, session_mode="request"):
/home/tonal/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py:135: in __enter__
return next(self.gen)
/home/tonal/.pyenv/versions/epool-delivery_calc/lib/python3.10/site-packages/sentry_sdk/sessions.py:39: in auto_session_tracking
should_track = is_auto_session_tracking_enabled(hub)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hub = <sentry_sdk.hub.Hub object at 0x7f20c74d6830>
def is_auto_session_tracking_enabled(hub=None):
# type: (Optional[sentry_sdk.Hub]) -> bool
"""Utility function to find out if session tracking is enabled."""
if hub is None:
hub = sentry_sdk.Hub.current
should_track = hub.scope._force_auto_session_tracking
if should_track is None:
client_options = hub.client.options if hub.client else {}
> should_track = client_options["auto_session_tracking"]
E KeyError: 'auto_session_tracking'
In version sentry-sdk=1.5.4 all work Ok
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:12 (5 by maintainers)
Top GitHub Comments
@simonkern Yes. After add
sentry_sdk.init()
test work OkI just checked and you are right @lsmith77 . It should be totally fine to not call
init()
. So I will do some tweaking so no errors are thrown in 1.5.5 when init() is never called.Thanks for bringing this up!