Skip to content

Commit d6a6011

Browse files
michaelnealezanesq
andcommitted
fix: metrics on posthog (#6024)
Co-authored-by: Zane Staggs <zane@squareup.com> Co-authored-by: Zane <75694352+zanesq@users.noreply.github.com>
1 parent 52c31ed commit d6a6011

File tree

20 files changed

+689
-34
lines changed

20 files changed

+689
-34
lines changed

Cargo.lock

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/goose-cli/src/session/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ pub struct SessionSettings {
248248
}
249249

250250
pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {
251+
goose::posthog::set_session_context("cli", session_config.resume);
252+
251253
let config = Config::global();
252254

253255
let (saved_provider, saved_model_config) = if session_config.resume {

crates/goose-server/src/routes/agent.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ async fn start_agent(
105105
State(state): State<Arc<AppState>>,
106106
Json(payload): Json<StartAgentRequest>,
107107
) -> Result<Json<Session>, ErrorResponse> {
108+
goose::posthog::set_session_context("desktop", false);
109+
108110
let StartAgentRequest {
109111
working_dir,
110112
recipe,
@@ -197,6 +199,8 @@ async fn resume_agent(
197199
State(state): State<Arc<AppState>>,
198200
Json(payload): Json<ResumeAgentRequest>,
199201
) -> Result<Json<Session>, ErrorResponse> {
202+
goose::posthog::set_session_context("desktop", true);
203+
200204
let session = SessionManager::get_session(&payload.session_id, true)
201205
.await
202206
.map_err(|err| {

crates/goose/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ shellexpand = "3.1.1"
111111
indexmap = "2.12.0"
112112
ignore = "0.4.25"
113113
which = "8.0.0"
114+
posthog-rs = "0.3.7"
114115

115116

116117
[target.'cfg(target_os = "windows")'.dependencies]

crates/goose/src/agents/agent.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,8 @@ impl Agent {
11751175
no_tools_called = false;
11761176
}
11771177
}
1178-
Err(ProviderError::ContextLengthExceeded(_error_msg)) => {
1178+
Err(ref provider_err @ ProviderError::ContextLengthExceeded(_)) => {
1179+
crate::posthog::emit_error(provider_err.telemetry_type());
11791180
yield AgentEvent::Message(
11801181
Message::assistant().with_system_notification(
11811182
SystemNotificationType::InlineMessage,
@@ -1209,11 +1210,12 @@ impl Agent {
12091210
}
12101211
}
12111212
}
1212-
Err(e) => {
1213-
error!("Error: {}", e);
1213+
Err(ref provider_err) => {
1214+
crate::posthog::emit_error(provider_err.telemetry_type());
1215+
error!("Error: {}", provider_err);
12141216
yield AgentEvent::Message(
12151217
Message::assistant().with_text(
1216-
format!("Ran into this error: {e}.\n\nPlease retry if you think this is a transient or recoverable error.")
1218+
format!("Ran into this error: {provider_err}.\n\nPlease retry if you think this is a transient or recoverable error.")
12171219
)
12181220
);
12191221
break;

crates/goose/src/agents/tool_route_manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ impl ToolRouteManager {
3838

3939
pub async fn record_tool_requests(&self, requests: &[ToolRequest]) {
4040
let selector = self.router_tool_selector.lock().await.clone();
41-
if let Some(selector) = selector {
42-
for request in requests {
43-
if let Ok(tool_call) = &request.tool_call {
41+
for request in requests {
42+
if let Ok(tool_call) = &request.tool_call {
43+
if let Some(ref selector) = selector {
4444
if let Err(e) = selector.record_tool_call(&tool_call.name).await {
4545
error!("Failed to record tool call: {}", e);
4646
}

crates/goose/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod mcp_utils;
99
pub mod model;
1010
pub mod oauth;
1111
pub mod permission;
12+
pub mod posthog;
1213
pub mod prompt_template;
1314
pub mod providers;
1415
pub mod recipe;

0 commit comments

Comments
 (0)