Skip to main content

init_posthog_client_from_env

Function init_posthog_client_from_env 

Source
pub async fn init_posthog_client_from_env() -> Option<Arc<Client>>
Expand description

Constructs a PostHog client from environment variables and returns it wrapped in an Arc.

This function is a pure factory: it does not write to posthog_client_slot. Callers must invoke install_posthog_client with the result — including passing None when the factory returns None — so that any stale client from a prior run in the same process is cleared rather than left behind.

Returns None when the API key env var is absent, or the SDK refuses to initialise.