OpenFeature Provider (Java)
Overview
The Mixpanel OpenFeature provider allows you to use Mixpanel Feature Flags through the standardized OpenFeature API. This provider wraps the Mixpanel Java SDK’s feature flags, letting you use the OpenFeature Java SDK with Mixpanel as the backend.
For the core Feature Flags SDK guide, see Feature Flags (Java).
Prerequisites
- You are on an Enterprise subscription plan
- You have the Mixpanel Java SDK installed (minimum version
v1.7.0) - You have your Project Token from your Mixpanel Project Settings
Installation
Add the OpenFeature provider and SDK to your Maven pom.xml:
<dependency>
<groupId>com.mixpanel</groupId>
<artifactId>mixpanel-java-openfeature-provider</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>dev.openfeature</groupId>
<artifactId>sdk</artifactId>
<version>1.20.1</version>
</dependency>Or with Gradle:
implementation 'com.mixpanel:mixpanel-java-openfeature-provider:1.7.0'
implementation 'dev.openfeature:sdk:1.20.1'Usage
The provider wraps a BaseFlagsProvider (either LocalFlagsProvider or RemoteFlagsProvider) from the Mixpanel SDK.
With Local Evaluation
import com.mixpanel.openfeature.MixpanelProvider;
import dev.openfeature.sdk.*;
// Create provider with local evaluation (automatically starts polling)
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new MixpanelProvider("YOUR_PROJECT_TOKEN", localFlagsConfig));
Client client = api.getClient();
boolean showNewUI = client.getBooleanValue("new-ui", false);With Remote Evaluation
import com.mixpanel.openfeature.MixpanelProvider;
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new MixpanelProvider("YOUR_PROJECT_TOKEN", remoteFlagsConfig));
Client client = api.getClient();
String variant = client.getStringValue("checkout-flow", "control");With an Existing Flags Provider
If you already have a configured LocalFlagsProvider or RemoteFlagsProvider, you can wrap it directly:
import com.mixpanel.mixpanelapi.featureflags.provider.LocalFlagsProvider;
import com.mixpanel.openfeature.MixpanelProvider;
LocalFlagsProvider flagsProvider = new LocalFlagsProvider("YOUR_PROJECT_TOKEN", config, sdkVersion, eventSender);
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(new MixpanelProvider(flagsProvider));Supported Flag Types
| OpenFeature Method | Java Type |
|---|---|
getBooleanValue / getBooleanDetails | Boolean |
getStringValue / getStringDetails | String |
getIntegerValue / getIntegerDetails | Integer (coerces from Long, Double) |
getDoubleValue / getDoubleDetails | Double (coerces from Integer, Long) |
getObjectValue / getObjectDetails | Value (wraps maps, lists, and primitives) |
Numeric types are coerced automatically. For example, a flag returning a Long value will work with getIntegerValue().
Context and Identity
The evaluation context passed to each flag evaluation is forwarded to the Mixpanel flags provider.
targetingKeyhas no special meaning in this provider. It is treated as a regular context property.- Identity should be managed through the Mixpanel SDK (e.g., setting
distinct_idin the context).
Error Handling
The provider returns the default value on all errors, with an error code indicating the cause:
| Error Code | Condition |
|---|---|
PROVIDER_NOT_READY | The provider has not been initialized |
FLAG_NOT_FOUND | The requested flag does not exist |
TYPE_MISMATCH | The flag value does not match the requested type |
Use getDetails() methods instead of getValue() to inspect error codes:
FlagEvaluationDetails<Boolean> details = client.getBooleanDetails("my-flag", false);
if (details.getErrorCode() != null) {
System.out.println("Flag error: " + details.getErrorCode() + " - " + details.getErrorMessage());
}Lifecycle
shutdown()delegates to the underlying flags provider to clean up resources (e.g., stop polling).- The reason code for successful evaluations is
STATIC.
Was this page useful?