1818 raise DidNotEnable ("LaunchDarkly is not installed" )
1919
2020
21- def _get_ldclient ():
22- # type: () -> LDClient
23- try :
24- client = ldclient .get ()
25- except Exception as exc :
26- sentry_sdk .capture_exception (exc )
27- raise DidNotEnable ("Error getting LaunchDarkly client. " + str (exc ))
21+ class LaunchDarklyIntegration (Integration ):
22+ identifier = "launchdarkly"
2823
29- if client and client .is_initialized ():
30- return client
31- raise DidNotEnable ("LaunchDarkly client is not initialized" )
24+ def __init__ (self , client = None ):
25+ # type: (LDClient | None) -> None
26+ if client is None :
27+ try :
28+ client = ldclient .get () # global singleton
29+ except Exception as exc :
30+ raise DidNotEnable ("Error getting LaunchDarkly client. " + repr (exc ))
3231
32+ if not client .is_initialized ():
33+ raise DidNotEnable ("LaunchDarkly client is not initialized" )
3334
34- class LaunchDarklyIntegration ( Integration ):
35- identifier = "launchdarkly"
35+ # Register the flag collection hook with the given client.
36+ client . add_hook ( LaunchDarklyHook ())
3637
3738 @staticmethod
3839 def setup_once ():
@@ -46,10 +47,6 @@ def error_processor(event, _exc_info):
4647 scope = sentry_sdk .get_current_scope ()
4748 scope .add_error_processor (error_processor )
4849
49- # Register the hook with the global launchdarkly client.
50- client = _get_ldclient ()
51- client .add_hook (LaunchDarklyHook ())
52-
5350
5451class LaunchDarklyHook (Hook ):
5552
0 commit comments