Statsig.ObservabilityClient behaviour (statsig_elixir v0.23.2)
Behaviour and helper APIs for forwarding Statsig SDK metrics to an observability backend (Datadog, Prometheus, etc.) from Elixir.
An implementation is a module that implements the callbacks in this
behaviour. Use start_link/3 to launch the bridge process and pass the
returned %Statsig.ObservabilityClient.Reference{} into Statsig.Options.
Callbacks are invoked fire-and-forget by the core: the SDK does not wait for
a reply, and there is no backpressure. Callbacks should be non-blocking — a
slow callback (e.g. a synchronous HTTP push inside handle_increment) lets
the bridge process mailbox grow unbounded. Hand slow work off to another
process instead.
The core's high-cardinality tags (lcut and prev_lcut) are dropped before
the metric callbacks are invoked unless allowlisted. The synchronous
should_enable_high_cardinality_for_this_tag callback cannot round-trip over
the fire-and-forget bridge, so the allowlist is configured statically via the
:high_cardinality_tags option to start_link/3:
{:ok, ref} =
Statsig.ObservabilityClient.start_link(MyClient, nil,
high_cardinality_tags: ["lcut"]
)
Summary
Functions
Starts a bridge process for the provided implementation module.
Stops the bridge process for the given reference.
Types
Callbacks
Invoked when the bridge process shuts down gracefully (e.g. via stop/3).
A last chance for implementations that buffer metrics in their state to
flush them. Subject to the usual GenServer.terminate/2 caveats: not
guaranteed to run on abnormal exits.
Functions
@spec start_link(module(), term(), Keyword.t()) :: {:ok, Statsig.ObservabilityClient.Reference.t()} | :ignore | {:error, term()}
Starts a bridge process for the provided implementation module.
Returns {:ok, %Statsig.ObservabilityClient.Reference{}} which can be
assigned to %Statsig.Options{observability_client: reference}.
Options
:high_cardinality_tags- which of the core's high-cardinality tags to keep on metrics. The core currently consults this only for"lcut"and"prev_lcut"; other values are a no-op, and tags outside that set are always kept regardless of this option. Defaults tonil(core default:lcut/prev_lcutare dropped).
Remaining options are passed to GenServer.start_link/3.
@spec stop(Statsig.ObservabilityClient.Reference.t(), term(), non_neg_integer()) :: :ok
Stops the bridge process for the given reference.