11from functools import wraps
2+ from typing import TYPE_CHECKING
23
34import sentry_sdk
45from sentry_sdk .flag_utils import flag_error_processor
5- from sentry_sdk .integrations import Integration , DidNotEnable
6-
7- from typing import TYPE_CHECKING
6+ from sentry_sdk .integrations import Integration
87
8+ from UnleashClient import UnleashClient
99
1010if TYPE_CHECKING :
11- from typing import Optional , Any
12- from UnleashClient import UnleashClient
11+ from typing import Any
1312
1413
1514class UnleashIntegration (Integration ):
1615 identifier = "unleash"
17- _unleash_client = None # type: Optional[UnleashClient]
18-
19- def __init__ (self , unleash_client ):
20- # type: (UnleashClient) -> None
21- self .__class__ ._unleash_client = unleash_client
2216
2317 @staticmethod
2418 def setup_once ():
2519 # type: () -> None
2620
2721 # Wrap and patch evaluation functions
28- client = UnleashIntegration ._unleash_client
29- if not client :
30- raise DidNotEnable ("Error finding UnleashClient instance." )
31-
32- # Instance methods (self is excluded)
33- old_is_enabled = client .is_enabled
34- old_get_variant = client .get_variant
22+ old_is_enabled = UnleashClient .is_enabled
23+ old_get_variant = UnleashClient .get_variant
3524
3625 @wraps (old_is_enabled )
37- def sentry_is_enabled (feature , * a , ** kw ):
38- # type: (str, *Any, **Any) -> Any
39- enabled = old_is_enabled (feature , * a , ** kw )
26+ def sentry_is_enabled (self , feature , * a , ** kw ):
27+ # type: (UnleashClient, str, *Any, **Any) -> Any
28+ enabled = old_is_enabled (self , feature , * a , ** kw )
4029
4130 # We have no way of knowing what type of feature this is. Have to treat it as
4231 # boolean flag. TODO: Unless we fetch a list of non-bool flags on startup..
@@ -46,9 +35,9 @@ def sentry_is_enabled(feature, *a, **kw):
4635 return enabled
4736
4837 @wraps (old_get_variant )
49- def sentry_get_variant (feature , * a , ** kw ):
50- # type: (str, *Any, **Any) -> Any
51- variant = old_get_variant (feature , * a , ** kw )
38+ def sentry_get_variant (self , feature , * a , ** kw ):
39+ # type: (UnleashClient, str, *Any, **Any) -> Any
40+ variant = old_get_variant (self , feature , * a , ** kw )
5241 enabled = variant .get ("enabled" , False )
5342 payload_type = variant .get ("payload" , {}).get ("type" )
5443
@@ -58,8 +47,8 @@ def sentry_get_variant(feature, *a, **kw):
5847
5948 return variant
6049
61- client .is_enabled = sentry_is_enabled # type: ignore
62- client .get_variant = sentry_get_variant # type: ignore
50+ UnleashClient .is_enabled = sentry_is_enabled # type: ignore
51+ UnleashClient .get_variant = sentry_get_variant # type: ignore
6352
6453 # Error processor
6554 scope = sentry_sdk .get_current_scope ()
0 commit comments