helix

OpenFeature

The openfeature integration provides an opinionated way to interact with feature flags for helix services. It uses the OpenFeature specification and the GO Feature Flag provider.

Event attributes

The openfeature integration doesn't create traces/spans. Instead, it creates a new event on each flag evaluation associated to the active span. It sets the following event attributes:

  • openfeature.flag
  • openfeature.default_value
  • openfeature.target
  • openfeature.variant
  • openfeature.value

Example:

name: "openfeature.evaluate"
openfeature.flag: "color-testing"
openfeature.default_value: "red"
openfeature.target: "bf3eab40-29ec-46e1-afa9-7dd8c08dc6a0"
openfeature.variant: "version-blue"
openfeature.value: "blue"

Usage

The integration uses the OpenFeature Go SDK as well as the GO Feature Flag provider.

Install the Go module with:

$ go get go.nunchi.studio/helix/integration/openfeature

Simple example on how to import, configure, and use the integration:

import (
  "context"
  "fmt"

  "go.nunchi.studio/helix/event"
  "go.nunchi.studio/helix/integration/openfeature"
  "go.nunchi.studio/helix/service"
)

func main() {
  cfg := openfeature.Config{
    Paths: []string{
      "./flags/marketing.yaml",
      "./flags/canary.yaml",
    },
  }

  ff, err := openfeature.Connect(cfg)
  if err != nil {
    return err
  }

  var e = event.Event{
    Name:   "post.anything",
    UserID: "7469e788-617a-4b6a-8a26-a61f6acd01d3",
    Subscriptions: []event.Subscription{
      {
        CustomerID:  "2658da04-7c8f-4a7e-9ab0-d5d555b8173e",
        PlanID:      "7781028b-eb48-410d-8cae-c36cffed663d",
        Usage:       "api.requests",
        IncrementBy: 1.0,
      },
    },
  }

  ctx := event.ContextWithEvent(context.Background(), e)
  details, err := app.FeatureFlags.EvaluateString(ctx, "flag-name", "default value", e.UserID)
  if err != nil {
    // ...
  }

  fmt.Println("Variant:", details.Variant)
  fmt.Println("Value:", details.Value)

  if err := service.Start(); err != nil {
    panic(err)
  }

  if err := service.Close(); err != nil {
    panic(err)
  }
}

Is something missing?

Built by
Nunchi