Posthog.Application (posthog v1.0.2)

View Source

The main application module for PostHog Elixir client.

This module handles the application lifecycle and supervises the necessary processes for the PostHog client to function properly. It primarily manages the Cachex instance used for feature flag event deduplication.

Features

  • Validates configuration before starting
  • Manages a Cachex instance for feature flag event deduplication
  • Implements LRU (Least Recently Used) caching strategy
  • Automatically prunes cache entries to maintain size limits

Cache Configuration

The Cachex instance is configured with:

  • Maximum of 50,000 entries (matching posthog-python's limit)
  • LRU (Least Recently Used) eviction policy
  • Automatic pruning every 10 seconds
  • Access tracking for LRU implementation

Usage

The application is automatically started by the Elixir runtime when included in your application's supervision tree. You don't need to start it manually.

To access the cache name in your code:

Posthog.Application.cache_name()
# Returns: :posthog_feature_flag_cache

Summary

Functions

Returns the name of the Cachex instance used for feature flag event deduplication.

Starts the PostHog application.

Functions

cache_name()

Returns the name of the Cachex instance used for feature flag event deduplication.

Returns

  • atom() - The cache name, always :posthog_feature_flag_cache at the moment

Examples

iex> Posthog.Application.cache_name()
:posthog_feature_flag_cache

start(type, args)

Starts the PostHog application.

This callback is called by the Elixir runtime when the application starts. It performs the following tasks:

  1. Validates the PostHog configuration
  2. Sets up the Cachex instance for feature flag event deduplication
  3. Starts the supervision tree

Parameters

  • _type - The type of start (ignored)
  • args - Keyword list of arguments, can include:

Returns

  • {:ok, pid()} on successful start
  • {:error, term()} on failure

Examples

# Start with default configuration
Posthog.Application.start(:normal, [])