feat: add EvaluateFlags() API for single-call flag evaluation#191
Open
feat: add EvaluateFlags() API for single-call flag evaluation#191
Conversation
832df34 to
30b1585
Compare
Contributor
posthog-go Compliance ReportDate: 2026-04-29 21:27:15 UTC
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 609ms |
| Format Validation.Event Has Uuid | ✅ | 607ms |
| Format Validation.Event Has Lib Properties | ✅ | 608ms |
| Format Validation.Distinct Id Is String | ✅ | 607ms |
| Format Validation.Token Is Present | ✅ | 607ms |
| Format Validation.Custom Properties Preserved | ✅ | 607ms |
| Format Validation.Event Has Timestamp | ✅ | 608ms |
| Retry Behavior.Retries On 503 | ✅ | 5612ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 2610ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 2608ms |
| Retry Behavior.Respects Retry After Header | ✅ | 5611ms |
| Retry Behavior.Implements Backoff | ✅ | 15623ms |
| Retry Behavior.Retries On 500 | ✅ | 5614ms |
| Retry Behavior.Retries On 502 | ✅ | 5613ms |
| Retry Behavior.Retries On 504 | ✅ | 5613ms |
| Retry Behavior.Max Retries Respected | ✅ | 15623ms |
| Deduplication.Generates Unique Uuids | ✅ | 615ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 5613ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 10617ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 5616ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 610ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 622ms |
| Compression.Sends Gzip When Enabled | ✅ | 607ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 606ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 606ms |
| Batch Format.Multiple Events Batched Together | ✅ | 609ms |
| Error Handling.Does Not Retry On 403 | ✅ | 2610ms |
| Error Handling.Does Not Retry On 413 | ✅ | 2609ms |
| Error Handling.Retries On 408 | ✅ | 5612ms |
Feature_Flags Tests
View Details
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ❌ | 7ms |
Failures
request_payload.request_with_person_properties_device_id
Field 'distinct_id' not found in /flags request body at path 'person_properties.distinct_id'. Available keys: ['$device_id']
30b1585 to
c6d9751
Compare
Adds a Phase 1 implementation of the Server SDK Feature Flag Evaluations RFC, mirroring posthog-js#3476 and posthog-python#539. Client.EvaluateFlags returns a FeatureFlagEvaluations snapshot built from at most one /flags request. The snapshot powers IsEnabled, GetFlag, and GetFlagPayload checks, fires deduped $feature_flag_called events with full v4 metadata (id, version, reason, request_id), and can be attached to a Capture event via the new Capture.Flags field to populate $feature/<key> and $active_feature_flags with no extra network call. The dedup logic for $feature_flag_called is extracted into captureFlagCalledIfNeeded so the existing single-flag path and the new snapshot path share the same per-distinct_id LRU cache and behave identically. OnlyAccessed and Only return filtered child snapshots with independent access tracking, so filtering for a Capture does not back-propagate to the parent. A new Config.FeatureFlagsLogWarnings option silences their warnings for callers that prefer quieter helpers. Capture.SendFeatureFlags is unchanged and not deprecated; Phase 2 will follow up with deprecations and migration guidance. Generated-By: PostHog Code Task-Id: b9d98122-fe61-462a-bfb3-6e1be3a8966a
c6d9751 to
4b71cbd
Compare
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.
Summary
Client.EvaluateFlags(payload)returns a*FeatureFlagEvaluationssnapshot built from a single/flagsrequest.IsEnabled/GetFlag/GetFlagPayload/OnlyAccessed/Only/Keys. Access methods fire deduped$feature_flag_calledwith full v4 metadata;GetFlagPayloadis silent.Capture.Flags *FeatureFlagEvaluationsattaches$feature/<key>and$active_feature_flagsfrom the snapshot — no second/flagscall per event. Takes precedence overSendFeatureFlagsand warns if both are set.Config.FeatureFlagsLogWarnings *boolsilences theOnly()filter-helper warning.SendFeatureFlagsis unchanged (no deprecations in this PR).RFC — mirrored from posthog-python#539 and posthog-js#3476, incorporating the latest review feedback from the Python PR.
Design decisions
(distinctId, key, deviceId)dedup cache, so mixing the two APIs in one process can't double-fire$feature_flag_called.OnlyAccessed()honors its name — empty by default: returning all flags as a "safety net" when nothing was accessed contradicted the method's intent; callers who want all flags can just pass the parent snapshot directly.Capture.Flagstakes precedence overSendFeatureFlagswith a runtime warning when both are set — firing a redundant/flagsrequest would defeat the whole point of supplying a snapshot.accessedset:OnlyAccessed()/Only()clones don't back-propagate access into the parent, so attachingsnap.OnlyAccessed()to aCapturedoesn't widen what a laterparent.OnlyAccessed()returns.DistinctIdreturns a silent empty snapshot instead of erroring — matches the Python/Node design and avoids$feature_flag_calledevents with empty distinct_ids leaking into analytics.errorsWhileComputingFlagsandquotaLimitedon the snapshot are combined comma-joined with per-flag errors (e.g.errors_while_computing_flags,flag_missing) in$feature_flag_error, matching the legacy single-flag path's granularity so dashboards don't lose error categories when callers migrate.flag_keys_to_evaluatewired through the decider interface, so existing single-flag callers passniland behavior is unchanged on the wire.Phase 2 follow-ups (out of scope here)
Capture.SendFeatureFlagsin favor ofCapture.Flags.IsFeatureEnabled/GetFeatureFlag/GetFeatureFlagResultcallers towardEvaluateFlagsfor multi-flag use.flag_definitions_loaded_attimestamp from the local-eval poller so$feature_flag_definitions_loaded_atcan be attached for locally-evaluated flags.TIMEOUT/CONNECTION_ERROR/api_error_NNNexceptions in the snapshot's$feature_flag_error(currently only the response-level error categories are propagated).Created with PostHog Code