Skip to content

Ruby: Add OpenFeature provider#132

Merged
msiebert merged 17 commits intomasterfrom
msiebert-openfeature-provider
Apr 9, 2026
Merged

Ruby: Add OpenFeature provider#132
msiebert merged 17 commits intomasterfrom
msiebert-openfeature-provider

Conversation

@msiebert
Copy link
Copy Markdown
Contributor

Summary

  • Adds an OpenFeature-compatible provider as a separate gem (mixpanel-openfeature) in the openfeature-provider/ directory
  • Wraps either LocalFlagsProvider or RemoteFlagsProvider via a single Mixpanel::OpenFeature::Provider class
  • Implements the OpenFeature Ruby SDK duck-type interface: fetch_boolean_value, fetch_string_value, fetch_number_value, fetch_integer_value, fetch_float_value, fetch_object_value

Design decisions

  • Identity check for flag-not-found detection: passes a fallback SelectedVariant to get_variant and uses equal? (object identity) to detect when the flag was not found
  • Reason codes: STATIC for successful evaluations, ERROR for all failure cases
  • Error codes: PROVIDER_NOT_READY, FLAG_NOT_FOUND, TYPE_MISMATCH
  • Variant key passthrough: successful resolutions include variant: result.variant_key in ResolutionDetails
  • Context forwarding: evaluation_context is converted and forwarded to get_variant
  • Provider readiness: uses respond_to?(:are_flags_ready) so remote providers are treated as always ready
  • Type coercion: float-to-int when no fractional part, int-to-float promotion
  • shutdown is a no-op: Mixpanel SDK manages its own lifecycle
  • targetingKey has no special meaning: included in context as a regular property

Test coverage

37 RSpec tests covering all 6 flag types, type coercion, all 3 error codes, variant key passthrough, context forwarding, remote provider readiness, lifecycle, and metadata.

Test plan

  • bundle exec rspec spec/ — 37 examples, 0 failures

Generated with Claude Code

Implement an OpenFeature-compatible provider as a separate gem
(mixpanel-openfeature) that wraps the existing Mixpanel flags providers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert self-assigned this Mar 19, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 98.19820% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.64%. Comparing base (a3020d2) to head (a4c48c9).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
lib/mixpanel-ruby/flags/flags_provider.rb 83.33% 1 Missing ⚠️
lib/mixpanel-ruby/flags/local_flags_provider.rb 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #132      +/-   ##
==========================================
+ Coverage   96.29%   96.64%   +0.34%     
==========================================
  Files          12       14       +2     
  Lines         567      655      +88     
==========================================
+ Hits          546      633      +87     
- Misses         21       22       +1     
Flag Coverage Δ
openfeature 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

msiebert and others added 3 commits March 20, 2026 11:05
Adds begin/rescue for SDK exceptions in provider, plus tests for
exception handling and null variant key behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use camelCase 'targetingKey' instead of snake_case 'targeting_key' to
match the key name Java and Go SDKs receive from their OpenFeature
SDKs' built-in flattening.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- shutdown now delegates to underlying flags provider
- Add shutdown to FlagsProvider (no-op) and LocalFlagsProvider (stops polling)
- Explicitly pass report_exposure: true to get_variant
- Add context value unwrapping with whole-number float→int conversion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert changed the title Add OpenFeature provider Ruby: Add OpenFeature provider Mar 31, 2026
msiebert and others added 4 commits April 1, 2026 12:49
Fix bug where ServerError was incorrectly caught and re-raised as
ConnectionError in call_flags_endpoint. Use dig for nested hash
access, each_with_object for hash construction, map(&:dup), and
simplified conditionals throughout. Simplify boolean type check
and make number case consistent in provider.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add nil guard for typed resolutions to return TYPE_MISMATCH instead of
passing nil through. Update mock signatures to capture report_exposure
keyword arg. Add exposure reporting verification test. Strengthen
shutdown test to verify delegation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Required by repo policy — all actions must use full-length commit SHAs
instead of version tags.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Aligns with the convention used by other SDKs (e.g. mixpanel-java-openfeature-provider)
where the language name is included in the package name.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert requested a review from efahk April 2, 2026 22:25
@msiebert msiebert marked this pull request as ready for review April 2, 2026 22:25
@msiebert msiebert requested review from a team and jaredmixpanel April 2, 2026 22:25
msiebert and others added 4 commits April 2, 2026 15:34
Runs the openfeature-provider test suite as a separate job across all
Ruby versions to ensure the provider is tested in CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
openfeature-sdk 0.5.1 requires Ruby >= 3.1, so Ruby 3.0 is no longer
compatible. Update the gemspec and remove 3.0 from the CI matrix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add SimpleCov with Cobertura output to the openfeature-provider test
suite and upload coverage from the test-openfeature CI job. This lets
Codecov merge coverage from both test suites, fixing the patch/project
coverage check failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Provider.from_local and Provider.from_remote accept a token and config,
create the Tracker internally, auto-start polling for local configs,
and expose the tracker via the mixpanel attr_reader.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# @param selected_variant [SelectedVariant] The selected variant
# @param context [Hash] User context (must include 'distinct_id')
# @param latency_ms [Integer, nil] Optional latency in milliseconds
def shutdown; end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The param comments got separated from the track_exposure_event call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh lol, whoops

msiebert and others added 2 commits April 7, 2026 11:09
Move shutdown method above track_exposure_event doc comments to fix
separated param annotations. Revert @flag_definitions assignment to
use a local variable for GIL-safe concurrent reads. Add tests for
from_local/from_remote factory methods and complex context type
unwrapping (floats, arrays, nested hashes) to reach 100% coverage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…found

Address review feedback: successful flag evaluations now return
TARGETING_MATCH reason instead of STATIC, and FLAG_NOT_FOUND returns
DEFAULT reason instead of ERROR. Also adds error_handler parameter
to from_local and from_remote factory methods.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
msiebert and others added 3 commits April 9, 2026 14:16
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The OpenFeature provider depends on shutdown methods and error handling
fixes added after the 3.0.0 release. Bump the main SDK version and
tighten the provider's dependency constraint to ~> 3.1. Add release
ordering documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert merged commit a780e93 into master Apr 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants