Ruby implementation of the OpenFeature SDK
Repo open-feature/ruby-sdk, read from GitHub 1 min ago. open-feature has not joined Take My Repo.
open-feature/ruby-sdk is a public repo on GitHub by open-feature. Ruby implementation of the OpenFeature SDK. It declares the Apache-2.0 license on GitHub. It is written mainly in Ruby, has 43 stars and last changed on 2026-11-21. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-21.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
OpenFeature is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.
| Supported Ruby Version | OS |
|---|---|
| Ruby 3.4.x | Windows, MacOS, Linux |
| Ruby 4.0.x | Windows, MacOS, Linux |
This project supports all Ruby versions in active maintenance per the Ruby maintenance schedule.
Install the gem and add to the application's Gemfile by executing:
bundle add openfeature-sdk
If bundler is not being used to manage dependencies, install the gem by executing:
gem install openfeature-sdk
require 'open_feature/sdk' # API Initialization and configuration OpenFeature::SDK.configure do |config| # your provider of choice, which will be used as the default provider config.set_provider(OpenFeature::SDK::Provider::InMemoryProvider.new( { "flag1" => true, "flag2" => 1, # Variant flags report a variant and reason, and can target on the evaluation context "flag3" => OpenFeature::SDK::Provider::InMemoryProvider::Flag.new( variants: {"on" => true, "off" => false}, default_variant: "off", context_evaluator: ->(ctx) { "on" if ctx&.targeting_key == "beta-user" } ) } )) end # Create a client client = OpenFeature::SDK.build_client # fetching boolean value feature flag bool_value = client.fetch_boolean_value(flag_key: 'boolean_flag', default_value: false) # a details method is also available for more information about the flag evaluation # see `EvaluationDetails` for more info bool_details = client.fetch_boolean_details(flag_key: 'boolean_flag', default_value: false) # fetching string value feature flag string_value = client.fetch_string_value(flag_key: 'string_flag', default_value: 'default') # fetching number value feature flag float_value = client.fetch_number_value(flag_key: 'number_value', default_value: 1.0) integer_value = client.fetch_number_value(flag_key: 'number_value', default_value: 1) # get an object value object = client.fetch_object_value(flag_key: 'object_value', default_value: { name: 'object'})
| Status | Features | Description |
|---|---|---|
| โ | Providers | Integrate with a commercial, open source, or in-house feature management tool. |
| โ | Targeting | Contextually-aware flag evaluation using evaluation context. |
| โ | Hooks | Add functionality to various stages of the flag evaluation life-cycle. |
| โ | Logging | Integrate with popular logging packages. |
| โ | Domains | Logically bind clients with providers. |
| โ | Eventing | React to state changes in the provider or flag management system. |
| โ | Shutdown | Gracefully clean up a provider during application shutdown. |
| โ | Tracking | Associate user actions with feature flag evaluations for experimentation. |
| โ | Transaction Context Propagation | Set a specific evaluation context for a transaction (e.g. an HTTP request or a thread) |
| โ | Extending | Extend OpenFeature with custom providers and hooks. |
Implemented: โ | In-progress: โ ๏ธ | Not implemented yet: โ
Providers are an abstraction between a flag management system and the OpenFeature SDK. Look here for a complete list of available providers.
If the provider you're looking for hasn't been created yet, see the develop a provider section to learn how to build it yourself.
Once you've added a provider as a dependency, it can be registered with OpenFeature like this:
OpenFeature::SDK.configure do |config| # your provider of choice, which will be used as the default provider config.set_provider(OpenFeature::SDK::Provider::InMemoryProvider.new( { "v2_enabled" => true, } )) end
If you need to ensure that a provider is fully initialized before continuing, you can use set_provider_and_wait:
# Using the SDK directly begin OpenFeature::SDK.set_provider_and_wait(my_provider) puts "Provider is ready!" rescue OpenFeature::SDK::ProviderInitializationError => e puts "Provider failed to initialize: #{e.message}" puts "Error code: #{e.error_code}" # original_error contains the underlying exception that caused the initialization failure puts "Original error: #{e.original_error}" end # Domain-specific provider OpenFeature::SDK.set_provider_and_wait(my_provider, domain: "feature-flags") # Via configuration block OpenFeature::SDK.configure do |config| begin config.set_provider_and_wait(my_provider) rescue OpenFeature::SDK::ProviderInitializationError => e # Handle initialization failure end end
The set_provider_and_wait method:
init method to complete successfullyProviderInitializationError if initialization fails or times outoriginal_error field contains the underlying exception that caused the initialization failureset_providerIn some situations, it may be beneficial to register multiple providers in the same application. This is possible using domains, which is covered in more detail below.
Sometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location. In OpenFeature, we refer to this as targeting. If the flag management system you're using supports targeting, you can provide the input data using the evaluation context.
OpenFeature::SDK.configure do |config| # you can set a global evaluation context here config.evaluation_context = OpenFeature::SDK::EvaluationContext.new("host" => "myhost.com") end # Evaluation context can be set on a client as well client_with_context = OpenFeature::SDK.build_client( evaluation_context: OpenFeature::SDK::EvaluationContext.new("controller_name" => "admin") ) # Invocation evaluation context can also be passed in during flag evaluation. # During flag evaluation, invocation context takes precedence over client context # which takes precedence over API (aka global) context. bool_value = client.fetch_boolean_value( flag_key: 'boolean_flag', default_value: false, evaluation_context: OpenFeature::SDK::EvaluationContext.new("is_friday" => true) )
Hooks allow for custom logic to be added at well-defined points of the flag evaluation life-cycle. Look here for a complete list of available hooks. If the hook you're looking for hasn't been created yet, see the develop a hook section to learn how to build it yourself.
Hooks can be registered at the global, client, or flag invocation level.
# Define a hook class MyHook include OpenFeature::SDK::Hooks::Hook def before(hook_context:, hints:) puts "Evaluating flag: #{hook_context.flag_key}" nil end def after(hook_context:, evaluation_details:, hints:) puts "Flag #{hook_context.flag_key} evaluated to: #{evaluation_details.value}" end def error(hook_context:, exception:, hints:) puts "Error evaluating #{hook_context.flag_key}: #{exception.message}" end def finally(hook_context:, evaluation_details:, hints:) puts "Evaluation complete for #{hook_context.flag_key}" end end # Register at the API (global) level OpenFeature::SDK.hooks << MyHook.new # Register at the client level client = OpenFeature::SDK.build_client client.hooks << MyHook.new # Register at the invocation level client.fetch_boolean_value( flag_key: "my-flag", default_value: false, hooks: [MyHook.new] )
The SDK includes a built-in LoggingHook that provides structured log output for flag evaluations. It logs at the before, after, and error stages of the hook lifecycle.
# Use the SDK's default logger (from Configuration) OpenFeature::SDK.hooks << OpenFeature::SDK::Hooks::LoggingHook.new # Or provide your own logger logger = Logger.new($stdout) OpenFeature::SDK.hooks << OpenFeature::SDK::Hooks::LoggingHook.new(logger: logger) # Optionally include evaluation context in log output OpenFeature::SDK.hooks << OpenFeature::SDK::Hooks::LoggingHook.new( logger: logger, include_evaluation_context: true )
Log output uses a structured key=value format:
stage=before domain=my-domain provider_name=my-provider flag_key=my-flag default_value=falsereason, variant, and valueerror_code and error_messageClients can be assigned to a domain. A domain is a logical identifier which can be used to associate clients with a particular provider.
If a domain has no associated provider, the default provider is used.
Clients look up their domain's provider on every call, so a client created before set_provider follows the new binding.
OpenFeature::SDK.configure do |config| config.set_provider(OpenFeature::SDK::Provider::NoOpProvider.new, domain: "legacy_flags") end # Create a client for a different domain, this will use the provider assigned to that domain legacy_flag_client = OpenFeature::SDK.build_client(domain: "legacy_flags")
Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.
Providers emit initialization events (PROVIDER_READY on success, PROVIDER_ERROR on failure) from init.
A provider without init is READY as soon as it's registered, and its PROVIDER_READY handlers run before set_provider returns.
For providers that define init but not emits_lifecycle_events? returning true, the SDK emits PROVIDER_READY after init returns and PROVIDER_ERROR if it raises.
That path is deprecated (spec Appendix E), and the SDK logs a deprecation warning once per provider class to its configured logger.
Handlers for events a provider emits from init run while init is still in progress, so they can't call set_provider_and_wait for that same provider.
Some providers emit additional events: PROVIDER_CONFIGURATION_CHANGED, PROVIDER_STALE, PROVIDER_RECONCILING and PROVIDER_CONTEXT_CHANGED.
Handlers receive a hash with the provider_name and any details the provider sent, such as message or error_code.
Please refer to the documentation of the provider you're using to see what events are supported.
# Register event handlers at the API (global) level ready_handler = ->(event_details) do puts "Provider #{event_details[:provider_name]} is ready!" end OpenFeature::SDK.add_handler(OpenFeature::SDK::ProviderEvent::PROVIDER_READY, ready_handler) # Providers emit events using the EventEmitter mixin: lifecycle events from init, and spontaneous # events to signal internal state changes like configuration updates. class MyEventAwareProvider include OpenFeature::SDK::Provider::EventEmitter def emits_lifecycle_events? = true def init(evaluation_context) # Start background process to monitor for configuration changes start_background_process emit_event(OpenFeature::SDK::ProviderEvent::PROVIDER_READY) end def start_background_process Thread.new do # Monitor for configuration changes and emit events when they occur if configuration_changed? emit_event( OpenFeature::SDK::ProviderEvent::PROVIDER_CONFIGURATION_CHANGED, message: "Flag configuration updated" ) end end end end # Remove specific handlers when no longer needed OpenFeature::SDK.remove_handler(OpenFeature::SDK::ProviderEvent::PROVIDER_READY, ready_handler)
The OpenFeature API provides a shutdown method to perform cleanup of all registered providers.
This should only be called when your application is in the process of shutting down.
# Shut down all registered providers and clear state OpenFeature::SDK.shutdown
The SDK also shuts down a replaced provider once no domain uses it. Events from shut-down providers are ignored.
Individual providers can implement a shutdown method to perform cleanup:
class MyProvider def shutdown # Perform any shutdown/reclamation steps with flag management system here end end
The tracking API allows you to use OpenFeature abstractions and objects to associate user actions with feature flag evaluations.
This is essential for robust experimentation powered by feature flags.
For example, a flag enhancing the appearance of a UI component might drive user engagement to a new feature; to test this hypothesis, telemetry collected by a hook or provider can be associated with telemetry reported in the client's track function.
client = OpenFeature::SDK.build_client # Simple tracking event client.track("checkout_completed") # With evaluation context client.track( "purchase", evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "user-123") ) # With tracking event details (optional numeric value + custom fields) details = OpenFeature::SDK::TrackingEventDetails.new( value: 99.99, plan: "premium", currency: "USD" ) client.track("subscription", tracking_event_details: details)
Note that some providers may not support tracking; if the provider does not implement a track method, the call is a no-op.
Check the documentation for your provider for more information.
Transaction context is a container for transaction-specific evaluation context (e.g. user id, user agent, IP). Transaction context can be set where specific data is available (e.g. an auth service or request handler) and by using the transaction context propagator it will automatically be applied to all flag evaluations within a transaction (e.g. a request or thread).
The SDK ships with a ThreadLocalTransactionContextPropagator that stores context in Thread.current:
# Set up the propagator OpenFeature::SDK.set_transaction_context_propagator( OpenFeature::SDK::ThreadLocalTransactionContextPropagator.new ) # Set transaction context (e.g. in a request middleware) OpenFeature::SDK.set_transaction_context( OpenFeature::SDK::EvaluationContext.new(targeting_key: "user-123", "email" => "user@example.com") ) # Transaction context is automatically merged during flag evaluation. # Merge precedence: invocation > client > transaction > API (global) client = OpenFeature::SDK.build_client client.fetch_boolean_value(flag_key: "my-flag", default_value: false)
You can implement a custom propagator by including the TransactionContextPropagator module:
class MyRequestScopedPropagator include OpenFeature::SDK::TransactionContextPropagator def set_transaction_context(evaluation_context) # Store context in your request-scoped storage RequestStore[:openfeature_context] = evaluation_context end def get_transaction_context RequestStore[:openfeature_context] end end
OpenFeature::SDK is a global singleton. Some applications need more than one independent API in a process, for example separately developed modules that each need their own provider, or tests that run in parallel. Require the factory explicitly to create one:
require "open_feature/sdk/isolated" api = OpenFeature::SDK::Isolated.create_api api.set_provider_and_wait(MyProvider.new) client = api.build_client client.fetch_boolean_value(flag_key: "my-flag", default_value: false)
Each instance has its own providers, hooks, evaluation context, event handlers, transaction context propagator and shutdown, and shares none of them with OpenFeature::SDK or other instances.
Build its clients with api.build_client; OpenFeature::SDK::Client.new binds to the global API.
Prefer the global API unless you need this.
A provider instance should be registered with only one API at a time.
Registering a provider that includes OpenFeature::SDK::Provider::EventEmitter with a second API raises ArgumentError; other providers can't be detected.
Once the first API replaces the provider or shuts down, it can be registered with another.
A LoggingHook created without logger: logs to the global API's logger, even when added to an isolated API. Pass logger: to use another.
To develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency.
This can be a new repository or included in the existing contrib repository available under the OpenFeature organization.
Youโll then need to write the provider by implementing the Provider duck.
class MyProvider include OpenFeature::SDK::Provider::EventEmitter # Tells the SDK that init emits PROVIDER_READY/PROVIDER_ERROR itself. def emits_lifecycle_events? = true # Optional: a provider without init is READY as soon as it's registered. # Both arguments are optional; declare only the ones you need. # `domain` is the domain the provider was bound to, or nil for the default provider. def init(evaluation_context = nil, domain: nil) # Perform any initialization steps with flag management system here, then emit PROVIDER_READY. # Return value is ignored # **Note** The OpenFeature spec defines a lifecycle method called `initialize` to be called when a new provider is set. # To avoid conflicting with the Ruby `initialize` method, this method should be named `init` when creating a provider. emit_event(OpenFeature::SDK::ProviderEvent::PROVIDER_READY) rescue => e emit_event(OpenFeature::SDK::ProviderEvent::PROVIDER_ERROR, error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL, message: e.message) raise end # Optional: return true if this provider keeps state for a single domain. # The SDK then raises ArgumentError if the same instance is bound to a second domain. def domain_scoped? false end def shutdown # Perform any shutdown/reclamation steps with flag management system here # Return value is ignored end # Optional: hooks the SDK runs on every evaluation that uses this provider (spec 2.3.1). # They run after API, client and invocation hooks in the before stage, and first in the after, error and finally stages. def hooks [] end def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) # Retrieve a boolean value from provider source # To signal an error, return ResolutionDetails with an error_code, or raise # OpenFeature::SDK::EvaluationError.new("message", error_code: OpenFeature::SDK::Provider::ErrorCode::FLAG_NOT_FOUND) end def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) # Retrieve a string value from provider source end def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) # Retrieve a numeric value from provider source end def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) # Retrieve a integer value from provider source end def fetch_float_value(flag_key:, default_value:, evaluation_context: nil) # Retrieve a float value from provider source end def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) # Retrieve a hash value from provider source end # Optional: implement tracking support (spec 6.1.4) # If not defined, Client#track is a no-op def track(tracking_event_name, evaluation_context:, tracking_event_details:) # Record a tracking event with your flag management system end end
Built a new provider? Let us know so we can add it to the docs!
To develop a hook, you need to create a new project and include the OpenFeature SDK as a dependency.
This can be a new repository or included in the existing contrib repository available under the OpenFeature organization.
Implement your own hook by including the OpenFeature::SDK::Hooks::Hook module.
You only need to define the stages you care about โ unimplemented stages are no-ops by default.
class MyLoggingHook include OpenFeature::SDK::Hooks::Hook def before(hook_context:, hints:) puts "Evaluating #{hook_context.flag_key}" nil # Return nil or an EvaluationContext to merge end def after(hook_context:, evaluation_details:, hints:) puts "Result: #{evaluation_details.value}" end # error and finally are optional โ only define what you need end
Hooks can read the hook context and hints but not change them:
before hooks can change the evaluation context: return an EvaluationContext for the SDK to merge in, or assign hook_context.evaluation_context. By the time after, error and finally run, it's a deep-frozen copy, so assigning it or changing its values raises FrozenError. Your own context isn't frozen.utc and localtime still work, and a hash's default proc isn't copied.Built a new hook? Let us know so we can add it to the docs!
Interested in contributing? Great, we'd love your help! To get started, take a look at the CONTRIBUTING guide.
Made with contrib.rocks.
open-feature/ruby-sdk is a public repo on GitHub by open-feature. Ruby implementation of the OpenFeature SDK.
It declares the Apache-2.0 license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-21. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Build infinite canvas apps in React with the tldraw SDK. World's best, top-most agent recommended #1 five star SDK.
:globe_with_meridians: Jekyll is a blog-aware static site generator in Ruby
Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/open-feature/ruby-sdkTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.