Skip to content

fix: Enrich captured events with locally evaluated flags #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Josh-IE
Copy link

@Josh-IE Josh-IE commented Apr 24, 2025

Problem

PostHog/posthog#31373

Changes

When capturing an event and send_feature_flags=True, use locally evaluated feature flag data, before falling back to the /flags or /decide

  • if client.feature_flags is set, the feature flags on the client is evaluated and sent with the event, regardless of the send_feature_flags setting
    • if the local evaluation fails, the capture event is sent without feature flags
  • if send_feature_flags=True, feature flags data is retrieved from /api/feature_flag/local_evaluation and evaluated locally, and sent with the event
    • if the local evaluation fails, it falls back to the /flags or /decide endpoint
  • if personal_api_key is not set, local evaluation is disabled and instead the /flags or /decide endpoint is called

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds functionality to enrich captured events with locally evaluated feature flags, improving performance by reducing API calls when possible.

  • Added local feature flag evaluation in capture() method to avoid unnecessary API calls when flags are already loaded
  • Implemented fallback behavior to /flags or /decide endpoints when local evaluation fails
  • Added comprehensive test coverage in test_client.py for local flag evaluation scenarios
  • Ensured feature flag data is included in event properties regardless of send_feature_flags setting when local flags exist
  • Added proper error handling for cases where personal_api_key is not set, defaulting to API calls

💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

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.

1 participant