From 280feb8594574a0c70194a64bf04dd1b0db1633d Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 14 Feb 2022 14:14:56 +0100 Subject: [PATCH 1/3] fix(asgi): Added default value for auto_session_tracking to make it work in fastapi refs #1334 --- sentry_sdk/sessions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/sessions.py b/sentry_sdk/sessions.py index 06ad880d0f..bdbe2feab3 100644 --- a/sentry_sdk/sessions.py +++ b/sentry_sdk/sessions.py @@ -23,10 +23,13 @@ def is_auto_session_tracking_enabled(hub=None): """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"] + should_track = client_options.get("auto_session_tracking", None) + return should_track From b5895a230b0fa2c923a351832e1708deaf76eb63 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 15 Feb 2022 12:06:06 +0100 Subject: [PATCH 2/3] Always return a boolean --- sentry_sdk/sessions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/sessions.py b/sentry_sdk/sessions.py index bdbe2feab3..eaaa87148a 100644 --- a/sentry_sdk/sessions.py +++ b/sentry_sdk/sessions.py @@ -28,7 +28,7 @@ def is_auto_session_tracking_enabled(hub=None): if should_track is None: client_options = hub.client.options if hub.client else {} - should_track = client_options.get("auto_session_tracking", None) + should_track = client_options.get("auto_session_tracking", False) return should_track From 75f56a5ffe846ff10cd92dae2f7b7d021fac3d50 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 16 Feb 2022 11:42:19 +0100 Subject: [PATCH 3/3] Fixed type anotations --- sentry_sdk/sessions.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/sessions.py b/sentry_sdk/sessions.py index eaaa87148a..4e4d21b89c 100644 --- a/sentry_sdk/sessions.py +++ b/sentry_sdk/sessions.py @@ -10,16 +10,17 @@ from sentry_sdk.utils import format_timestamp if MYPY: - from typing import Callable - from typing import Optional from typing import Any + from typing import Callable from typing import Dict - from typing import List from typing import Generator + from typing import List + from typing import Optional + from typing import Union def is_auto_session_tracking_enabled(hub=None): - # type: (Optional[sentry_sdk.Hub]) -> bool + # type: (Optional[sentry_sdk.Hub]) -> Union[Any, bool, None] """Utility function to find out if session tracking is enabled.""" if hub is None: hub = sentry_sdk.Hub.current