-
Notifications
You must be signed in to change notification settings - Fork 3
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
Statsig adapter #27
Merged
Merged
Statsig adapter #27
Conversation
This file contains 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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
New and updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
AndyBitz
approved these changes
Jan 15, 2025
AndyBitz
reviewed
Jan 15, 2025
Acts as a feature flag by default, and includes `.experiment` `.featureGate` and so on for advanced usage
AAorris
force-pushed
the
statsig-adapter
branch
from
January 20, 2025 16:24
af94d1f
to
6f69dce
Compare
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.
Statsig Adapter
Implements a Statsig adapter using
statsig-node
andstatsig-node-vercel
.The adapter takes initialization details for Statsig and the Edge Config adapter, and returns an interface that can be used to declare Feature Gates, Feature Gates with metric lifts, Experiments, DynamicConfigs, and Autotunes.
The adapter will initialize Statsig, notably with defaults where IDLists are not synced and there is no strategy to sync them. This can be changed by passing alternatives in
statsigOptions
, but these defaults reduce network fetching when flags are precomputed in middleware.The decide function will not log events to Statsig — Instead, it's expected that this will be done client side. The reasoning for this is that Next.js may prefetch routes, and we do not want to expose a user to experiments or gates just because they were prefetched. Additionally, because of the serverless runtime context, the buffering and flushing of logs can be unreliable.
For this reason, we will expect the client to log events, for which they will either need to log events manually with a rule ID, or take these results as initial values while checking them again with exposures on the client side.
Simple usage
The usage of calling the adapter directly is the simplest case — A feature gate without metric lifts.
Methods
featureGate
— Receives the boolean value and ruleID and can map the result to a flag valuedynamicConfig
— Receives the evaluated value of a DynamicConfig object and ruleId and can map the result to a flag valueexperiment
— Receives the evaluated value of an Experiment object and ruleId and can map the result to a flag valueautotune
— Receives the evaluated value of an Autotune and ruleId and can map the result to a flag valueinitialize
— Statsig.initialize will be called lazily, when a flag'sdecide
method is invoked. To initialize Statsig earlier using the adapter's implementation: