fix: Enrich captured events with locally evaluated flags#229
Open
Josh-IE wants to merge 2 commits intoPostHog:masterfrom
Open
fix: Enrich captured events with locally evaluated flags#229Josh-IE wants to merge 2 commits intoPostHog:masterfrom
Josh-IE wants to merge 2 commits intoPostHog:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
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
/flagsor/decideendpoints when local evaluation fails - Added comprehensive test coverage in
test_client.pyfor local flag evaluation scenarios - Ensured feature flag data is included in event properties regardless of
send_feature_flagssetting when local flags exist - Added proper error handling for cases where
personal_api_keyis 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 /decideclient.feature_flagsis set, the feature flags on the client is evaluated and sent with the event, regardless of thesend_feature_flagssettingsend_feature_flags=True, feature flags data is retrieved from/api/feature_flag/local_evaluationand evaluated locally, and sent with the event/flags or /decideendpointpersonal_api_keyis not set, local evaluation is disabled and instead the/flags or /decideendpoint is called