View Source Unleash.Propagation.Plugs (Unleash v2.0.0-git-4b61)

Module that defines plugs to automatically integrate with the Unleash.Propagation mechanism.

All you have to do is plug them in your scope, pipeline, router or endpoint:

defmodule MyAppRouter do
  use Plug.Router
  import Unleash.Propagation.Plugs

  plug :extract_unleash_context
  plug :extract_unleash_overrides
  plug :track_impressions

  # Rest of your plugs...
end

You then can simply use Unleash as usual in your controllers, and all propagation features (client-supplied context, client-supplied overrides and returning feature toggles impressions) will automagically work!

See Unleash.Propagation for more details.

Summary

Functions

A generic Plug to extract an header value, transform it, and store it.

A Plug that extracts the unleash context from a request header and stores it in the process dictionary under :unleash_context.

A Plug that extracts unleash overrides from a request header and stores them in the process dictionary under :unleash_overrides.

A Plug that will make your controller track all of the feature toggles invoked while handling the request (including spawned subprocesses) and return the (deduplicated) impressions in a response header.

Functions

Link to this function

extract_header_and_store(conn, opts)

View Source
@spec extract_header_and_store(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

A generic Plug to extract an header value, transform it, and store it.

It's unlikely you'll need to use this directly, and you should simply plug extract_unleash_context/2 and extract_unleash_overrides/2 in your pipelines instead, but if you know what you're doing and you need custom behaviour, feel free to use this.

Link to this function

extract_unleash_context(conn, opts \\ [])

View Source
@spec extract_unleash_context(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

A Plug that extracts the unleash context from a request header and stores it in the process dictionary under :unleash_context.

By default it uses x-unleash-context header, but you can specify the header_name option to use a different one:

plug :extract_unleash_context, header_name: "my-custom-header"
Link to this function

extract_unleash_overrides(conn, opts \\ [])

View Source
@spec extract_unleash_overrides(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

A Plug that extracts unleash overrides from a request header and stores them in the process dictionary under :unleash_overrides.

By default it uses x-unleash-overrides header, but you can specify the header_name option to use a different one:

plug :extract_unleash_overrides, header_name: "my-custom-header"
Link to this function

track_impressions(conn, opts \\ [])

View Source
@spec track_impressions(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

A Plug that will make your controller track all of the feature toggles invoked while handling the request (including spawned subprocesses) and return the (deduplicated) impressions in a response header.

By default it uses x-unleash-impressions header, but you can specify the header_name option to use a different one:

plug :track_impressions, header_name: "my-custom-header"