Langfuse.Config (Langfuse v0.2.0)

View Source

Configuration management for the Langfuse SDK.

The SDK reads configuration from application config and environment variables. Environment variables take precedence over application config.

Application Configuration

Configure Langfuse in your config/config.exs or runtime config:

config :langfuse,
  public_key: "pk-lf-...",
  secret_key: "sk-lf-...",
  host: "https://cloud.langfuse.com",
  environment: "production",
  flush_interval: 5_000,
  batch_size: 100,
  max_retries: 3,
  enabled: true

Environment Variables

These environment variables override application config:

  • LANGFUSE_PUBLIC_KEY - API public key
  • LANGFUSE_SECRET_KEY - API secret key
  • LANGFUSE_HOST - Langfuse server URL
  • LANGFUSE_ENVIRONMENT - Environment name (e.g., "production", "staging")
  • LANGFUSE_CACERTFILE - Path to a custom CA certificate PEM file

Configuration Options

  • :public_key - Langfuse API public key (required for API calls)
  • :secret_key - Langfuse API secret key (required for API calls)
  • :host - Langfuse server URL. Defaults to "https://cloud.langfuse.com".
  • :environment - Environment name for filtering in Langfuse dashboard. Common values: "production", "staging", "development".
  • :flush_interval - Interval in milliseconds between automatic flushes. Defaults to 5,000 (5 seconds).
  • :batch_size - Maximum events per batch before automatic flush. Defaults to 100.
  • :max_retries - Maximum retry attempts for failed requests. Defaults to 3.
  • :enabled - Whether tracing is enabled. Defaults to true. Set to false to disable all tracing (useful for tests).
  • :debug - Whether debug logging is enabled. Defaults to false. When enabled, logs detailed information about HTTP requests, batching, and event processing. Useful for troubleshooting integration issues.
  • :cacertfile - Path to a custom CA certificate PEM file for self-hosted Langfuse instances with self-signed certificates.

Self-Hosted Langfuse

For self-hosted Langfuse instances, set the host:

config :langfuse,
  host: "https://langfuse.mycompany.com",
  public_key: "pk-...",
  secret_key: "sk-...",
  cacertfile: "/etc/ssl/langfuse-root-ca.pem"

Summary

Types

t()

Configuration struct containing all SDK settings.

Functions

Returns a specification to start this module under a supervisor.

Returns whether API credentials are configured.

Returns whether debug logging is enabled.

Returns whether tracing is enabled.

Returns the current configuration struct.

Returns a specific configuration value by key.

Reloads configuration from application environment.

Types

t()

@type t() :: %Langfuse.Config{
  batch_size: pos_integer(),
  cacertfile: String.t() | nil,
  debug: boolean(),
  enabled: boolean(),
  environment: String.t() | nil,
  flush_interval: pos_integer(),
  host: String.t(),
  max_retries: non_neg_integer(),
  public_key: String.t() | nil,
  secret_key: String.t() | nil
}

Configuration struct containing all SDK settings.

The struct is populated on application start from application config and environment variables.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

configured?()

@spec configured?() :: boolean()

Returns whether API credentials are configured.

Returns true if both :public_key and :secret_key are set.

Examples

Langfuse.Config.configured?()
# => true

debug?()

@spec debug?() :: boolean()

Returns whether debug logging is enabled.

When enabled, the SDK logs detailed information about HTTP requests, batching, and event processing to help troubleshoot integration issues.

Examples

Langfuse.Config.debug?()
# => false

enabled?()

@spec enabled?() :: boolean()

Returns whether tracing is enabled.

When disabled, all tracing operations become no-ops.

Examples

Langfuse.Config.enabled?()
# => true

get()

@spec get() :: t()

Returns the current configuration struct.

Examples

config = Langfuse.Config.get()
config.host
# => "https://cloud.langfuse.com"

get(key)

@spec get(atom()) :: term()

Returns a specific configuration value by key.

Examples

Langfuse.Config.get(:host)
# => "https://cloud.langfuse.com"

Langfuse.Config.get(:batch_size)
# => 100

reload()

@spec reload() :: :ok

Reloads configuration from application environment.

This is primarily useful for testing when you need to change configuration values at runtime.

Examples

Application.put_env(:langfuse, :host, "https://custom.langfuse.com")
Langfuse.Config.reload()