DocsTracking MethodsSDKsGoOpenFeature Provider (Go)

OpenFeature Provider (Go)

Overview

The Mixpanel OpenFeature provider allows you to use Mixpanel Feature Flags through the standardized OpenFeature API. This provider wraps the Mixpanel Go SDK’s feature flags, letting you use the OpenFeature Go SDK with Mixpanel as the backend.

For the core Feature Flags SDK guide, see Feature Flags (Go).

Prerequisites

Installation

go get github.com/mixpanel/mixpanel-go/v2/openfeature
go get github.com/open-feature/go-sdk

Usage

The provider wraps either a LocalFeatureFlagsProvider or RemoteFeatureFlagsProvider from the Mixpanel SDK.

With Local Evaluation

package main
 
import (
    "context"
    "fmt"
    "time"
 
    "github.com/mixpanel/mixpanel-go/v2/flags"
    mpof "github.com/mixpanel/mixpanel-go/v2/openfeature"
    "github.com/open-feature/go-sdk/openfeature"
)
 
func main() {
    config := flags.DefaultLocalFlagsConfig()
    config.PollingInterval = 60 * time.Second
 
    // Create a provider with local evaluation (automatically starts polling)
    provider, err := mpof.NewProviderWithLocalConfig("YOUR_PROJECT_TOKEN", config)
    if err != nil {
        panic(err)
    }
    defer provider.Shutdown()
 
    openfeature.SetProvider(provider)
 
    client := openfeature.NewClient("my-app")
    showNewUI, _ := client.BooleanValue(context.Background(), "new-ui", false, openfeature.EvaluationContext{})
    fmt.Println("Show new UI:", showNewUI)
}

With Remote Evaluation

config := flags.DefaultRemoteFlagsConfig()
 
provider, err := mpof.NewProviderWithRemoteConfig("YOUR_PROJECT_TOKEN", config)
if err != nil {
    panic(err)
}
 
openfeature.SetProvider(provider)
 
client := openfeature.NewClient("my-app")
variant, _ := client.StringValue(context.Background(), "checkout-flow", "control", openfeature.EvaluationContext{})

With an Existing Flags Provider

If you already have a configured LocalFeatureFlagsProvider or RemoteFeatureFlagsProvider, you can wrap it directly:

import (
    mixpanel "github.com/mixpanel/mixpanel-go/v2"
    mpof "github.com/mixpanel/mixpanel-go/v2/openfeature"
)
 
mp := mixpanel.NewClient("YOUR_PROJECT_TOKEN",
    mixpanel.WithLocalFlagsConfig(mixpanel.LocalFlagsConfig{
        EnablePolling:   true,
        PollingInterval: 60 * time.Second,
    }),
)
 
mp.LocalFlags().StartPollingForDefinitions()
defer mp.LocalFlags().StopPollingForDefinitions()
 
provider := mpof.NewProvider(mp.LocalFlags())
openfeature.SetProvider(provider)

Supported Flag Types

OpenFeature MethodGo Type
BooleanValue / BooleanValueDetailsbool
StringValue / StringValueDetailsstring
IntValue / IntValueDetailsint64
FloatValue / FloatValueDetailsfloat64
ObjectValue / ObjectValueDetailsinterface{}

Context and Identity

The evaluation context passed to each flag evaluation is forwarded to the Mixpanel flags provider.

  • targetingKey has 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_id in the context).

Error Handling

The provider returns the default value on all errors, with a resolution error indicating the cause:

Error CodeCondition
PROVIDER_NOT_READYThe provider has not been initialized
FLAG_NOT_FOUNDThe requested flag does not exist
TYPE_MISMATCHThe flag value does not match the requested type

Use ValueDetails methods to inspect error codes:

details, err := client.BooleanValueDetails(ctx, "my-flag", false, openfeature.EvaluationContext{})
if details.ErrorCode != "" {
    fmt.Printf("Flag error: %s - %s\n", details.ErrorCode, details.ErrorMessage)
}

Lifecycle

  • Shutdown() stops background polling for local evaluation providers. Call it when your application exits.
  • The reason code for successful evaluations is STATIC.

Was this page useful?