Class: Datadog::OpenFeature::Provider
- Inherits:
-
Object
- Object
- Datadog::OpenFeature::Provider
- Defined in:
- lib/datadog/open_feature/provider.rb
Overview
OpenFeature feature flagging provider backed by Datadog Remote Configuration.
Implementation follows the OpenFeature contract of Provider SDK. For details see:
- https://github.com/open-feature/ruby-sdk/blob/v0.4.1/README.md#develop-a-provider
- https://github.com/open-feature/ruby-sdk/blob/v0.4.1/lib/open_feature/sdk/provider/no_op_provider.rb
In the example below you can see how to configure the OpenFeature SDK github.com/open-feature/ruby-sdk to use the Datadog feature flags provider.
Example:
Make sure to enable Remote Configuration and OpenFeature in the Datadog configuration.
```ruby
# FILE: initializers/datadog.rb
Datadog.configure do |config|
config.remote.enabled = true
config.open_feature.enabled = true
end
```
And configure the OpenFeature SDK to use the Datadog feature flagging provider.
```ruby
# FILE: initializers/open_feature.rb
require 'open_feature/sdk'
require 'datadog/open_feature/provider'
OpenFeature::SDK.configure do |config|
config.set_provider(Datadog::OpenFeature::Provider.new)
end
```
Now you can create OpenFeature SDK client and use it to fetch feature flag values.
```ruby
client = OpenFeature::SDK.build_client
context = OpenFeature::SDK::EvaluationContext.new('email' => '[email protected]')
client.fetch_string_value(
flag_key: 'banner', default_value: 'Greetings!', evaluation_context: context
)
# => 'Welcome back!'
```
Constant Summary collapse
- NAME =
'Datadog Feature Flagging Provider'
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #init ⇒ Object
-
#initialize ⇒ Provider
constructor
A new instance of Provider.
- #shutdown ⇒ Object
Constructor Details
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
56 57 58 |
# File 'lib/datadog/open_feature/provider.rb', line 56 def @metadata end |
Instance Method Details
#fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
70 71 72 |
# File 'lib/datadog/open_feature/provider.rb', line 70 def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) evaluate(flag_key, default_value: default_value, expected_type: :boolean, evaluation_context: evaluation_context) end |
#fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
86 87 88 |
# File 'lib/datadog/open_feature/provider.rb', line 86 def fetch_float_value(flag_key:, default_value:, evaluation_context: nil) evaluate(flag_key, default_value: default_value, expected_type: :float, evaluation_context: evaluation_context) end |
#fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
82 83 84 |
# File 'lib/datadog/open_feature/provider.rb', line 82 def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) evaluate(flag_key, default_value: default_value, expected_type: :integer, evaluation_context: evaluation_context) end |
#fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
78 79 80 |
# File 'lib/datadog/open_feature/provider.rb', line 78 def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) evaluate(flag_key, default_value: default_value, expected_type: :number, evaluation_context: evaluation_context) end |
#fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
90 91 92 |
# File 'lib/datadog/open_feature/provider.rb', line 90 def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) evaluate(flag_key, default_value: default_value, expected_type: :object, evaluation_context: evaluation_context) end |
#fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
74 75 76 |
# File 'lib/datadog/open_feature/provider.rb', line 74 def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) evaluate(flag_key, default_value: default_value, expected_type: :string, evaluation_context: evaluation_context) end |
#init ⇒ Object
62 63 64 |
# File 'lib/datadog/open_feature/provider.rb', line 62 def init # no-op end |
#shutdown ⇒ Object
66 67 68 |
# File 'lib/datadog/open_feature/provider.rb', line 66 def shutdown # no-op end |