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.
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.
FlagType type class, which ensures robust type-checking and minimizes runtime errors.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())
)
}
ZIO OpenFeature supports various core functionalities including flag evaluation, scoped context management, and transaction tracking:
val enabled = FeatureFlags.boolean("feature", default = false)
val variant = FeatureFlags.string("variant", default = "control")
val ctx = EvaluationContext("user-123").withAttribute("plan", "premium")
FeatureFlags.boolean("premium-feature", default = false, ctx)
FeatureFlags.addHook(FeatureHook.logging())
FeatureFlags.track("button-clicked")
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.
No comments yet.
Sign in to be the first to comment.