2025-12-01
This commit is contained in:
+5
-9
@@ -1,6 +1,6 @@
|
||||
from typing import TYPE_CHECKING
|
||||
import sentry_sdk
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from sentry_sdk.feature_flags import add_feature_flag
|
||||
from sentry_sdk.integrations import DidNotEnable, Integration
|
||||
|
||||
try:
|
||||
@@ -8,7 +8,6 @@ try:
|
||||
from openfeature.hook import Hook
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from openfeature.flag_evaluation import FlagEvaluationDetails
|
||||
from openfeature.hook import HookContext, HookHints
|
||||
except ImportError:
|
||||
raise DidNotEnable("OpenFeature is not installed")
|
||||
@@ -25,15 +24,12 @@ class OpenFeatureIntegration(Integration):
|
||||
|
||||
|
||||
class OpenFeatureHook(Hook):
|
||||
|
||||
def after(self, hook_context, details, hints):
|
||||
# type: (HookContext, FlagEvaluationDetails[bool], HookHints) -> None
|
||||
# type: (Any, Any, Any) -> None
|
||||
if isinstance(details.value, bool):
|
||||
flags = sentry_sdk.get_current_scope().flags
|
||||
flags.set(details.flag_key, details.value)
|
||||
add_feature_flag(details.flag_key, details.value)
|
||||
|
||||
def error(self, hook_context, exception, hints):
|
||||
# type: (HookContext, Exception, HookHints) -> None
|
||||
if isinstance(hook_context.default_value, bool):
|
||||
flags = sentry_sdk.get_current_scope().flags
|
||||
flags.set(hook_context.flag_key, hook_context.default_value)
|
||||
add_feature_flag(hook_context.flag_key, hook_context.default_value)
|
||||
|
||||
Reference in New Issue
Block a user