unleash.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. from functools import wraps
  2. from typing import Any
  3. from sentry_sdk.feature_flags import add_feature_flag
  4. from sentry_sdk.integrations import Integration, DidNotEnable
  5. try:
  6. from UnleashClient import UnleashClient
  7. except ImportError:
  8. raise DidNotEnable("UnleashClient is not installed")
  9. class UnleashIntegration(Integration):
  10. identifier = "unleash"
  11. @staticmethod
  12. def setup_once():
  13. # type: () -> None
  14. # Wrap and patch evaluation methods (class methods)
  15. old_is_enabled = UnleashClient.is_enabled
  16. @wraps(old_is_enabled)
  17. def sentry_is_enabled(self, feature, *args, **kwargs):
  18. # type: (UnleashClient, str, *Any, **Any) -> Any
  19. enabled = old_is_enabled(self, feature, *args, **kwargs)
  20. # We have no way of knowing what type of unleash feature this is, so we have to treat
  21. # it as a boolean / toggle feature.
  22. add_feature_flag(feature, enabled)
  23. return enabled
  24. UnleashClient.is_enabled = sentry_is_enabled # type: ignore