OpenFeature Provider (Ruby)
Overview
The Mixpanel OpenFeature provider allows you to use Mixpanel Feature Flags through the standardized OpenFeature API. This provider wraps the Mixpanel Ruby SDK’s feature flags, letting you use the OpenFeature Ruby SDK with Mixpanel as the backend.
For the core Feature Flags SDK guide, see Feature Flags (Ruby).
Prerequisites
- You are on an Enterprise subscription plan
- You have the Mixpanel Ruby SDK installed
- You have your Project Token from your Mixpanel Project Settings
Installation
gem install mixpanel-openfeature-provider openfeature-sdkOr add to your Gemfile:
gem 'mixpanel-openfeature-provider'
gem 'openfeature-sdk'Usage
The provider wraps either a local or remote flags provider from the Mixpanel SDK.
With Local Evaluation
require 'mixpanel'
require 'openfeature/sdk'
require 'mixpanel/openfeature'
tracker = Mixpanel::Tracker.new('YOUR_PROJECT_TOKEN', local_flags_config: {
enable_polling: true,
polling_interval_in_seconds: 60
})
tracker.local_flags.start_polling_for_definitions
# Register the provider
OpenFeature::SDK.configure do |config|
config.set_provider(Mixpanel::OpenFeature::Provider.new(tracker.local_flags))
end
client = OpenFeature::SDK.build_client
show_new_ui = client.fetch_boolean_value(flag_key: 'new-ui', default_value: false)With Remote Evaluation
tracker = Mixpanel::Tracker.new('YOUR_PROJECT_TOKEN', remote_flags_config: {
api_host: 'api.mixpanel.com'
})
OpenFeature::SDK.configure do |config|
config.set_provider(Mixpanel::OpenFeature::Provider.new(tracker.remote_flags))
end
client = OpenFeature::SDK.build_client
variant = client.fetch_string_value(flag_key: 'checkout-flow', default_value: 'control')Supported Flag Types
| OpenFeature Method | Ruby Type |
|---|---|
fetch_boolean_value / fetch_boolean_details | TrueClass / FalseClass |
fetch_string_value / fetch_string_details | String |
fetch_integer_value / fetch_integer_details | Integer |
fetch_float_value / fetch_float_details | Float |
fetch_object_value / fetch_object_details | Hash |
Context and Identity
Context is set globally when registering the provider, not per-evaluation. Per-evaluation context passed to individual flag evaluations is ignored.
targeting_keyhas no special meaning in this provider. It is treated as a regular context property.- Identity should be managed through the Mixpanel SDK (e.g., setting
distinct_idin the context).
Error Handling
The provider returns the default value on all errors, with an error code indicating the cause:
| Error Code | Condition |
|---|---|
PROVIDER_NOT_READY | The provider has not been initialized |
FLAG_NOT_FOUND | The requested flag does not exist |
TYPE_MISMATCH | The flag value does not match the requested type |
Use fetch_details methods to inspect error codes:
details = client.fetch_boolean_details(flag_key: 'my-flag', default_value: false)
if details.error_code
puts "Flag error: #{details.error_code} - #{details.error_message}"
endLifecycle
shutdownis a no-op. The Mixpanel SDK manages its own lifecycle.- The reason code for successful evaluations is
STATIC.
Was this page useful?