feat: implement Tracking API (spec section 6)#227
Conversation
- Add Client#track method for recording tracking events with optional evaluation context and tracking event details (spec 6.1.1.1) - Merge evaluation context in order: API → client → invocation, matching flag evaluation precedence (spec 6.1.3) - No-op when provider does not implement tracking (spec 6.1.4) - Add TrackingEventDetails class with optional numeric value and custom fields (spec 6.2.1, 6.2.2) - Add 8 spec tests covering all tracking requirements Closes #157 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Jose Colella <jose.colella@gusto.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the OpenFeature Tracking API, allowing clients to record events associated with feature flag evaluations. This enhancement provides a standardized mechanism for providers to capture user actions and other relevant data, which is crucial for experimentation and analytics. The implementation carefully adheres to the OpenFeature specification regarding context merging and ensures backward compatibility for providers that do not yet support tracking. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully implements the Tracking API as described in section 6 of the OpenFeature specification. The changes are well-structured and include comprehensive tests. I have one suggestion to improve the implementation's adherence to the specification by adding a type check.
| def initialize(value: nil, **fields) | ||
| @value = value | ||
| @fields = fields.transform_keys(&:to_s) | ||
| end |
There was a problem hiding this comment.
The OpenFeature specification requires the optional value in TrackingEventDetails to be numeric (spec 6.2.1). The current implementation allows any type for value. To ensure compliance and prevent potential issues with providers expecting a numeric type, I recommend adding a type check in the initializer. This will make the implementation more robust and prevent invalid data from being passed to providers.
def initialize(value: nil, **fields)
if !value.nil? && !value.is_a?(Numeric)
raise ArgumentError, "Tracking event `value` must be a Numeric, but was #{value.class}"
end
@value = value
@fields = fields.transform_keys(&:to_s)
end
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
==========================================
+ Coverage 99.36% 99.37% +0.01%
==========================================
Files 26 27 +1
Lines 632 644 +12
==========================================
+ Hits 628 640 +12
Misses 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Spec 6.2.1 requires the value to be numeric. Add ArgumentError when a non-Numeric value is provided. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Jose Colella <jose.colella@gusto.com>
|
Re: numeric type check suggestion Fixed in d2190e0. Added 🤖 Jose's AI agent |
Summary
Implements the Tracking API from the OpenFeature specification (section 6), enabling providers to associate user actions with feature flag evaluations for experimentation.
Client#track(event_name, evaluation_context:, tracking_event_details:)— records tracking events with the dynamic-context paradigm (spec 6.1.1.1)track— no breaking changes to existing providers (spec 6.1.4)TrackingEventDetailsclass with optional numericvalueand customfields(spec 6.2.1, 6.2.2)Closes #157
Spec References
Part of the spec compliance roadmap: #220
Test plan
bundle exec rspec spec/specification/tracking_spec.rb— 8 examples, 0 failuresbundle exec rspec— 359 examples, 0 failuresbundle exec standardrb— no offenses🤖 Jose's AI agent