Skip to content

Commit

Permalink
Move api to top-level, rename to add_flag
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Dec 6, 2024
1 parent 921b133 commit 4651b6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
8 changes: 4 additions & 4 deletions sentry_sdk/integrations/featureflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
25 changes: 8 additions & 17 deletions tests/integrations/featureflags/test_featureflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"))
Expand All @@ -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!"))
Expand Down Expand Up @@ -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!"))
Expand Down

0 comments on commit 4651b6a

Please sign in to comment.