EppoSdk.Client (Eppo SDK v0.2.3)

View Source

Client for interacting with Eppo feature flags and experiments.

Provides methods to evaluate feature flags and experiments for subjects based on targeting rules and randomization. Supports string and JSON value assignments with optional evaluation details.

Configuration

The client is configured using EppoSdk.Client.Config:

  • api_key: SDK API key for authentication (Can be configured in the Eppo SDK keys page)
  • assignment_logger: Module for logging assignments (implements EppoSdk.AssignmentLogger)
  • is_graceful_mode: Whether to fail gracefully on errors (default: true)
  • poll_interval_seconds: Interval between config polls in seconds (default: 30)
  • poll_jitter_seconds: Random jitter added to poll interval (default: 3)
  • base_url: Base URL for the Eppo API (default: https://fscdn.eppo.cloud/api)

Usage

Initialization

To create a new client, use the new/1 function with a Config struct:

config = %EppoSdk.Client.Config{api_key: "your-api-key", assignment_logger: YourApp.AssignmentLogger}
{:ok, client} = EppoSdk.Client.new(config)

Evaluating Feature Flags

Use the client to evaluate feature flags and experiments for subjects:

assignment = EppoSdk.Client.get_string_assignment(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  "default")

Note that these functions will never return an error or nil value. When an error occurs, the client will return the default value.

Debugging with get_assignment_details

To get more information about the assignment, you can use get_assignment_details functions. These functions return a tuple with the assignment value and a map of additional details. This is less efficient than using the get_assignment functions, and should only be used for debugging.

{value, details} = EppoSdk.Client.get_string_assignment_details(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  "default")

Summary

Functions

Assigns a boolean variant based on the provided flag configuration.

Like get_boolean_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

Assigns an integer variant based on the provided flag configuration.

Like get_integer_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

Assigns a JSON variant based on the provided flag configuration. Returns a Map

Like get_json_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

Assigns a numeric (float) variant based on the provided flag configuration.

Like get_numeric_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

Assigns a string variant based on the provided flag configuration.

Like get_string_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

Creates a new Eppo client for evaluating feature flags.

Waits for client to fetch configuration and get ready to serve assignments.

Functions

get_boolean_assignment(client, flag_key, subject_key, subject_attributes, default)

Assigns a boolean variant based on the provided flag configuration.

Parameters

  • flag_key: Identifies which set of configuration rules to use
  • subject_key: Unique identifier for the subject (usually a user ID)
  • subject_attributes: Optional key-value pairs for rule evaluation
  • default: Fallback value if assignment fails
assignment = EppoSdk.Client.get_boolean_assignment(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  false)

get_boolean_assignment_details(client, flag_key, subject_key, subject_attributes, default)

Like get_boolean_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

get_integer_assignment(client, flag_key, subject_key, subject_attributes, default)

Assigns an integer variant based on the provided flag configuration.

Parameters

  • flag_key: Identifies which set of configuration rules to use
  • subject_key: Unique identifier for the subject (usually a user ID)
  • subject_attributes: Optional key-value pairs for rule evaluation
  • default: Fallback value if assignment fails
assignment = EppoSdk.Client.get_integer_assignment(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  10)

get_integer_assignment_details(client, flag_key, subject_key, subject_attributes, default)

Like get_integer_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

get_json_assignment(client, flag_key, subject_key, subject_attributes, default)

Assigns a JSON variant based on the provided flag configuration. Returns a Map

Parameters

  • flag_key: Identifies which set of configuration rules to use
  • subject_key: Unique identifier for the subject (usually a user ID)
  • subject_attributes: Optional key-value pairs for rule evaluation
  • default: Fallback Map if assignment fails
assignment = EppoSdk.Client.get_json_assignment(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  %{"default" => "value"})

get_json_assignment_details(client, flag_key, subject_key, subject_attributes, default)

Like get_json_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

get_numeric_assignment(client, flag_key, subject_key, subject_attributes, default)

Assigns a numeric (float) variant based on the provided flag configuration.

Parameters

  • flag_key: Identifies which set of configuration rules to use
  • subject_key: Unique identifier for the subject (usually a user ID)
  • subject_attributes: Optional key-value pairs for rule evaluation
  • default: Fallback value if assignment fails
assignment = EppoSdk.Client.get_numeric_assignment(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  3.14159)

get_numeric_assignment_details(client, flag_key, subject_key, subject_attributes, default)

Like get_numeric_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

get_string_assignment(client, flag_key, subject_key, subject_attributes, default)

Assigns a string variant based on the provided flag configuration.

Parameters

  • flag_key: Identifies which set of configuration rules to use
  • subject_key: Unique identifier for the subject (usually a user ID)
  • subject_attributes: Optional key-value pairs for rule evaluation
  • default: Fallback value if assignment fails
assignment = EppoSdk.Client.get_string_assignment(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  "default")

get_string_assignment_details(client, flag_key, subject_key, subject_attributes, default)

Like get_string_assignment/4 but returns additional evaluation details. Returns {value, details} tuple.

{value, details} = EppoSdk.Client.get_string_assignment_details(
  client,
  "flag-key",
  "user-123",
  %{"country" => "US", "age" => 25},
  "default")

new(config)

Creates a new Eppo client for evaluating feature flags.

Takes a Config struct and returns {:ok, client} on success or {:error, reason} on failure.

{:ok, client} = EppoSdk.Client.new(config)

wait_for_initialization(client, timeout_seconds \\ 1.0)

Waits for client to fetch configuration and get ready to serve assignments.

This method blocks the current thread until configuration is successfully fetched or timeout_seconds passes.

Parameters

  • timeout_seconds: Timeout in seconds (default: 1.0)

Usage

EppoSdk.Client.wait_for_initialization(client, 2.0)