Skip to content

Commit a153e19

Browse files
committed
Moved adding of flags context into scope
1 parent fa241c3 commit a153e19

File tree

6 files changed

+4
-34
lines changed

6 files changed

+4
-34
lines changed

sentry_sdk/flag_utils.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from typing import TYPE_CHECKING
22

3-
import sentry_sdk
43
from sentry_sdk._lru_cache import LRUCache
54

65
if TYPE_CHECKING:
7-
from typing import TypedDict, Optional
8-
from sentry_sdk._types import Event, ExcInfo
6+
from typing import TypedDict
97

108
FlagData = TypedDict("FlagData", {"flag": str, "result": bool})
119

@@ -31,10 +29,3 @@ def get(self):
3129
def set(self, flag, result):
3230
# type: (str, bool) -> None
3331
self.buffer.set(flag, result)
34-
35-
36-
def flag_error_processor(event, exc_info):
37-
# type: (Event, ExcInfo) -> Optional[Event]
38-
scope = sentry_sdk.get_current_scope()
39-
event["contexts"]["flags"] = {"values": scope.flags.get()}
40-
return event

sentry_sdk/integrations/feature_flags.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from sentry_sdk.flag_utils import flag_error_processor
2-
31
import sentry_sdk
42
from sentry_sdk.integrations import Integration
53

@@ -27,12 +25,6 @@ class FeatureFlagsIntegration(Integration):
2725

2826
identifier = "feature_flags"
2927

30-
@staticmethod
31-
def setup_once():
32-
# type: () -> None
33-
scope = sentry_sdk.get_current_scope()
34-
scope.add_error_processor(flag_error_processor)
35-
3628

3729
def add_feature_flag(flag, result):
3830
# type: (str, bool) -> None

sentry_sdk/integrations/launchdarkly.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sentry_sdk
33

44
from sentry_sdk.integrations import DidNotEnable, Integration
5-
from sentry_sdk.flag_utils import flag_error_processor
65

76
try:
87
import ldclient
@@ -38,12 +37,6 @@ def __init__(self, ld_client=None):
3837
# Register the flag collection hook with the LD client.
3938
client.add_hook(LaunchDarklyHook())
4039

41-
@staticmethod
42-
def setup_once():
43-
# type: () -> None
44-
scope = sentry_sdk.get_current_scope()
45-
scope.add_error_processor(flag_error_processor)
46-
4740

4841
class LaunchDarklyHook(Hook):
4942

sentry_sdk/integrations/openfeature.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sentry_sdk
33

44
from sentry_sdk.integrations import DidNotEnable, Integration
5-
from sentry_sdk.flag_utils import flag_error_processor
65

76
try:
87
from openfeature import api
@@ -21,9 +20,6 @@ class OpenFeatureIntegration(Integration):
2120
@staticmethod
2221
def setup_once():
2322
# type: () -> None
24-
scope = sentry_sdk.get_current_scope()
25-
scope.add_error_processor(flag_error_processor)
26-
2723
# Register the hook within the global openfeature hooks list.
2824
api.add_hooks(hooks=[OpenFeatureHook()])
2925

sentry_sdk/integrations/unleash.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Any
33

44
import sentry_sdk
5-
from sentry_sdk.flag_utils import flag_error_processor
65
from sentry_sdk.integrations import Integration, DidNotEnable
76

87
try:
@@ -49,7 +48,3 @@ def sentry_get_variant(self, feature, *args, **kwargs):
4948

5049
UnleashClient.is_enabled = sentry_is_enabled # type: ignore
5150
UnleashClient.get_variant = sentry_get_variant # type: ignore
52-
53-
# Error processor
54-
scope = sentry_sdk.get_current_scope()
55-
scope.add_error_processor(flag_error_processor)

sentry_sdk/scope.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,9 @@ def _apply_contexts_to_event(self, event, hint, options):
13781378
else:
13791379
contexts["trace"] = self.get_trace_context()
13801380

1381+
# Add "flags" context
1382+
contexts.setdefault("flags", {}).update({"values": self.flags.get()})
1383+
13811384
def _drop(self, cause, ty):
13821385
# type: (Any, str) -> Optional[Any]
13831386
logger.info("%s (%s) dropped event", ty, cause)

0 commit comments

Comments
 (0)