-
Notifications
You must be signed in to change notification settings - Fork 147
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
chore(flags): use the new /flags
endpoint to manage flag evaluation for team 2
#1841
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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
This PR introduces a new /flags
endpoint specifically for PostHog team 2's feature flag evaluation, while maintaining the existing /decide
endpoint for other customers.
- Added
DEFAULT_POSTHOG_APP_API_KEY
constant to identify PostHog team 2 requests in/src/constants.ts
- Modified feature flag evaluation in
/src/posthog-featureflags.ts
to use/flags?v=2
endpoint when token matches team 2's API key and remote config is enabled - Added logic to handle remote config interaction, ensuring
/decide
endpoint is still called when needed for non-flag functionality - Added eligibility check
eligibleForFlagsV2
to determine when to use the new endpoint
2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
Size Change: +1.31 kB (+0.04%) Total Size: 3.63 MB
ℹ️ View Unchanged
|
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.
Looks good to me!
src/posthog-featureflags.ts
Outdated
@@ -390,10 +391,12 @@ export class PostHogFeatureFlags { | |||
data.disable_flags = true | |||
} | |||
|
|||
const eligibleForFlagsV2 = token === DEFAULT_POSTHOG_APP_API_KEY && this.instance.config.__preview_remote_config |
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.
Any chance we could just do
const eligibleForFlagsV2 = token === DEFAULT_POSTHOG_APP_API_KEY && this.instance.config.__preview_remote_config | |
const eligibleForFlagsV2 = this.instance.config.__preview_flags_v2 |
so that I can run this on localhost easily?
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.
oh yeah, and then we can just set the preview to true for our own posthog JS initialization + any other instances of it.
That's a good idea; I might still want to use API tokens down the road (especially when rolling out to specific users), but I'm happy doing something like this instead. Thanks for the suggestion!
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.
@robbie-c went ahead and went with the config-based approach, although I might need to use API tokens down the road too (so I can turn this on for specific customers as needed). I think my plan will be to have a set of tokens that have this feature toggled on, and then allow folks to specify it in their config as well.
Changes
Basically, what I'm doing is that any request with the PostHog team 2 public API key, we use
/flags
, and then for everything else we just use/decide
.There's a little bit of trickiness w.r.t remote config (I added a comment to that end) since new flags relies on the fact that remote config takes care of all the other non-flag-related code (it basically does away with
/decide
altogether). But if a customer isn't using remote config, they'll need to hit/decide
anyway. I should have this handled in the logic, but worth calling out.