Enhanced PostHog Error Tracking with Detailed Messages (#6176)

This commit is contained in:
Zane
2025-12-18 13:40:31 -08:00
committed by GitHub
parent 7ff3adcc5f
commit 70ac4b4322
8 changed files with 61 additions and 10 deletions
+7 -2
View File
@@ -534,6 +534,10 @@ impl Agent {
.dispatch_tool_call(tool_call.clone(), cancellation_token.unwrap_or_default())
.await;
result.unwrap_or_else(|e| {
crate::posthog::emit_error(
"tool_execution_failed",
&format!("{}: {}", tool_call.name, e),
);
ToolCallResult::from(Err(ErrorData::new(
ErrorCode::INTERNAL_ERROR,
e.to_string(),
@@ -1242,7 +1246,7 @@ impl Agent {
}
}
Err(ref provider_err @ ProviderError::ContextLengthExceeded(_)) => {
crate::posthog::emit_error(provider_err.telemetry_type());
crate::posthog::emit_error(provider_err.telemetry_type(), &provider_err.to_string());
compaction_attempts += 1;
if compaction_attempts >= 2 {
@@ -1279,13 +1283,14 @@ impl Agent {
break;
}
Err(e) => {
crate::posthog::emit_error("compaction_failed", &e.to_string());
error!("Compaction failed: {}", e);
break;
}
}
}
Err(ref provider_err) => {
crate::posthog::emit_error(provider_err.telemetry_type());
crate::posthog::emit_error(provider_err.telemetry_type(), &provider_err.to_string());
error!("Error: {}", provider_err);
yield AgentEvent::Message(
Message::assistant().with_text(
+4
View File
@@ -137,6 +137,10 @@ impl RetryManager {
"Maximum retry attempts ({}) exceeded",
retry_config.max_retries
);
crate::posthog::emit_error(
"retry_max_exceeded",
&format!("Max retries ({}) exceeded", retry_config.max_retries),
);
return Ok(RetryResult::MaxAttemptsReached);
}
+13 -2
View File
@@ -218,10 +218,17 @@ pub fn emit_session_started() {
pub struct ErrorContext {
pub component: Option<String>,
pub action: Option<String>,
pub error_message: Option<String>,
}
pub fn emit_error(error_type: &str) {
emit_error_with_context(error_type, ErrorContext::default());
pub fn emit_error(error_type: &str, error_message: &str) {
emit_error_with_context(
error_type,
ErrorContext {
error_message: Some(error_message.to_string()),
..Default::default()
},
);
}
pub fn emit_error_with_context(error_type: &str, context: ErrorContext) {
@@ -273,6 +280,10 @@ async fn send_error_event(
if let Some(action) = &context.action {
event.insert_prop("action", action.as_str()).ok();
}
if let Some(error_message) = &context.error_message {
let sanitized = sanitize_string(error_message);
event.insert_prop("error_message", sanitized).ok();
}
if let Some(platform_version) = get_platform_version() {
event.insert_prop("platform_version", platform_version).ok();
+4 -1
View File
@@ -260,7 +260,10 @@ impl Scheduler {
match result {
Ok(_) => tracing::info!("Job '{}' completed", task_job_id),
Err(e) => tracing::error!("Job '{}' failed: {}", task_job_id, e),
Err(ref e) => {
tracing::error!("Job '{}' failed: {}", task_job_id, e);
crate::posthog::emit_error("scheduler_job_failed", &e.to_string());
}
}
})
})