feat(analytics): add variantSource alongside fallbackReason (SDK-79) - #87
Closed
tylerjroach wants to merge 1 commit into
Closed
feat(analytics): add variantSource alongside fallbackReason (SDK-79)#87tylerjroach wants to merge 1 commit into
tylerjroach wants to merge 1 commit into
Conversation
SelectedVariant now carries two source fields: `variant_source` (local | remote | fallback) and `fallback_reason` (FLAG_NOT_FOUND | MISSING_CONTEXT_KEY | NO_ROLLOUT_MATCH | BACKEND_ERROR | NOT_READY, set only when source is fallback). Three behaviorally distinct outcomes — flag-not-found, no-rollout-match, and missing-context-key — previously all returned the bare fallback. The OpenFeature wrapper collapsed them to FLAG_NOT_FOUND, sending callers chasing the flag name when the real cause was usually a rule miss or absent context. The wrapper now dispatches on fallback_reason and maps each to the spec-correct OpenFeature response. Most notably, NO_ROLLOUT_MATCH becomes `reason: DEFAULT` with no error code instead of FLAG_NOT_FOUND. Constant names align with mixpanel-php for consistency across SDKs. Linear: SDK-79 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
MixpanelSelectedVariant->variantSource(always set):local|remote|fallback. NewSOURCE_*constants on the class.MixpanelSelectedVariant->fallbackReason(existing field, semantics tightened): one ofFLAG_NOT_FOUND|MISSING_CONTEXT_KEY|NO_ROLLOUT_MATCH|BACKEND_ERROR|NOT_READY. Only set whenvariantSource === SOURCE_FALLBACK.withFallbackReason()now sets bothvariantSource = SOURCE_FALLBACKandfallbackReason. NewwithSource()clearsfallbackReason.MixpanelLocalFlagstags matched returns withSOURCE_LOCAL.MixpanelRemoteFlagstags network successes withSOURCE_REMOTE.Why
The base feature-flag work in #86 already introduced
fallbackReasonto distinguish the various fallback paths. AddingvariantSourcealongside completes the picture: callers (especially a future OpenFeature wrapper, and exposure analytics) can answer both "where did this value come from?" and "if it's a fallback, why?".Constants and field naming align with the design being applied to the other Mixpanel SDKs (Python / Ruby / Java / Go / Node / Android / Swift / JS-web), tracked at Linear SDK-79.
Stacked on #86
This PR is based on
feature-flags-support(PR #86's branch). Once #86 merges to master, GitHub auto-rebases this onto master.Test plan
vendor/bin/phpunit test/FeatureFlags/)fallbackReasontests still pass; assertions augmented to also checkvariantSourcevariantSourceisSOURCE_LOCAL/SOURCE_REMOTEon successful eval, andSOURCE_FALLBACK(plus the rightfallbackReason) on every fallback path🤖 Generated with Claude Code