Skip to content

Latest commit

 

History

History
77 lines (57 loc) · 3.22 KB

README.md

File metadata and controls

77 lines (57 loc) · 3.22 KB

Unofficial Statsig OpenFeature Provider for Java

Statsig OpenFeature Provider can provide usage for Statsig via OpenFeature Java SDK.

Installation

<dependency>
    <groupId>dev.openfeature.contrib.providers</groupId>
    <artifactId>statsig</artifactId>
    <version>0.1.0</version>
</dependency>

Concepts

  • String/Integer/Double evaluations evaluation gets Dynamic config or Layer evaluation. As the key represents an inner attribute, feature config is required as a parameter with data needed for evaluation. For an example of dynamic config of product alias, need to differentiate between dynamic config or layer, and the dynamic config name.
  • Boolean evaluation gets gate status when feature config is not passed. When feature config exists, it evaluates to the config/layer attribute, similar to String/Integer/Float evaluations.
  • Object evaluation gets a structure representing the dynamic config or layer.
  • Private Attributes are supported as 'privateAttributes' context key.

Usage

Statsig OpenFeature Provider is based on Statsig Java SDK documentation.

Usage Example

StatsigOptions statsigOptions = new StatsigOptions();
StatsigProviderConfig statsigProviderConfig = StatsigProviderConfig.builder().sdkKey(sdkKey)
    .options(statsigOptions).build();
statsigProvider = new StatsigProvider(statsigProviderConfig);
OpenFeatureAPI.getInstance().setProviderAndWait(statsigProvider);

MutableContext evaluationContext = new MutableContext();
evaluationContext.setTargetingKey(TARGETING_KEY);
boolean featureEnabled = client.getBooleanValue(FLAG_NAME, false);

MutableContext featureConfig = new MutableContext();
featureConfig.add("type", "CONFIG");
featureConfig.add("name", "product");
evaluationContext.add("feature_config", featureConfig);
String value = statsigProvider.getStringEvaluation("alias", "fallback", evaluationContext).getValue());

MutableContext evaluationContext = new MutableContext();
evaluationContext.setTargetingKey("test-id");
evaluationContext.add("Email", "[email protected]");
MutableContext privateAttributes = new MutableContext();
privateAttributes.add("locale", locale);
evaluationContext.add("privateAttributes", privateAttributes);
featureEnabled = client.getBooleanValue(USERS_FLAG_NAME, false, evaluationContext);

See StatsigProviderTest for more information.

Notes

Some Statsig custom operations are supported from the Statsig client via:

Statsig...

Statsig Provider Tests Strategies

Unit test based on Statsig Local Overrides and mocking. As it is limited, evaluation context based tests are limited. See statsigProviderTest for more information.