-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ivana/populate-tox-2
- Loading branch information
Showing
16 changed files
with
661 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ pre-commit # local linting | |
httpcore | ||
openfeature-sdk | ||
launchdarkly-server-sdk | ||
UnleashClient | ||
typer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from functools import wraps | ||
from typing import Any | ||
|
||
import sentry_sdk | ||
from sentry_sdk.flag_utils import flag_error_processor | ||
from sentry_sdk.integrations import Integration, DidNotEnable | ||
|
||
try: | ||
from UnleashClient import UnleashClient | ||
except ImportError: | ||
raise DidNotEnable("UnleashClient is not installed") | ||
|
||
|
||
class UnleashIntegration(Integration): | ||
identifier = "unleash" | ||
|
||
@staticmethod | ||
def setup_once(): | ||
# type: () -> None | ||
# Wrap and patch evaluation methods (instance methods) | ||
old_is_enabled = UnleashClient.is_enabled | ||
old_get_variant = UnleashClient.get_variant | ||
|
||
@wraps(old_is_enabled) | ||
def sentry_is_enabled(self, feature, *args, **kwargs): | ||
# type: (UnleashClient, str, *Any, **Any) -> Any | ||
enabled = old_is_enabled(self, feature, *args, **kwargs) | ||
|
||
# We have no way of knowing what type of unleash feature this is, so we have to treat | ||
# it as a boolean / toggle feature. | ||
flags = sentry_sdk.get_current_scope().flags | ||
flags.set(feature, enabled) | ||
|
||
return enabled | ||
|
||
@wraps(old_get_variant) | ||
def sentry_get_variant(self, feature, *args, **kwargs): | ||
# type: (UnleashClient, str, *Any, **Any) -> Any | ||
variant = old_get_variant(self, feature, *args, **kwargs) | ||
enabled = variant.get("enabled", False) | ||
|
||
# Payloads are not always used as the feature's value for application logic. They | ||
# may be used for metrics or debugging context instead. Therefore, we treat every | ||
# variant as a boolean toggle, using the `enabled` field. | ||
flags = sentry_sdk.get_current_scope().flags | ||
flags.set(feature, enabled) | ||
|
||
return variant | ||
|
||
UnleashClient.is_enabled = sentry_is_enabled # type: ignore | ||
UnleashClient.get_variant = sentry_get_variant # type: ignore | ||
|
||
# Error processor | ||
scope = sentry_sdk.get_current_scope() | ||
scope.add_error_processor(flag_error_processor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import pytest | ||
import jsonschema | ||
|
||
|
||
try: | ||
import gevent | ||
except ImportError: | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.