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: Support for client-assigned feature flags #1519

Closed
wants to merge 1 commit into from

Conversation

danielbachhuber
Copy link

@danielbachhuber danielbachhuber commented Nov 12, 2024

Changes

Adds support for client-assigned feature flags. When bootstrap.clientAssignedFeatureFlags is provided, the specified feature flags will be assigned with values based on the PostHog backend's allocation strategy.

posthog.init('<ph_project_api_key>', {
    bootstrap: {
        clientAssignedFeatureFlags: [
            {
                key: 'my-awesome-experiment-flag',
                variants: {
                    test: 0.5,
                    control: 0.5,
                },
            },
        ],
    },
})

Related PostHog/posthog#26145

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Nov 12, 2024 1:18pm

@danielbachhuber danielbachhuber changed the title Support for client-assigned feature flags feat: Support for client-assigned feature flags Nov 12, 2024
Copy link

Size Change: +20.3 kB (+0.66%)

Total Size: 3.12 MB

Filename Size Change
dist/array.full.es5.js 255 kB +2.29 kB (+0.91%)
dist/array.full.js 357 kB +2.01 kB (+0.57%)
dist/array.full.no-external.js 356 kB +2.01 kB (+0.57%)
dist/array.js 172 kB +2.01 kB (+1.18%)
dist/array.no-external.js 171 kB +2.01 kB (+1.19%)
dist/main.js 173 kB +2.01 kB (+1.18%)
dist/module.full.js 357 kB +2.01 kB (+0.57%)
dist/module.full.no-external.js 356 kB +2.01 kB (+0.57%)
dist/module.js 172 kB +2.01 kB (+1.18%)
dist/module.no-external.js 171 kB +2.01 kB (+1.19%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 204 kB
dist/dead-clicks-autocapture.js 13 kB
dist/exception-autocapture.js 8.8 kB
dist/external-scripts-loader.js 2.19 kB
dist/recorder-v2.js 113 kB
dist/recorder.js 113 kB
dist/surveys-preview.js 56.7 kB
dist/surveys.js 62.1 kB
dist/tracing-headers.js 1.33 kB
dist/web-vitals.js 10.3 kB

compressed-size-action

Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is interesting work; what's the context here? Is this supporting some sort of customer request?

return Number(hashInt) / Number(LONG_SCALE) // Normalize the hash to a value between 0 and 1
}

// TODO how much do we trust sonnet to write a hashing function?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

}

// TODO how much do we trust sonnet to write a hashing function?
_hash(input: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use sha1 in both the python and rust implementations when creating hash keys; any reason why we wouldn't do the same here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why we wouldn't do the same here?

@dmarticus Tell me more? I ran into some IE11 linting issue with crypto, but maybe we can actually use it.

Copy link
Contributor

@dmarticus dmarticus Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh, should've known there's some browser compat issue – there's some prior art (slack, github around separating our bundles into es5 (for things that explicitly need IE11 support) and es6 (for everything else), but I'm not sure what our policy on adding new behavior that explicitly doesn't support IE11 is.

It might be a pain to support it here though, even if crypto is technically "supported" on IE11, it seems like the support pegged to a specific version of that library, and I'm not sure if taking on the overhead of making sure we have IE11 support is worth using the library. Then again, using a standard for crypto is probably safer than rolling our owning hashing algo. TBH – the decision is up to you, I just wanted to provide my 2 cents. I definitely didn't realize this was a browser compat thing beforehand.

@danielbachhuber
Copy link
Author

Is this supporting some sort of customer request?

@dmarticus Yep, see https://posthog.slack.com/archives/C07PXH2GTGV/p1731099028903259

@dmarticus
Copy link
Contributor

Is this supporting some sort of customer request?

@dmarticus Yep, see posthog.slack.com/archives/C07PXH2GTGV/p1731099028903259

great, thanks for the context!

@posthog-bot
Copy link
Collaborator

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@danielbachhuber
Copy link
Author

Closing in favor of https://posthog-fast-feature-flags.vercel.app/ for now

If it turns out to work well, I'll submit a new PR

@danielbachhuber danielbachhuber deleted the client-assigned-feature-flags branch November 22, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants