Skip to content
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

feat(flags): Include version and other feature flag details in /decide response #29693

Open
haacked opened this issue Mar 10, 2025 · 1 comment
Labels
enhancement New feature or request feature/feature-flags Feature Tag: Feature flags team/feature-flags

Comments

@haacked
Copy link
Contributor

haacked commented Mar 10, 2025

Feature request

Right now, it can be difficult for users to understand why a flag evaluated the way it did. It's especially difficult because a flag may have changed since the $feature_flag_called event. Anything we can do to provide more information is helpful.

I'd like to include the $flag_version in the $feature_flag_called event. To do this, we need to add more information in the /decide response.

Describe the solution you'd like

Today, feature flag information is in two different top-level properties of the /decide response body.

{
  ...
  "featureFlags" : {
    "hogtied_got_character" : "danaerys",
    "hogtied-homepage-user" : true,
    "hogtied-homepage-bonanza" : true
  },
  ...
 "featureFlagPayloads" : {
    "hogtied_got_character" : "{\"role\": \"khaleesi\"}",
    "hogtied-homepage-user" : "{\"is_cool\": true}"
  }
}

I propose we add a new section named featureFlagDetails:

"featureFlagDetails" : {
    "hogtied_got_character" : {
        "enabled": true,
        "variant": "danaerys",
        "metadata": {
            "version": 42
            "description": "The character path the user will take",
            "payload": "{\"role\": \"khaleesi\"}"
         }
     },
    ...
  },

You'll notice that information in featureFlags and featureFlagPayloads is repeated there. This is for a few reasons.

I modeled this new dictionary after the OpenFeature API. I'm not by any means suggesting we adopt it 100% right now. But no harm in moving to a format that OpenFeature clients will have an easier time with.

Second, our clients that understand this new format will have an easier time parsing this format and getting the info they need.

For example, down the road, we could add a posthog.getFeatureFlagDetail(...) method to each client that just grabs a node from this new /decide response. This can reduce the requests that server-side clients need to make compared to calling getFeatureFlag and then getFeatureFlagPayload.

Lastly, this format is scalable for new changes. For example, when we want to add a reason for a flag evaluation, we don't need to add a top-level featureFlagReasons property to the JSON.

Debug info

- [ ] PostHog Cloud, Debug information: [please copy/paste from https://us.posthog.com/settings/project-details#variables]
- [ ] PostHog Hobby self-hosted with `docker compose`, version/commit: [please provide]
- [ ] PostHog self-hosted with Kubernetes (deprecated, see [`Sunsetting Kubernetes support`](https://posthog.com/blog/sunsetting-helm-support-posthog)), version/commit: [please provide]
@haacked
Copy link
Contributor Author

haacked commented Mar 10, 2025

In keeping with OpenFeature, I may name the top-level property flags instead of featureFlagDetails.

haacked added a commit that referenced this issue Mar 11, 2025
This contains details about each flag evaluation. The format is designed to be compatible with OpenFeature clients (though for them to work, we may still need to implement a provider).

Related to #29693
haacked added a commit that referenced this issue Mar 11, 2025
This contains details about each flag evaluation. The format is designed to be compatible with OpenFeature clients (though for them to work, we may still need to implement a provider).

Related to #29693
haacked added a commit that referenced this issue Mar 11, 2025
This contains details about each flag evaluation. The format is designed to be compatible with OpenFeature clients (though for them to work, we may still need to implement a provider).

Related to #29693
haacked added a commit that referenced this issue Mar 11, 2025
This contains details about each flag evaluation. The format is designed to be compatible with OpenFeature clients (though for them to work, we may still need to implement a provider).

Related to #29693

Return 0 if version is null

Fix mypy errors
haacked added a commit that referenced this issue Mar 12, 2025
This implements a new shape for `/decide` in v4.

This replaces the top-level `featureFlags` and `featureFlagPayloads` hashes with a simple `flags` hash. Each key is mapped to a feature flag detail object that contains all the info we need:

- evaluation result
- variant
- payload
- version
- reason
- other metadata

While not a primary goal, the shape of the response is inspired by Open Feature. Open Feature doesn't specify how the JSON response has to look, but looking at the other providers, there are common patterns they all implement. Following these patterns will make implemeting an Open Feature provider easier (I hope). Even without that in mind, they're good patterns.

Related to #29693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature/feature-flags Feature Tag: Feature flags team/feature-flags
Projects
None yet
Development

No branches or pull requests

1 participant