Class: Datadog::OpenFeature::Hooks::FlagEvalMetricsHook
- Inherits:
-
Object
- Object
- Datadog::OpenFeature::Hooks::FlagEvalMetricsHook
- Includes:
- OpenFeature::SDK::Hooks::Hook
- Defined in:
- lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb
Overview
Records flag evaluation metrics via OpenTelemetry hook
Compatible with OpenFeature SDK >= 0.5.0 which provides the Hooks::Hook module, but also works with older versions since the SDK uses respond_to?(:finally) to detect hook capabilities.
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns true if the OpenFeature SDK supports hooks (>= 0.5.0).
Instance Method Summary collapse
- #finally(hook_context:, evaluation_details:, **_opts) ⇒ Object
-
#initialize(metrics) ⇒ FlagEvalMetricsHook
constructor
A new instance of FlagEvalMetricsHook.
Constructor Details
#initialize(metrics) ⇒ FlagEvalMetricsHook
Returns a new instance of FlagEvalMetricsHook.
23 24 25 |
# File 'lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb', line 23 def initialize(metrics) @metrics = metrics end |
Class Method Details
.available? ⇒ Boolean
Returns true if the OpenFeature SDK supports hooks (>= 0.5.0)
19 20 21 |
# File 'lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb', line 19 def self.available? !!defined?(::OpenFeature::SDK::Hooks::Hook) end |
Instance Method Details
#finally(hook_context:, evaluation_details:, **_opts) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb', line 27 def finally(hook_context:, evaluation_details:, **_opts) metrics = @metrics return unless metrics metrics.record( hook_context.flag_key, variant: evaluation_details.variant, reason: evaluation_details.reason, error_code: evaluation_details.error_code, allocation_key: extract_allocation_key(evaluation_details), ) end |