about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-4a52a71956a8d46fcb7294ac71734504bb09bcc2.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py')
-rw-r--r--.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py b/.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py
new file mode 100644
index 00000000..cb9e9114
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/sentry_sdk/integrations/launchdarkly.py
@@ -0,0 +1,62 @@
+from typing import TYPE_CHECKING
+import sentry_sdk
+
+from sentry_sdk.integrations import DidNotEnable, Integration
+
+try:
+    import ldclient
+    from ldclient.hook import Hook, Metadata
+
+    if TYPE_CHECKING:
+        from ldclient import LDClient
+        from ldclient.hook import EvaluationSeriesContext
+        from ldclient.evaluation import EvaluationDetail
+
+        from typing import Any
+except ImportError:
+    raise DidNotEnable("LaunchDarkly is not installed")
+
+
+class LaunchDarklyIntegration(Integration):
+    identifier = "launchdarkly"
+
+    def __init__(self, ld_client=None):
+        # type: (LDClient | None) -> None
+        """
+        :param client: An initialized LDClient instance. If a client is not provided, this
+            integration will attempt to use the shared global instance.
+        """
+        try:
+            client = ld_client or ldclient.get()
+        except Exception as exc:
+            raise DidNotEnable("Error getting LaunchDarkly client. " + repr(exc))
+
+        if not client.is_initialized():
+            raise DidNotEnable("LaunchDarkly client is not initialized.")
+
+        # Register the flag collection hook with the LD client.
+        client.add_hook(LaunchDarklyHook())
+
+    @staticmethod
+    def setup_once():
+        # type: () -> None
+        pass
+
+
+class LaunchDarklyHook(Hook):
+
+    @property
+    def metadata(self):
+        # type: () -> Metadata
+        return Metadata(name="sentry-flag-auditor")
+
+    def after_evaluation(self, series_context, data, detail):
+        # type: (EvaluationSeriesContext, dict[Any, Any], EvaluationDetail) -> dict[Any, Any]
+        if isinstance(detail.value, bool):
+            flags = sentry_sdk.get_current_scope().flags
+            flags.set(series_context.key, detail.value)
+        return data
+
+    def before_evaluation(self, series_context, data):
+        # type: (EvaluationSeriesContext, dict[Any, Any]) -> dict[Any, Any]
+        return data  # No-op.