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.
Dart language version: 3.7.2
Note
The OpenFeature DartServer SDK only supports the latest currently maintained Dart language versions.
TBD
See TBD for the complete API documentation.
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:
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:
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 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.
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.
Note that in accordance with the OpenFeature specification, the SDK doesn't generally log messages during flag evaluation.
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".
{"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.
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.
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.
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).
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!
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!
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()
- Give this repo a βοΈ!
- Follow us on social media:
- Twitter: @openfeature
- LinkedIn: OpenFeature
- Join us on Slack
- For more, check out our community page
Interested in contributing? Great, we'd love your help! To get started, take a look at the CONTRIBUTING guide.
Made with contrib.rocks.