Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: add sanitized error_type to pipe_scheduled_run analytics

Louis Beaumontbda2c2438a13
diff --git a/apps/screenpipe-app-tauri/lib/notifications.ts b/apps/screenpipe-app-tauri/lib/notifications.ts
index 85ff9aa0d..130b7b31e 100644
--- a/apps/screenpipe-app-tauri/lib/notifications.ts
+++ b/apps/screenpipe-app-tauri/lib/notifications.ts
@@ -4,7 +4,6 @@
import { invoke } from "@tauri-apps/api/core";
import localforage from "localforage";
-import posthog from "posthog-js";
const FIRST_RUN_SCHEDULED_KEY = "firstRunNotificationScheduled";
const FIRST_RUN_SENT_KEY = "firstRunNotificationSent";
@@ -72,7 +71,6 @@ export async function checkFirstRunNotification(): Promise<void> {
async function showFirstRunNotification(): Promise<void> {
try {
- posthog.capture("notification_scheduled", { type: "first_run" });
await invoke("show_notification_panel", {
payload: JSON.stringify({
id: "first-run-2h",
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index e466cbea1..a597709c9 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9074,7 +9074,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.2.68"
+version = "2.2.69"
dependencies = [
"anyhow",
"arboard",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs b/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
index bd8167e28..5de756d17 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
@@ -420,16 +420,19 @@ pub async fn start_embedded_server(
pipe_store,
config.port,
);
- pipe_manager.set_on_run_complete(std::sync::Arc::new(|pipe_name, success, duration_secs| {
- analytics::capture_event_nonblocking(
- "pipe_scheduled_run",
- serde_json::json!({
+ pipe_manager.set_on_run_complete(std::sync::Arc::new(
+ |pipe_name, success, duration_secs, error_type| {
+ let mut props = serde_json::json!({
"pipe": pipe_name,
"success": success,
"duration_secs": duration_secs,
- }),
- );
- }));
+ });
+ if let Some(et) = error_type {
+ props["error_type"] = serde_json::Value::String(et.to_string());
+ }
+ analytics::capture_event_nonblocking("pipe_scheduled_run", props);
+ },
+ ));
if let Some(cb) = on_pipe_output {
pipe_manager.set_on_output_line(cb);
}
diff --git a/crates/screenpipe-core/src/pipes/mod.rs b/crates/screenpipe-core/src/pipes/mod.rs
index 980489cf0..8949ab7d8 100644
--- a/crates/screenpipe-core/src/pipes/mod.rs
+++ b/crates/screenpipe-core/src/pipes/mod.rs
@@ -423,8 +423,10 @@ fn parse_error_type(stderr: &str) -> (Option<String>, Option<String>) {
/// Manages all pipes: loading, scheduling, execution, logs.
/// Callback fired after each scheduled pipe run completes.
-/// Args: (pipe_name, success, duration_secs)
-pub type OnPipeRunComplete = Arc<dyn Fn(&str, bool, f64) + Send + Sync>;
+/// Args: (pipe_name, success, duration_secs, error_type)
+/// `error_type` is a sanitized category (e.g. "rate_limited", "auth_failed", "timeout", "crash")
+/// — never contains user data.
+pub type OnPipeRunComplete = Arc<dyn Fn(&str, bool, f64, Option<&str>) + Send + Sync>;
/// Callback fired for each stdout line from a running pipe.
/// Args: (pipe_name, execution_id, line)
@@ -1079,7 +1081,7 @@ impl PipeManager {
exec_ids.remove(&pipe_name);
}
- let log = match run_result {
+ let (log, cb_error_type): (PipeRunLog, Option<String>) = match run_result {
Ok(Ok(output)) => {
let (error_type, error_message) = if !output.success {
parse_error_type(&output.stderr)
@@ -1110,14 +1112,19 @@ impl PipeManager {
.upsert_scheduler_state(&pipe_name, output.success)
.await;
}
- PipeRunLog {
+ let et = if output.success {
+ None
+ } else {
+ Some(error_type.unwrap_or_else(|| "unknown".to_string()))
+ };
+ (PipeRunLog {
pipe_name: pipe_name.clone(),
started_at,
finished_at,
success: output.success,
stdout: truncate_string(&filtered_stdout, 10_000),
stderr: truncate_string(&output.stderr, 5_000),
- }
+ }, et)
}
Ok(Err(e)) => {
if let (Some(ref store), Some(id)) = (&store_ref, exec_id) {
@@ -1136,14 +1143,14 @@ impl PipeManager {
if let Some(ref store) = store_ref {
let _ = store.upsert_scheduler_state(&pipe_name, false).await;
}
- PipeRunLog {
+ (PipeRunLog {
pipe_name: pipe_name.clone(),
started_at,
finished_at,
success: false,
stdout: String::new(),
stderr: e.to_string(),
- }
+ }, Some("crash".to_string()))
}
Err(_elapsed) => {
if let Some(handle) = removed_handle {
@@ -1172,14 +1179,14 @@ impl PipeManager {
if let Some(ref store) = store_ref {
let _ = store.upsert_scheduler_state(&pipe_name, false).await;
}
- PipeRunLog {
+ (PipeRunLog {
pipe_name: pipe_name.clone(),
started_at,
finished_at,
success: false,
stdout: String::new(),
stderr: format!("execution timed out after {}s", DEFAULT_TIMEOUT_SECS),
- }
+ }, Some("timeout".to_string()))
}
};
@@ -1205,7 +1212,7 @@ impl PipeManager {
drop(l);
if let Some(ref cb) = on_complete {
- cb(&name_for_cb, success, duration_secs);
+ cb(&name_for_cb, success, duration_secs, cb_error_type.as_deref());
}
// Clean up pipe token from server registry
@@ -2105,7 +2112,7 @@ impl PipeManager {
exec_ids.remove(&pipe_name);
}
- let log = match run_result {
+ let (log, cb_error_type): (PipeRunLog, Option<String>) = match run_result {
Ok(Ok(output)) => {
let (error_type, error_message) = if !output.success {
parse_error_type(&output.stderr)
@@ -2143,14 +2150,19 @@ impl PipeManager {
} else {
warn!("pipe '{}' failed: {}", pipe_name, output.stderr);
}
- PipeRunLog {
+ let et = if output.success {
+ None
+ } else {
+ Some(error_type.unwrap_or_else(|| "unknown".to_string()))
+ };
+ (PipeRunLog {
pipe_name: pipe_name.clone(),
started_at,
finished_at,
success: output.success,
stdout: truncate_string(&filtered_stdout, 10_000),
stderr: truncate_string(&output.stderr, 5_000),
- }
+ }, et)
}
Ok(Err(e)) => {
error!("pipe '{}' error: {}", pipe_name, e);
@@ -2170,14 +2182,14 @@ impl PipeManager {
if let Some(ref store) = store_ref {
let _ = store.upsert_scheduler_state(&pipe_name, false).await;
}
- PipeRunLog {
+ (PipeRunLog {
pipe_name: pipe_name.clone(),
started_at,
finished_at,
success: false,
stdout: String::new(),
stderr: e.to_string(),
- }
+ }, Some("crash".to_string()))
}
Err(_elapsed) => {
warn!(
@@ -2208,7 +2220,7 @@ impl PipeManager {
if let Some(ref store) = store_ref {
let _ = store.upsert_scheduler_state(&pipe_name, false).await;
}
- PipeRunLog {
+ (PipeRunLog {
pipe_name: pipe_name.clone(),
started_at,
finished_at,
@@ -2218,7 +2230,7 @@ impl PipeManager {
"execution timed out after {}s",
DEFAULT_TIMEOUT_SECS
),
- }
+ }, Some("timeout".to_string()))
}
};
@@ -2247,7 +2259,7 @@ impl PipeManager {
// Fire run-complete callback (analytics, etc.)
if let Some(ref cb) = on_complete {
- cb(&name_for_cb, success, duration_secs);
+ cb(&name_for_cb, success, duration_secs, cb_error_type.as_deref());
}
// Clean up pipe token from server registry
diff --git a/crates/screenpipe-server/src/bin/screenpipe-server.rs b/crates/screenpipe-server/src/bin/screenpipe-server.rs
index 5bbd9f7ef..c286cbb25 100644
--- a/crates/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/crates/screenpipe-server/src/bin/screenpipe-server.rs
@@ -722,16 +722,19 @@ async fn main() -> anyhow::Result<()> {
server.pipe_permissions.clone(),
),
));
- pipe_manager.set_on_run_complete(std::sync::Arc::new(|pipe_name, success, duration_secs| {
- analytics::capture_event_nonblocking(
- "pipe_scheduled_run",
- serde_json::json!({
+ pipe_manager.set_on_run_complete(std::sync::Arc::new(
+ |pipe_name, success, duration_secs, error_type| {
+ let mut props = serde_json::json!({
"pipe": pipe_name,
"success": success,
"duration_secs": duration_secs,
- }),
- );
- }));
+ });
+ if let Some(et) = error_type {
+ props["error_type"] = serde_json::Value::String(et.to_string());
+ }
+ analytics::capture_event_nonblocking("pipe_scheduled_run", props);
+ },
+ ));
pipe_manager.install_builtin_pipes().ok();
if let Err(e) = pipe_manager.load_pipes().await {
tracing::warn!("failed to load pipes: {}", e);