DocsTracking MethodsSDKsRubyOpenFeature Provider (Ruby)

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

Installation

gem install mixpanel-openfeature-provider openfeature-sdk

Or 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 MethodRuby Type
fetch_boolean_value / fetch_boolean_detailsTrueClass / FalseClass
fetch_string_value / fetch_string_detailsString
fetch_integer_value / fetch_integer_detailsInteger
fetch_float_value / fetch_float_detailsFloat
fetch_object_value / fetch_object_detailsHash

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_key has 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_id in the context).

Error Handling

The provider returns the default value on all errors, with an error code indicating the cause:

Error CodeCondition
PROVIDER_NOT_READYThe provider has not been initialized
FLAG_NOT_FOUNDThe requested flag does not exist
TYPE_MISMATCHThe 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}"
end

Lifecycle

  • shutdown is a no-op. The Mixpanel SDK manages its own lifecycle.
  • The reason code for successful evaluations is STATIC.

Was this page useful?