Class: Datadog::OpenFeature::ExposureHook
- Inherits:
-
Object
- Object
- Datadog::OpenFeature::ExposureHook
- Includes:
- OpenFeature::SDK::Hooks::Hook
- Defined in:
- lib/datadog/open_feature/exposure_hook.rb
Overview
An OpenFeature hook that hands each completed evaluation to a callback, with the Datadog exposure decision, so an application can record exposures in its own data store.
Register it on the OpenFeature API, a client, or an evaluation:
hook = Datadog::OpenFeature::ExposureHook.new do |evaluation|
next unless evaluation.should_send?
exposure_queue << [evaluation.flag_key, evaluation.targeting_key, evaluation.variant, evaluation.features]
end
OpenFeature::SDK.configure { |config| config.hooks << hook }
The callback runs on the evaluation thread for every evaluation of a directly registered Datadog provider, including errors and repeats. It must not block or do I/O. An exception raised by the callback never affects the evaluation: the first one is logged at warn level, later ones at debug level.
Defined Under Namespace
Classes: Evaluation
Instance Method Summary collapse
- #finally(hook_context:, evaluation_details:, **_opts) ⇒ Object
-
#initialize(callback = nil, &block) ⇒ ExposureHook
constructor
A new instance of ExposureHook.
Constructor Details
#initialize(callback = nil, &block) ⇒ ExposureHook
Returns a new instance of ExposureHook.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/datadog/open_feature/exposure_hook.rb', line 94 def initialize(callback = nil, &block) raise ArgumentError, "pass either a callback or a block, not both" if callback && block callable = callback || block raise ArgumentError, "callback must respond to #call" unless callable.respond_to?(:call) @callback = callable @failure_warning = Core::Utils::OnlyOnce.new @unsupported_provider_warning = Core::Utils::OnlyOnce.new end |
Instance Method Details
#finally(hook_context:, evaluation_details:, **_opts) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/datadog/open_feature/exposure_hook.rb', line 105 def finally(hook_context:, evaluation_details:, **_opts) return unless datadog_provider?(hook_context) @callback.call(Evaluation.new(hook_context, evaluation_details)) rescue StandardError, ScriptError => e log_callback_failure(hook_context, e) end |