Skip to main content

OpenFeature Provider for Go SDK

Last updated on

Integrate your Go applications with Harness FME using the Go OpenFeature ProviderAn OpenFeature Provider wraps the Harness FME SDK, acting as a bridge between the OpenFeature SDK and the FME SDK. It translates OpenFeature function calls into operations handled by the FME SDK., a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME Go SDK.

This page walks you through installing, configuring, and using the Go OpenFeature provider to evaluate feature flags in your Go applications.

Before you begin

Before you begin, ensure you have the following:

  • A valid Harness FME SDK key for your project
  • A Go environment running version 1.21 or later
  • Access to your Go module configuration (go.mod)

Version compatibility

ComponentMinimum Version
Go1.21+
github.com/splitio/split-openfeature-provider-go≥ 2.0.0
OpenFeature Go SDK≥ 1.0.0

Install the provider and dependencies

Add the Harness FME OpenFeature provider to your Go module.

go get github.com/splitio/split-openfeature-provider-go

Initialize the provider

You can instantiate and register the provider using your Harness FME SDK key.

import (
"github.com/open-feature/go-sdk/openfeature"
splitProvider "github.com/splitio/split-openfeature-provider-go"
)

provider, err := splitProvider.NewProviderSimple("YOUR_SDK_API_KEY")
if err != nil {
// Provider creation error
}
openfeature.SetProviderAndWait(provider)

Alternatively, if you want more control or need advanced initialization, you can create a SplitClient and provide it directly:

import (
"github.com/open-feature/go-sdk/openfeature"
"github.com/splitio/go-client/v6/splitio/client"
"github.com/splitio/go-client/v6/splitio/conf"
splitProvider "github.com/splitio/split-openfeature-provider-go"
)

cfg := conf.Default()
factory, err := client.NewSplitFactory("YOUR_SDK_API_KEY", cfg)
if err != nil {
// SDK initialization error
}

splitClient := factory.Client()
if err := splitClient.BlockUntilReady(10); err != nil {
// SDK timeout error
}

provider, err := splitProvider.NewProvider(splitClient)
if err != nil {
// Provider creation error
}
_ = openfeature.SetProviderAndWait(provider)

Construct an evaluation context

Provide an evaluation contextThe Evaluation Context holds contextual information used during flag evaluation. It can include static data (like application or host identifiers) and dynamic data (such as a client IP address), which can be passed explicitly or propagated automatically. with a targeting keyA unique identifier used to target specific users or entities when evaluating feature flags. It helps determine which variation of a flag should be served based on predefined rules and conditions. to evaluate flags. The evaluation context passes targeting information such as user IDs, email addresses, or plan types for flag targeting.

For example:

import "context"

client := openfeature.NewClient("CLIENT_NAME")
ctx := context.Background()

evaluationContext := openfeature.NewEvaluationContext("TARGETING_KEY", nil)
boolValue, err := client.BooleanValue(ctx, "boolFlag", false, evaluationContext)

If the same targeting key is reused across evaluations, set the context at the client level:

evaluationContext := openfeature.NewEvaluationContext("TARGETING_KEY", nil)
client.SetEvaluationContext(evaluationContext)

Or globally:

evaluationContext := openfeature.NewEvaluationContext("TARGETING_KEY", nil)
openfeature.SetEvaluationContext(evaluationContext)

Once the context is set at the client or API level, you don't need to provide it for each evaluation.

Evaluate with details

Use the *ValueDetails APIs to get flag values and metadata (such as variant, reason, error code, and configuration). The FME treatment configuration is returned as a raw JSON string under FlagMetadata["config"].

For example:

details, err := client.StringValueDetails(ctx, "my-flag", "fallback", evalCtx)
if err == nil && details.FlagMetadata != nil {
if config, ok := details.FlagMetadata["config"].(string); ok {
// config holds the Split treatment config
}
}

Track events

The Harness FME OpenFeature provider supports tracking user actions or conversion events directly from your Go application.

To enable event tracking with Track(ctx, eventName, evalCtx, details), your evaluation context must include the following:

  • A non-blank targeting key on the EvaluationContext
  • A trafficType attribute (for example, "user" or "account")
  • A non-blank event name

Optionally, you can include a numeric value and additional event properties using openfeature.NewTrackingEventDetails(value) and .Add(key, value). For more information, see Sending Events.

For example:

evalCtx := openfeature.NewEvaluationContext("user-123", map[string]any{"trafficType": "user"})

details := openfeature.NewTrackingEventDetails(19.99).
Add("plan", "pro").
Add("coupon", "WELCOME10")

client.Track(ctx, "checkout.completed", evalCtx, details)

For more information, go to the Harness FME Go OpenFeature Provider GitHub repository.