Skip to content

Commit 4651b6a

Browse files
committed
Move api to top-level, rename to add_flag
1 parent 921b133 commit 4651b6a

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

sentry_sdk/integrations/featureflags.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def setup_once():
1212
scope = sentry_sdk.get_current_scope()
1313
scope.add_error_processor(flag_error_processor)
1414

15-
@staticmethod
16-
def set_flag(flag: str, result: bool):
17-
flags = sentry_sdk.get_current_scope().flags
18-
flags.set(flag, result)
15+
16+
def add_flag(flag: str, result: bool):
17+
flags = sentry_sdk.get_current_scope().flags
18+
flags.set(flag, result)

tests/integrations/featureflags/test_featureflags.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import sentry_sdk
77
from sentry_sdk.integrations import _processed_integrations, _installed_integrations
8-
from sentry_sdk.integrations.featureflags import FeatureFlagsIntegration
8+
from sentry_sdk.integrations.featureflags import FeatureFlagsIntegration, add_flag
99

1010

1111
@pytest.fixture
@@ -22,11 +22,10 @@ def inner(identifier):
2222
def test_featureflags_integration(sentry_init, capture_events, uninstall_integration):
2323
uninstall_integration(FeatureFlagsIntegration.identifier)
2424
sentry_init(integrations=[FeatureFlagsIntegration()])
25-
flags_integration = sentry_sdk.get_client().get_integration(FeatureFlagsIntegration)
2625

27-
flags_integration.set_flag("hello", False)
28-
flags_integration.set_flag("world", True)
29-
flags_integration.set_flag("other", False)
26+
add_flag("hello", False)
27+
add_flag("world", True)
28+
add_flag("other", False)
3029

3130
events = capture_events()
3231
sentry_sdk.capture_exception(Exception("something wrong!"))
@@ -49,17 +48,13 @@ def test_featureflags_integration_threaded(
4948
events = capture_events()
5049

5150
# Capture an eval before we split isolation scopes.
52-
flags_integration = sentry_sdk.get_client().get_integration(FeatureFlagsIntegration)
53-
flags_integration.set_flag("hello", False)
51+
add_flag("hello", False)
5452

5553
def task(flag_key):
5654
# Creates a new isolation scope for the thread.
5755
# This means the evaluations in each task are captured separately.
5856
with sentry_sdk.isolation_scope():
59-
flags_integration = sentry_sdk.get_client().get_integration(
60-
FeatureFlagsIntegration
61-
)
62-
flags_integration.set_flag(flag_key, False)
57+
add_flag(flag_key, False)
6358
# use a tag to identify to identify events later on
6459
sentry_sdk.set_tag("task_id", flag_key)
6560
sentry_sdk.capture_exception(Exception("something wrong!"))
@@ -102,17 +97,13 @@ def test_featureflags_integration_asyncio(
10297
events = capture_events()
10398

10499
# Capture an eval before we split isolation scopes.
105-
flags_integration = sentry_sdk.get_client().get_integration(FeatureFlagsIntegration)
106-
flags_integration.set_flag("hello", False)
100+
add_flag("hello", False)
107101

108102
async def task(flag_key):
109103
# Creates a new isolation scope for the thread.
110104
# This means the evaluations in each task are captured separately.
111105
with sentry_sdk.isolation_scope():
112-
flags_integration = sentry_sdk.get_client().get_integration(
113-
FeatureFlagsIntegration
114-
)
115-
flags_integration.set_flag(flag_key, False)
106+
add_flag(flag_key, False)
116107
# use a tag to identify to identify events later on
117108
sentry_sdk.set_tag("task_id", flag_key)
118109
sentry_sdk.capture_exception(Exception("something wrong!"))

0 commit comments

Comments
 (0)