Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/goose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ shellexpand = "3.1.1"
indexmap = "2.12.0"
ignore = "0.4.25"
which = "8.0.0"
posthog-rs = "0.3.7"


[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/goose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod mcp_utils;
pub mod model;
pub mod oauth;
pub mod permission;
pub mod posthog;
pub mod prompt_template;
pub mod providers;
pub mod recipe;
Expand Down
56 changes: 56 additions & 0 deletions crates/goose/src/posthog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! PostHog telemetry - fires once per session creation.

use crate::config::{get_enabled_extensions, Config};
use crate::session::SessionManager;
use once_cell::sync::Lazy;
use std::sync::atomic::{AtomicBool, Ordering};

const POSTHOG_API_KEY: &str = "phc_RyX5CaY01VtZJCQyhSR5KFh6qimUy81YwxsEpotAftT";

static TELEMETRY_DISABLED: Lazy<AtomicBool> = Lazy::new(|| {
std::env::var("GOOSE_TELEMETRY_OFF")
.map(|v| v == "1" || v.to_lowercase() == "true")
.unwrap_or(false)
.into()
});

pub fn emit_session_started() {
if TELEMETRY_DISABLED.load(Ordering::Relaxed) {
return;
}

tokio::spawn(async {
let _ = send_session_event().await;
});
}

async fn send_session_event() -> Result<(), String> {
let client = posthog_rs::client(POSTHOG_API_KEY).await;
let mut event = posthog_rs::Event::new("session_started", "goose_user");

event.insert_prop("os", std::env::consts::OS).ok();
event.insert_prop("arch", std::env::consts::ARCH).ok();
event.insert_prop("version", env!("CARGO_PKG_VERSION")).ok();

let config = Config::global();
if let Ok(provider) = config.get_param::<String>("GOOSE_PROVIDER") {
event.insert_prop("provider", provider).ok();
}
if let Ok(model) = config.get_param::<String>("GOOSE_MODEL") {
event.insert_prop("model", model).ok();
}

let extensions = get_enabled_extensions();
event.insert_prop("extensions_count", extensions.len()).ok();

if let Ok(insights) = SessionManager::get_insights().await {
event
.insert_prop("total_sessions", insights.total_sessions)
.ok();
event
.insert_prop("total_tokens", insights.total_tokens)
.ok();
}

client.capture(event).await.map_err(|e| format!("{:?}", e))
}
5 changes: 3 additions & 2 deletions crates/goose/src/session/session_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ pub struct SessionUpdateBuilder {
#[derive(Serialize, ToSchema, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SessionInsights {
total_sessions: usize,
total_tokens: i64,
pub total_sessions: usize,
pub total_tokens: i64,
}

impl SessionUpdateBuilder {
Expand Down Expand Up @@ -887,6 +887,7 @@ impl SessionStorage {
.await?;

tx.commit().await?;
crate::posthog::emit_session_started();
Ok(session)
}

Expand Down
Loading