-
Notifications
You must be signed in to change notification settings - Fork 55
fix(flags): fix the way we optimistically send feature flags with capture
methods when we have locally evaluated feature flags for a given instance
#563
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Enhanced feature flag local evaluation in PostHog Node.js client with improved property analysis and stricter controls.
- Added
getRequiredProperties
method inposthog-node/src/extensions/feature-flags/feature-flags.ts
to analyze properties needed for local evaluation - Implemented
strictLocalEvaluation
option inposthog-node/src/types.ts
for stronger control over local evaluation behavior - Enhanced
sendFeatureFlags
configuration inposthog-node/src/client.ts
to improve optimistic flag sending with capture methods - Added comprehensive test coverage in
posthog-node/test/feature-flags.spec.ts
for property requirement analysis and strict local evaluation
4 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile
if (cohortId in this.cohorts) { | ||
const cohort = this.cohorts[cohortId] | ||
this.analyzeCohortProperties(cohort, personProperties, groupProperties, groupTypes) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: could throw InconclusiveMatchError if cohort not found for consistency with other error handling
if (!cohort || !cohort.values) { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: early return should include explanation in debug mode like other similar cases
if (!cohort || !cohort.values) { | |
return | |
} | |
if (!cohort || !cohort.values) { | |
this.logMsgIfDebug(() => console.debug(`Skipping cohort analysis - cohort or cohort.values is null`)) | |
return | |
} |
describe('getRequiredProperties', () => { | ||
it('should analyze person property requirements', async () => { | ||
await posthog.reloadFeatureFlags() | ||
|
||
const requirements = posthog.getRequiredProperties('person-prop-flag') | ||
|
||
expect(requirements).toEqual({ | ||
personProperties: ['plan'], | ||
groupProperties: {}, | ||
canEvaluateLocally: true, | ||
requiresGroups: false, | ||
groupTypes: [], | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: good test coverage for analyzing property requirements, but make sure to add test for handling undefined/null person properties
describe('getRequiredProperties', () => { | |
it('should analyze person property requirements', async () => { | |
await posthog.reloadFeatureFlags() | |
const requirements = posthog.getRequiredProperties('person-prop-flag') | |
expect(requirements).toEqual({ | |
personProperties: ['plan'], | |
groupProperties: {}, | |
canEvaluateLocally: true, | |
requiresGroups: false, | |
groupTypes: [], | |
}) | |
}) | |
it('should analyze person property requirements', async () => { | |
await posthog.reloadFeatureFlags() | |
const requirements = posthog.getRequiredProperties('person-prop-flag') | |
expect(requirements).toEqual({ | |
personProperties: ['plan'], | |
groupProperties: {}, | |
canEvaluateLocally: true, | |
requiresGroups: false, | |
groupTypes: [], | |
}) | |
}) | |
it('should handle undefined/null person properties', async () => { | |
await posthog.reloadFeatureFlags() | |
const requirements = posthog.getRequiredProperties('person-prop-flag') | |
const flag = await posthog.getFeatureFlag('person-prop-flag', 'user123', { | |
onlyEvaluateLocally: true, | |
personProperties: { plan: undefined } | |
}) | |
expect(flag).toBe(false) | |
}) |
// Just test that the capture method accepts the new structure without throwing | ||
expect(() => { | ||
posthog.capture({ | ||
distinctId: 'user123', | ||
event: 'test_event', | ||
sendFeatureFlags: { | ||
personProperties: { plan: 'premium' }, | ||
onlyEvaluateLocally: true, | ||
}, | ||
}) | ||
}).not.toThrow() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: expand basic capture test to verify the actual feature flag evaluation results
Size Change: +9.04 kB (+2.91%) Total Size: 320 kB
ℹ️ View Unchanged
|
closing; did it here: #565 |
Problem
Closes PostHog/posthog#34188
Changes
TODO
Release info Sub-libraries affected
Bump level
Libraries affected
Changelog notes
capture
methods when we have locally evaluated feature flags for a given instance