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

chore(flags): use the new /flags endpoint to manage flag evaluation for team 2 #1841

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ export const PERSISTENCE_RESERVED_PROPERTIES = [
]

export const SURVEYS_REQUEST_TIMEOUT_MS = 10000

export const DEFAULT_POSTHOG_APP_API_KEY = 'sTMFPsFhdP1Ssg'
6 changes: 5 additions & 1 deletion src/posthog-featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
STORED_GROUP_PROPERTIES_KEY,
STORED_PERSON_PROPERTIES_KEY,
FLAG_CALL_REPORTED,
DEFAULT_POSTHOG_APP_API_KEY,
} from './constants'

import { isArray, isUndefined } from './utils/type-utils'
Expand Down Expand Up @@ -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
Copy link
Member

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

Suggested change
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?

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.


this._requestInFlight = true
this.instance._send_request({
method: 'POST',
url: this.instance.requestRouter.endpointFor('api', '/decide/?v=4'),
url: this.instance.requestRouter.endpointFor('api', eligibleForFlagsV2 ? '/flags/?v=2' : '/decide/?v=4'),
data,
compression: this.instance.config.disable_compression ? undefined : Compression.Base64,
timeout: this.instance.config.feature_flag_request_timeout_ms,
Expand All @@ -413,6 +416,7 @@ export class PostHogFeatureFlags {
this._requestInFlight = false

if (!this._decideCalled) {
// NB: this will be true if remote config is enabled, which it is for the default posthog app api key
this._decideCalled = true
this.instance._onRemoteConfig(response.json ?? {})
}
Expand Down