Skip to content

feat: implement Tracking API (spec section 6)#227

Merged
josecolella merged 2 commits intomainfrom
feat/tracking-api
Mar 5, 2026
Merged

feat: implement Tracking API (spec section 6)#227
josecolella merged 2 commits intomainfrom
feat/tracking-api

Conversation

@josecolella
Copy link
Collaborator

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)
  • Evaluation context is merged in order: API → client → invocation, matching flag evaluation precedence (spec 6.1.3)
  • No-op when provider does not implement track — no breaking changes to existing providers (spec 6.1.4)
  • TrackingEventDetails class with optional numeric value and custom fields (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 failures
  • bundle exec rspec — 359 examples, 0 failures
  • bundle exec standardrb — no offenses

🤖 Jose's AI agent

- 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>
@josecolella josecolella requested a review from a team as a code owner March 5, 2026 17:26
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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

  • Tracking API Implementation: Implemented the Client#track function, enabling the recording of tracking events with a dynamic-context paradigm as specified in OpenFeature spec 6.1.1.1.
  • Evaluation Context Merging: Ensured that the evaluation context for tracking events is merged in the specified order: API context, then client context, and finally invocation context, matching the flag evaluation precedence (spec 6.1.3).
  • No-op for Non-Tracking Providers: Designed the track function to gracefully perform no operation if the currently configured provider does not implement tracking, preventing breaking changes for existing providers (spec 6.1.4).
  • TrackingEventDetails Class: Introduced a new TrackingEventDetails class to encapsulate tracking event data, supporting an optional numeric value (spec 6.2.1) and custom fields with string keys (spec 6.2.2).
Changelog
  • lib/open_feature/sdk/api.rb
    • Required the new tracking_event_details class to make it available within the SDK.
  • lib/open_feature/sdk/client.rb
    • Added the track method to the Client class, accepting an event name, optional evaluation context, and optional tracking event details.
    • Implemented logic to merge API, client, and invocation contexts for tracking events.
    • Included a check to ensure the track method is a no-op if the active provider does not define its own track method.
  • lib/open_feature/sdk/tracking_event_details.rb
    • Created the TrackingEventDetails class to structure tracking event data.
    • Defined value as an optional numeric attribute for tracking event details.
    • Implemented support for custom fields with string keys, allowing flexible additional data to be attached to tracking events.
  • spec/specification/tracking_spec.rb
    • Added a new specification test file for the Tracking API.
    • Included tests to verify the Client#track method signature and parameter handling (Condition 6.1.1.1).
    • Developed tests to confirm the correct merging order of evaluation contexts (API → client → invocation) for tracking events (Requirement 6.1.3).
    • Added tests to ensure the Client#track method performs no operation when the provider does not implement tracking (Requirement 6.1.4).
    • Created tests to validate the TrackingEventDetails class's support for an optional numeric value (Requirement 6.2.1).
    • Implemented tests to confirm TrackingEventDetails supports custom fields with string keys (Requirement 6.2.2).
    • Verified that TrackingEventDetails objects are correctly passed through to the provider's track method.
Activity
  • The author has confirmed that bundle exec rspec spec/specification/tracking_spec.rb passed with 8 examples and 0 failures.
  • The author has confirmed that bundle exec rspec passed with 359 examples and 0 failures.
  • The author has confirmed that bundle exec standardrb reported no offenses.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +13 to +16
def initialize(value: nil, **fields)
@value = value
@fields = fields.transform_keys(&:to_s)
end

Choose a reason for hiding this comment

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

medium

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
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.37%. Comparing base (a185003) to head (654d286).

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.
📢 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.

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>
@josecolella
Copy link
Collaborator Author

Re: numeric type check suggestion

Fixed in d2190e0. Added ArgumentError when value is non-nil and not Numeric, plus a test for it.

🤖 Jose's AI agent

@josecolella josecolella merged commit 5576fce into main Mar 5, 2026
4 checks passed
@josecolella josecolella deleted the feat/tracking-api branch March 5, 2026 17:49
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.

[FEATURE] Implement Tracking in Ruby

1 participant