diff --git a/crates/remote/src/analytics.rs b/crates/remote/src/analytics.rs index 2cbad86d5a..602599a564 100644 --- a/crates/remote/src/analytics.rs +++ b/crates/remote/src/analytics.rs @@ -11,11 +11,23 @@ pub struct AnalyticsConfig { impl AnalyticsConfig { pub fn from_env() -> Option { - let api_key = option_env!("POSTHOG_API_KEY")?.to_string(); - let api_endpoint = option_env!("POSTHOG_API_ENDPOINT")?.to_string(); + Self::from_values( + option_env!("POSTHOG_API_KEY"), + option_env!("POSTHOG_API_ENDPOINT"), + ) + } + + fn from_values(api_key: Option<&str>, api_endpoint: Option<&str>) -> Option { + let api_key = api_key?.trim(); + let api_endpoint = api_endpoint?.trim(); + + if api_key.is_empty() || api_endpoint.is_empty() { + return None; + } + Some(Self { - posthog_api_key: api_key, - posthog_api_endpoint: api_endpoint, + posthog_api_key: api_key.to_string(), + posthog_api_endpoint: api_endpoint.to_string(), }) } }