PitchHut logo
ZIO OpenFeature
Type-safe feature flag evaluation for ZIO applications.
Pitch

ZIO OpenFeature offers a type-safe, functional interface for evaluating feature flags using any compatible OpenFeature provider. It wraps the OpenFeature Java SDK, ensuring compile-time safety, first-class ZIO integration, and the ability to manage feature flags dynamically through scoped overrides and evaluation caching.

Description

ZIO OpenFeature is a robust ZIO-native wrapper around the OpenFeature Java SDK, designed specifically for Scala 2.13 and Scala 3. This library offers a type-safe, functional interface for feature flag evaluation, enabling seamless integration with any OpenFeature-compatible provider, including popular platforms such as LaunchDarkly, Flagsmith, CloudBees, and Flipt.

Key Features

  • Universal Provider Compatibility: Effortlessly utilize any OpenFeature provider, enhancing flexibility in choosing feature flag management solutions.
  • Type Safety: Leverage compile-time guarantees through the FlagType type class, which ensures robust type-checking and minimizes runtime errors.
  • Enhanced ZIO Integration: Benefit from first-class handling of effects, resource management, and fiber-local context, tailored specifically for ZIO applications.
  • Transaction Management: Implement scoped flag overrides with efficient caching and tracking mechanisms, optimizing performance in complex scenarios.
  • Extensible Hooks: Incorporate cross-cutting concerns for logging, metrics collection, and validation, promoting better maintainability and observability within applications.

Requirements

  • Scala 2.13+ or Scala 3.3+
  • ZIO 2.1+
  • Java 11+

Example Usage

The library allows for straightforward feature flag evaluation. Here’s a quick start example:

import zio.*
import zio.openfeature.*
import zio.openfeature.testkit.*

object MyApp extends ZIOAppDefault {
  val program = for {
    enabled <- FeatureFlags.boolean("my-feature", default = false)
    _       <- ZIO.when(enabled)(Console.printLine("Feature is enabled!"))
  } yield ()

  def run = program.provide(
    Scope.default >>> TestFeatureProvider.layer(Map("my-feature" -> true))
  )
}

To utilize specific OpenFeature providers, simply integrate them into your application as shown below:

import zio.*
import zio.openfeature.*
import dev.openfeature.contrib.providers.flagd.FlagdProvider

object ProductionApp extends ZIOAppDefault {
  val program = for {
    enabled <- FeatureFlags.boolean("new-checkout", default = false)
    variant <- FeatureFlags.string("button-color", default = "blue")
  } yield (enabled, variant)

  def run = program.provide(
    Scope.default >>> FeatureFlags.fromProvider(new FlagdProvider())
  )
}

Core Concepts

ZIO OpenFeature supports various core functionalities including flag evaluation, scoped context management, and transaction tracking:

Flag Evaluation Example

val enabled = FeatureFlags.boolean("feature", default = false)
val variant = FeatureFlags.string("variant", default = "control")

Evaluation Context

val ctx = EvaluationContext("user-123").withAttribute("plan", "premium")
FeatureFlags.boolean("premium-feature", default = false, ctx)

Hooks and Tracking

FeatureFlags.addHook(FeatureHook.logging())
FeatureFlags.track("button-clicked")

Comprehensive Documentation

Explore the complete documentation for further details on setup, architecture, and advanced usage. Specific sections include guides on getting started, utilizing various OpenFeature providers, and leveraging the library's features for improved application performance.

0 comments

No comments yet.

Sign in to be the first to comment.