View Source Unleash behaviour (Unleash v3.0.0)

Unofficial Elixir SDK for the Unleash Feature Flag System.

Use it to check feature flags and variants via the main usage macros:

require Unleash.Macros, as: Unleash
Unleash.enabled?(:some_feature, fallback: false)
Unleash.get_variant(:some_feature_with_variants)

The SDK additionally provides a bunch of utilities to automatically set some context fields in Plug applications (see Unleash.Plug) and some utilities for propagation of context, feature flags overrides and impressions across services (see Unleash.Propagation). Note that Propagation is not a standard Unleash mechanism, but a custom extension defined and developed by Fresha.

This module just contains the "interface "of the SDK, meaning the Unleash behaviour and types. For the actual runtime implementation, check Unleash.Runtime and related modules.

Summary

Types

The Unleash Context for activation strategies evaluation. See Unleash.Context.

Option that can be passed to enabled?/2.

Type that can be used to reference a feature.

Option that can be passed to get_variant/2.

Record of a feature flag activation check.

Represents local feature overrides that can be used to force a feature evaluation value, bypassing its activation strategies.

Callbacks

Checks if the given feature is enabled.

Returns the variant for the given feature flag.

Types

@type context() :: Unleash.Context.t()

The Unleash Context for activation strategies evaluation. See Unleash.Context.

@type enabled_opt() ::
  {:allow_overrides, boolean()}
  | {:context, Unleash.Context.t()}
  | {:fallback, boolean() | nil}

Option that can be passed to enabled?/2.

  • :allow_overrides - Whether propagated overrides should be considered for the feature flag check. See Unleash.overrides/0. The default is false.
  • :context - Context that might be used to evaluate activation strategies. The default is an empty map.
  • :fallback - Fallback value that will be returned if the feature is not found in the local cache or overrides. The default is false. You can use nil if you'd like to handle missing features explicitly.
@type feature_name() :: String.t() | atom()

Type that can be used to reference a feature.

Note that :feature_a and "feature_a" reference the same feature.

@type get_variant_opt() ::
  {:context, Unleash.Context.t()} | {:fallback, Unleash.Variant.result() | nil}

Option that can be passed to get_variant/2.

  • :context - Context that might be used to evaluate activation strategies. The default is an empty map.
  • :fallback - Fallback value that will be returned if the feature is not found in the local cache. The default is the special "disabled" variant. You can use nil if you'd like to handle missing features explicitly.
@type impression() :: %{feature_name: String.t(), enabled: boolean()}

Record of a feature flag activation check.

In other words, whenever a feature flag is queried for status via enabled?/3, an impression represents the feature that was checked and the result of that check. See https://docs.getunleash.io/reference/impression-data

@type overrides() :: %{required(String.t()) => :on | :off | String.t()}

Represents local feature overrides that can be used to force a feature evaluation value, bypassing its activation strategies.

These can be inherited from the clients, see Unleash.Propagation for a high-level introduction to the topic.

Callbacks

Link to this callback

enabled?(feature_name, opts)

View Source
@callback enabled?(feature_name(), opts :: [enabled_opt()]) :: boolean() | nil

Checks if the given feature is enabled.

Link to this callback

get_variant(feature_name, opts)

View Source
@callback get_variant(feature_name(), opts :: [get_variant_opt()]) ::
  Unleash.Variant.result() | nil

Returns the variant for the given feature flag.