Skip to content

open-feature/dart-server-sdk

OpenFeature Logo

OpenFeature Dart Server SDK

Specification Release Built with Dart
Pub Version API Reference Code Coverage GitHub CI Status

⚠️ This repository is a work in progress repository for an implementation of the dart-server-sdk.

OpenFeature is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.

πŸš€ Quick start

Requirements

Dart language version: 3.7.2

Note

The OpenFeature DartServer SDK only supports the latest currently maintained Dart language versions.

Install

TBD

API Reference

See TBD for the complete API documentation.

🌟 Features

Status Features Description
❌ Providers Integrate with a commercial, open source, or in-house feature management tool.
❌ Targeting Contextually-aware flag evaluation using evaluation context.
❌ Hooks Add functionality to various stages of the flag evaluation life-cycle.
❌ Logging Integrate with popular logging packages.
❌ Domains Logically bind clients with providers.
❌ Eventing React to state changes in the provider or flag management system.
❌ Shutdown Gracefully clean up a provider during application shutdown.
❌ Transaction Context Propagation Set a specific evaluation context for a transaction (e.g. an HTTP request or a thread)
❌ Extending Extend OpenFeature with custom providers and hooks.

Implemented: βœ… | In-progress: ⚠️ | Not implemented yet: ❌

Providers

Providers are an abstraction between a flag management system and the OpenFeature SDK. Look here for a complete list of available providers. If the provider you're looking for hasn't been created yet, see the develop a provider section to learn how to build it yourself.

Once you've added a provider as a dependency, it can be registered with OpenFeature like this:

Targeting

Sometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location. In OpenFeature, we refer to this as targeting. If the flag management system you're using supports targeting, you can provide the input data using the evaluation context.

Hooks

Hooks allow for custom logic to be added at well-defined points of the flag evaluation life-cycle Look here for a complete list of available hooks. If the hook you're looking for hasn't been created yet, see the develop a hook section to learn how to build it yourself.

Once you've added a hook as a dependency, it can be registered at the global, client, or flag invocation level.

Tracking

The tracking API allows you to use OpenFeature abstractions and objects to associate user actions with feature flag evaluations. This is essential for robust experimentation powered by feature flags. For example, a flag enhancing the appearance of a UI component might drive user engagement to a new feature; to test this hypothesis, telemetry collected by a hook or provider can be associated with telemetry reported in the client's track function.

Note that some providers may not support tracking; check the documentation for your provider for more information.

Logging

Note that in accordance with the OpenFeature specification, the SDK doesn't generally log messages during flag evaluation.

Logging Hook

The Dart SDK includes a LoggingHook, which logs detailed information at key points during flag evaluation, using TBD structured logging API. This hook can be particularly helpful for troubleshooting and debugging; simply attach it at the global, client or invocation level and ensure your log level is set to "debug".

Usage example
Output
{"time":"2024-10-23T13:33:09.8870867+03:00","level":"DEBUG","msg":"Before stage","domain":"test-client","provider_name":"InMemoryProvider","flag_key":"not-exist","default_value":true}  
{"time":"2024-10-23T13:33:09.8968242+03:00","level":"ERROR","msg":"Error stage","domain":"test-client","provider_name":"InMemoryProvider","flag_key":"not-exist","default_value":true,"error_message":"error code: FLAG_NOT_FOUND: flag for key not-exist not found"}

See hooks for more information on configuring hooks.

Domains

Clients can be assigned to a domain. A domain is a logical identifier that can be used to associate clients with a particular provider. If a domain has no associated provider, the default provider is used.

Eventing

Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions. Initialization events (PROVIDER_READY on success, PROVIDER_ERROR on failure) are dispatched for every provider. Some providers support additional events, such as PROVIDER_CONFIGURATION_CHANGED.

Please refer to the documentation of the provider you're using to see what events are supported.

Shutdown

Transaction Context Propagation

Transaction context is a container for transaction-specific evaluation context (e.g. user id, user agent, IP). Transaction context can be set where specific data is available (e.g. an auth service or request handler), and by using the transaction context propagator, it will automatically be applied to all flag evaluations within a transaction (e.g. a request or thread).

Extending

Develop a provider

To develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency. This can be a new repository or included in the existing contrib repository available under the OpenFeature organization. You’ll then need to write the provider by implementing the FeatureProvider interface exported by the OpenFeature SDK.

Built a new provider? Let us know so we can add it to the docs!

Develop a hook

To develop a hook, you need to create a new project and include the OpenFeature SDK as a dependency. This can be a new repository or included in the existing contrib repository available under the OpenFeature organization. Implement your own hook by conforming to the Hook interface. To satisfy the interface, all methods (Before/After/Finally/Error) need to be defined. To avoid defining empty functions make use of the UnimplementedHook struct (which already implements all the empty functions).

Built a new hook? Let us know so we can add it to the docs!

Testing

The SDK provides a NewTestProvider which allows you to set flags for the scope of a test. The TestProvider is thread-safe and can be used in tests that run in parallel.

Call testProvider.UsingFlags(t, tt.flags) to set flags for a test, and clean them up with testProvider.Cleanup()

⭐️ Support the project

🀝 Contributing

Interested in contributing? Great, we'd love your help! To get started, take a look at the CONTRIBUTING guide.

Thanks to everyone that has already contributed

Pictures of the folks who have contributed to the project

Made with contrib.rocks.