From 320e49e8063e3602f4634febba157a6ae8b7e3c5 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:04:34 -0800 Subject: [PATCH] Move api to top-level --- sentry_sdk/integrations/featureflags.py | 8 +++--- .../featureflags/test_featureflags.py | 25 ++++++------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/sentry_sdk/integrations/featureflags.py b/sentry_sdk/integrations/featureflags.py index 8a1e6b4106..6e995ac28b 100644 --- a/sentry_sdk/integrations/featureflags.py +++ b/sentry_sdk/integrations/featureflags.py @@ -12,7 +12,7 @@ def setup_once(): scope = sentry_sdk.get_current_scope() scope.add_error_processor(flag_error_processor) - @staticmethod - def set_flag(flag: str, result: bool): - flags = sentry_sdk.get_current_scope().flags - flags.set(flag, result) + +def add_flag(flag: str, result: bool): + flags = sentry_sdk.get_current_scope().flags + flags.set(flag, result) diff --git a/tests/integrations/featureflags/test_featureflags.py b/tests/integrations/featureflags/test_featureflags.py index 202107d603..4677870d50 100644 --- a/tests/integrations/featureflags/test_featureflags.py +++ b/tests/integrations/featureflags/test_featureflags.py @@ -5,7 +5,7 @@ import sentry_sdk from sentry_sdk.integrations import _processed_integrations, _installed_integrations -from sentry_sdk.integrations.featureflags import FeatureFlagsIntegration +from sentry_sdk.integrations.featureflags import FeatureFlagsIntegration, add_flag @pytest.fixture @@ -22,11 +22,10 @@ def inner(identifier): def test_featureflags_integration(sentry_init, capture_events, uninstall_integration): uninstall_integration(FeatureFlagsIntegration.identifier) sentry_init(integrations=[FeatureFlagsIntegration()]) - flags_integration = sentry_sdk.get_client().get_integration(FeatureFlagsIntegration) - flags_integration.set_flag("hello", False) - flags_integration.set_flag("world", True) - flags_integration.set_flag("other", False) + add_flag("hello", False) + add_flag("world", True) + add_flag("other", False) events = capture_events() sentry_sdk.capture_exception(Exception("something wrong!")) @@ -49,17 +48,13 @@ def test_featureflags_integration_threaded( events = capture_events() # Capture an eval before we split isolation scopes. - flags_integration = sentry_sdk.get_client().get_integration(FeatureFlagsIntegration) - flags_integration.set_flag("hello", False) + add_flag("hello", False) def task(flag_key): # Creates a new isolation scope for the thread. # This means the evaluations in each task are captured separately. with sentry_sdk.isolation_scope(): - flags_integration = sentry_sdk.get_client().get_integration( - FeatureFlagsIntegration - ) - flags_integration.set_flag(flag_key, False) + add_flag(flag_key, False) # use a tag to identify to identify events later on sentry_sdk.set_tag("task_id", flag_key) sentry_sdk.capture_exception(Exception("something wrong!")) @@ -102,17 +97,13 @@ def test_featureflags_integration_asyncio( events = capture_events() # Capture an eval before we split isolation scopes. - flags_integration = sentry_sdk.get_client().get_integration(FeatureFlagsIntegration) - flags_integration.set_flag("hello", False) + add_flag("hello", False) async def task(flag_key): # Creates a new isolation scope for the thread. # This means the evaluations in each task are captured separately. with sentry_sdk.isolation_scope(): - flags_integration = sentry_sdk.get_client().get_integration( - FeatureFlagsIntegration - ) - flags_integration.set_flag(flag_key, False) + add_flag(flag_key, False) # use a tag to identify to identify events later on sentry_sdk.set_tag("task_id", flag_key) sentry_sdk.capture_exception(Exception("something wrong!"))