Skip to content

Automate browser based workflows with AI

Add PostHog analytics for setup pain points tracking (#4840)

Shuchang Zheng72caccd3d60c
diff --git a/skyvern/analytics.py b/skyvern/analytics.py
index e751b94d7..a561db4be 100644
--- a/skyvern/analytics.py
+++ b/skyvern/analytics.py
@@ -1,7 +1,8 @@
import functools
import importlib.metadata
import platform
-from typing import Any, Dict
+import traceback
+from typing import Any, Dict, Optional
import structlog
import typer
@@ -55,6 +56,63 @@ def capture(
LOG.debug("analytics capture failed", event=event, exc_info=True)
+def capture_setup_event(
+ event_name: str,
+ success: bool = True,
+ error_type: Optional[str] = None,
+ error_message: Optional[str] = None,
+ extra_data: Optional[dict[str, Any]] = None,
+) -> None:
+ """Capture a setup-related analytics event.
+
+ Args:
+ event_name: The event name (will be prefixed with 'skyvern-oss-setup-')
+ success: Whether the setup step succeeded
+ error_type: Type/category of error (e.g., 'docker_not_running', 'port_conflict')
+ error_message: Human-readable error message
+ extra_data: Additional event properties
+ """
+ data: dict[str, Any] = {
+ **analytics_metadata(),
+ "success": success,
+ }
+ if error_type:
+ data["error_type"] = error_type
+ if error_message:
+ data["error_message"] = error_message
+ if extra_data:
+ data.update(extra_data)
+
+ capture(f"skyvern-oss-setup-{event_name}", data)
+
+
+def capture_setup_error(
+ event_name: str,
+ error: Exception,
+ error_type: Optional[str] = None,
+ extra_data: Optional[dict[str, Any]] = None,
+) -> None:
+ """Capture a setup error with exception details.
+
+ Args:
+ event_name: The event name (will be prefixed with 'skyvern-oss-setup-')
+ error: The exception that occurred
+ error_type: Optional error type/category
+ extra_data: Additional event properties
+ """
+ data: dict[str, Any] = {
+ **analytics_metadata(),
+ "success": False,
+ "error_type": error_type or type(error).__name__,
+ "error_message": str(error),
+ "stack_trace": traceback.format_exc(),
+ }
+ if extra_data:
+ data.update(extra_data)
+
+ capture(f"skyvern-oss-setup-{event_name}", data)
+
+
# This is the main function that will be called by the typer CLI. This is separate from capture because typer
# doesn't support dict type input arguments.
def capture_simple(event: str) -> None:
diff --git a/skyvern/cli/browser.py b/skyvern/cli/browser.py
index df85dbd6c..bdf2e8fa9 100644
--- a/skyvern/cli/browser.py
+++ b/skyvern/cli/browser.py
@@ -7,6 +7,7 @@ import requests # type: ignore
from rich.panel import Panel
from rich.prompt import Confirm, Prompt
+from skyvern.analytics import capture_setup_event
from skyvern.utils import detect_os
from .console import console
@@ -62,9 +63,22 @@ def setup_browser_config() -> tuple[str, Optional[str], Optional[str]]:
browser_location = default_location
if not os.path.exists(browser_location):
+ capture_setup_event(
+ "chrome-detect",
+ success=False,
+ error_type="chrome_not_found",
+ error_message=f"Chrome not found at {browser_location}",
+ extra_data={"path": browser_location},
+ )
console.print(
f"[yellow]Warning: Chrome not found at {browser_location}. Please verify the location is correct.[/yellow]"
)
+ else:
+ capture_setup_event(
+ "chrome-detect",
+ success=True,
+ extra_data={"path": browser_location},
+ )
console.print("\n[bold]To use CDP connection, Chrome must be running with remote debugging enabled.[/bold]")
console.print("Example: [code]chrome --remote-debugging-port=9222[/code]")
@@ -87,6 +101,11 @@ def setup_browser_config() -> tuple[str, Optional[str], Optional[str]]:
if response.status_code == 200:
try:
browser_info = response.json()
+ capture_setup_event(
+ "chrome-debug-connect",
+ success=True,
+ extra_data={"url": remote_debugging_url, "browser": browser_info.get("Browser")},
+ )
console.print("✅ [green]Chrome is already running with remote debugging![/green]")
if "Browser" in browser_info:
console.print(f" Browser: [bold]{browser_info['Browser']}[/bold]")
@@ -95,12 +114,33 @@ def setup_browser_config() -> tuple[str, Optional[str], Optional[str]]:
console.print(f" Connected to [link]{remote_debugging_url}[/link]")
return selected_browser, browser_location, remote_debugging_url
except ValueError:
+ capture_setup_event(
+ "chrome-debug-connect",
+ success=False,
+ error_type="port_not_chrome",
+ error_message="Port is in use but doesn't appear to be Chrome with remote debugging",
+ extra_data={"url": remote_debugging_url},
+ )
console.print(
"[yellow]Port is in use, but doesn't appear to be Chrome with remote debugging.[/yellow]"
)
else:
+ capture_setup_event(
+ "chrome-debug-connect",
+ success=False,
+ error_type="chrome_bad_response",
+ error_message=f"Chrome responded with status code {response.status_code}",
+ extra_data={"url": remote_debugging_url, "status_code": response.status_code},
+ )
console.print(f"[yellow]Chrome responded with status code {response.status_code}.[/yellow]")
except requests.RequestException:
+ capture_setup_event(
+ "chrome-debug-connect",
+ success=False,
+ error_type="chrome_not_running",
+ error_message=f"No Chrome instance detected on {remote_debugging_url}",
+ extra_data={"url": remote_debugging_url},
+ )
console.print(f"[red]No Chrome instance detected on {remote_debugging_url}[/red]")
status.stop()
diff --git a/skyvern/cli/database.py b/skyvern/cli/database.py
index f780e24f2..00bb82e3e 100644
--- a/skyvern/cli/database.py
+++ b/skyvern/cli/database.py
@@ -7,6 +7,8 @@ from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.prompt import Confirm
+from skyvern.analytics import capture_setup_event
+
from .console import console
@@ -69,13 +71,16 @@ def is_postgres_container_exists() -> bool:
def setup_postgresql(no_postgres: bool = False) -> None:
"""Set up PostgreSQL database for Skyvern."""
console.print(Panel("[bold cyan]PostgreSQL Setup[/bold cyan]", border_style="blue"))
+ capture_setup_event("database-start")
if command_exists("psql") and is_postgres_running():
console.print("✨ [green]PostgreSQL is already running locally.[/green]")
+ capture_setup_event("database-local-detected", success=True, extra_data={"source": "local"})
if database_exists("skyvern", "skyvern"):
console.print("✅ [green]Database and user exist.[/green]")
else:
create_database_and_user()
+ capture_setup_event("database-complete", success=True, extra_data={"source": "local"})
return
if no_postgres:
@@ -83,9 +88,16 @@ def setup_postgresql(no_postgres: bool = False) -> None:
console.print(
"[italic]If you plan to use Docker Compose, its Postgres service will start automatically.[/italic]"
)
+ capture_setup_event("database-skip", success=True, extra_data={"reason": "no_postgres_flag"})
return
if not is_docker_running():
+ capture_setup_event(
+ "database-fail",
+ success=False,
+ error_type="docker_not_running",
+ error_message="Docker is not running or not installed",
+ )
console.print(
"[red]Docker is not running or not installed. Please install or start Docker and try again.[/red]"
)
@@ -93,6 +105,7 @@ def setup_postgresql(no_postgres: bool = False) -> None:
if is_postgres_running_in_docker():
console.print("🐳 [green]PostgreSQL is already running in a Docker container.[/green]")
+ capture_setup_event("database-docker-detected", success=True, extra_data={"source": "docker_existing"})
else:
if not no_postgres:
start_postgres = Confirm.ask(
@@ -104,15 +117,27 @@ def setup_postgresql(no_postgres: bool = False) -> None:
console.print(
"[italic]If you plan to use Docker Compose, its Postgres service will start automatically.[/italic]"
)
+ capture_setup_event("database-skip", success=True, extra_data={"reason": "user_declined"})
return
console.print("🚀 [bold green]Attempting to install PostgreSQL via Docker...[/bold green]")
if not is_postgres_container_exists():
with console.status("[bold blue]Pulling and starting PostgreSQL container...[/bold blue]"):
- run_command(
+ output, code = run_command(
"docker run --name postgresql-container -e POSTGRES_HOST_AUTH_METHOD=trust -d -p 5432:5432 postgres:14"
)
- console.print("✅ [green]PostgreSQL has been installed and started using Docker.[/green]")
+ if code != 0:
+ capture_setup_event(
+ "database-container-fail",
+ success=False,
+ error_type="docker_run_error",
+ error_message=output or "Failed to start PostgreSQL container",
+ )
+ console.print(
+ "[red]Warning: Failed to start PostgreSQL container. Check Docker logs for details.[/red]"
+ )
+ else:
+ console.print("✅ [green]PostgreSQL has been installed and started using Docker.[/green]")
else:
with console.status("[bold blue]Starting existing PostgreSQL container...[/bold blue]"):
run_command("docker start postgresql-container")
@@ -134,8 +159,17 @@ def setup_postgresql(no_postgres: bool = False) -> None:
console.print("✅ [green]Database user exists.[/green]")
else:
console.print("🚀 [bold green]Creating database user...[/bold green]")
- run_command("docker exec postgresql-container createuser -U postgres skyvern")
- console.print("✅ [green]Database user created.[/green]")
+ output, user_code = run_command("docker exec postgresql-container createuser -U postgres skyvern")
+ if user_code != 0:
+ capture_setup_event(
+ "database-user-create-fail",
+ success=False,
+ error_type="createuser_error",
+ error_message=output or "Failed to create database user",
+ )
+ console.print("[red]Warning: Failed to create database user.[/red]")
+ else:
+ console.print("✅ [green]Database user created.[/green]")
with console.status("[bold green]Checking database...[/bold green]"):
_, code = run_command(
@@ -146,5 +180,16 @@ def setup_postgresql(no_postgres: bool = False) -> None:
console.print("✅ [green]Database exists.[/green]")
else:
console.print("🚀 [bold green]Creating database...[/bold green]")
- run_command("docker exec postgresql-container createdb -U postgres skyvern -O skyvern")
- console.print("✅ [green]Database and user created successfully.[/green]")
+ output, db_code = run_command("docker exec postgresql-container createdb -U postgres skyvern -O skyvern")
+ if db_code != 0:
+ capture_setup_event(
+ "database-create-fail",
+ success=False,
+ error_type="createdb_error",
+ error_message=output or "Failed to create database",
+ )
+ console.print("[red]Warning: Failed to create database.[/red]")
+ else:
+ console.print("✅ [green]Database and user created successfully.[/green]")
+
+ capture_setup_event("database-complete", success=True, extra_data={"source": "docker"})
diff --git a/skyvern/cli/init_command.py b/skyvern/cli/init_command.py
index c02eb512f..8d477c9d7 100644
--- a/skyvern/cli/init_command.py
+++ b/skyvern/cli/init_command.py
@@ -8,6 +8,7 @@ from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.prompt import Confirm, Prompt
+from skyvern.analytics import capture_setup_event
from skyvern.forge.forge_app_initializer import start_forge_app
from skyvern.utils import migrate_db
from skyvern.utils.env_paths import resolve_backend_env_path
@@ -134,14 +135,26 @@ def init_env(
if run_local:
console.print("\n⬇️ [bold blue]Installing Chromium browser...[/bold blue]")
+ capture_setup_event("playwright-install-start")
with Progress(
SpinnerColumn(), TextColumn("[progress.description]{task.description}"), transient=True, console=console
) as progress:
progress.add_task("[bold blue]Downloading Chromium, this may take a moment...", total=None)
- subprocess.run(["playwright", "install", "chromium"], check=True)
+ try:
+ subprocess.run(["playwright", "install", "chromium"], check=True, capture_output=True, text=True)
+ capture_setup_event("playwright-install-complete", success=True)
+ except subprocess.CalledProcessError as e:
+ capture_setup_event(
+ "playwright-install-fail",
+ success=False,
+ error_type="playwright_install_error",
+ error_message=e.stderr.strip() if e.stderr else str(e),
+ )
+ raise
console.print("✅ [green]Chromium installation complete.[/green]")
console.print("\n🎉 [bold green]Skyvern setup complete![/bold green]")
+ capture_setup_event("init-complete", success=True, extra_data={"mode": "local"})
console.print("[bold]To start using Skyvern, run:[/bold]")
console.print(Padding("skyvern run server", (1, 4), style="reverse green"))
@@ -151,18 +164,35 @@ def init_env(
def init_browser() -> None:
"""Initialize only the browser configuration and install Chromium."""
console.print("\n[bold blue]Configuring browser settings...[/bold blue]")
+ capture_setup_event("browser-config-start")
browser_type, browser_location, remote_debugging_url = setup_browser_config()
update_or_add_env_var("BROWSER_TYPE", browser_type)
if browser_location:
update_or_add_env_var("CHROME_EXECUTABLE_PATH", browser_location)
if remote_debugging_url:
update_or_add_env_var("BROWSER_REMOTE_DEBUGGING_URL", remote_debugging_url)
+ capture_setup_event(
+ "browser-config-complete",
+ success=True,
+ extra_data={"browser_type": browser_type, "has_custom_path": browser_location is not None},
+ )
console.print("✅ [green]Browser configuration complete.[/green]")
console.print("\n⬇️ [bold blue]Installing Chromium browser...[/bold blue]")
+ capture_setup_event("playwright-install-start")
with Progress(
SpinnerColumn(), TextColumn("[progress.description]{task.description}"), transient=True, console=console
) as progress:
progress.add_task("[bold blue]Downloading Chromium, this may take a moment...", total=None)
- subprocess.run(["playwright", "install", "chromium"], check=True)
+ try:
+ subprocess.run(["playwright", "install", "chromium"], check=True, capture_output=True, text=True)
+ capture_setup_event("playwright-install-complete", success=True)
+ except subprocess.CalledProcessError as e:
+ capture_setup_event(
+ "playwright-install-fail",
+ success=False,
+ error_type="playwright_install_error",
+ error_message=e.stderr.strip() if e.stderr else str(e),
+ )
+ raise
console.print("✅ [green]Chromium installation complete.[/green]")
diff --git a/skyvern/cli/llm_setup.py b/skyvern/cli/llm_setup.py
index 6dad0c74b..c36b53bff 100644
--- a/skyvern/cli/llm_setup.py
+++ b/skyvern/cli/llm_setup.py
@@ -4,6 +4,7 @@ from dotenv import load_dotenv, set_key
from rich.panel import Panel
from rich.prompt import Confirm, Prompt
+from skyvern.analytics import capture_setup_event
from skyvern.utils.env_paths import resolve_backend_env_path
from .console import console
@@ -60,7 +61,9 @@ def setup_llm_providers() -> None:
"""Configure Large Language Model (LLM) Providers."""
console.print(Panel("[bold magenta]LLM Provider Configuration[/bold magenta]", border_style="purple"))
console.print("[italic]Note: All information provided here will be stored only on your local machine.[/italic]")
+ capture_setup_event("llm-start")
model_options: list[str] = []
+ enabled_providers: list[str] = []
console.print("\n[bold blue]--- OpenAI Configuration ---[/bold blue]")
console.print("To enable OpenAI, you must have an OpenAI API key.")
@@ -72,6 +75,7 @@ def setup_llm_providers() -> None:
else:
update_or_add_env_var("OPENAI_API_KEY", openai_api_key)
update_or_add_env_var("ENABLE_OPENAI", "true")
+ enabled_providers.append("openai")
model_options.extend(
[
"OPENAI_GPT5",
@@ -95,6 +99,7 @@ def setup_llm_providers() -> None:
else:
update_or_add_env_var("ANTHROPIC_API_KEY", anthropic_api_key)
update_or_add_env_var("ENABLE_ANTHROPIC", "true")
+ enabled_providers.append("anthropic")
model_options.extend(
[
"ANTHROPIC_CLAUDE4.5_OPUS",
@@ -123,6 +128,7 @@ def setup_llm_providers() -> None:
update_or_add_env_var("AZURE_API_BASE", azure_api_base)
update_or_add_env_var("AZURE_API_VERSION", azure_api_version)
update_or_add_env_var("ENABLE_AZURE", "true")
+ enabled_providers.append("azure")
model_options.append("AZURE_OPENAI")
else:
update_or_add_env_var("ENABLE_AZURE", "false")
@@ -137,6 +143,7 @@ def setup_llm_providers() -> None:
else:
update_or_add_env_var("GEMINI_API_KEY", gemini_api_key)
update_or_add_env_var("ENABLE_GEMINI", "true")
+ enabled_providers.append("gemini")
else:
update_or_add_env_var("ENABLE_GEMINI", "false")
@@ -150,6 +157,7 @@ def setup_llm_providers() -> None:
else:
update_or_add_env_var("NOVITA_API_KEY", novita_api_key)
update_or_add_env_var("ENABLE_NOVITA", "true")
+ enabled_providers.append("novita")
model_options.extend(
[
"NOVITA_LLAMA_3_2_11B_VISION",
@@ -173,7 +181,7 @@ def setup_llm_providers() -> None:
else:
update_or_add_env_var("VOLCENGINE_API_KEY", volcengine_api_key)
update_or_add_env_var("ENABLE_VOLCENGINE", "true")
-
+ enabled_providers.append("volcengine")
model_options.extend(
[
"VOLCENGINE_DOUBAO_SEED_1_6",
@@ -211,11 +219,18 @@ def setup_llm_providers() -> None:
update_or_add_env_var("OPENAI_COMPATIBLE_API_VERSION", openai_compatible_api_version)
update_or_add_env_var("ENABLE_OPENAI_COMPATIBLE", "true")
+ enabled_providers.append("openai_compatible")
model_options.append("OPENAI_COMPATIBLE")
else:
update_or_add_env_var("ENABLE_OPENAI_COMPATIBLE", "false")
if not model_options:
+ capture_setup_event(
+ "llm-no-provider",
+ success=False,
+ error_type="no_provider_enabled",
+ error_message="No LLM providers were enabled during setup",
+ )
console.print(
Panel(
"[bold red]No LLM providers enabled.[/bold red]\n"
@@ -237,5 +252,14 @@ def setup_llm_providers() -> None:
chosen_model = model_options[int(chosen_model_idx) - 1]
console.print(f"🎉 [bold green]Chosen LLM Model: {chosen_model}[/bold green]")
update_or_add_env_var("LLM_KEY", chosen_model)
+ capture_setup_event(
+ "llm-complete",
+ success=True,
+ extra_data={
+ "enabled_providers": enabled_providers,
+ "chosen_model": chosen_model,
+ "provider_count": len(enabled_providers),
+ },
+ )
console.print("✅ [green]LLM provider configurations updated in .env.[/green]")
diff --git a/skyvern/cli/quickstart.py b/skyvern/cli/quickstart.py
index cb80697c8..7a90d0eb2 100644
--- a/skyvern/cli/quickstart.py
+++ b/skyvern/cli/quickstart.py
@@ -9,6 +9,8 @@ from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn
from rich.prompt import Confirm
+from skyvern.analytics import capture_setup_error, capture_setup_event
+
# Import console after skyvern.cli to ensure proper initialization
from skyvern.cli.console import console
from skyvern.cli.init_command import init_env # init is used directly
@@ -27,8 +29,24 @@ def check_docker() -> bool:
stderr=subprocess.PIPE,
text=True,
)
- return result.returncode == 0
- except (FileNotFoundError, subprocess.SubprocessError):
+ is_running = result.returncode == 0
+ capture_setup_event(
+ "docker-check",
+ success=is_running,
+ error_type=None if is_running else "docker_not_running",
+ error_message=None if is_running else result.stderr.strip() if result.stderr else "Docker not running",
+ )
+ return is_running
+ except FileNotFoundError:
+ capture_setup_event(
+ "docker-check",
+ success=False,
+ error_type="docker_not_installed",
+ error_message="Docker command not found",
+ )
+ return False
+ except subprocess.SubprocessError as e:
+ capture_setup_error("docker-check", e, error_type="docker_subprocess_error")
return False
@@ -54,9 +72,17 @@ def check_postgres_container_conflict() -> bool:
def run_docker_compose_setup() -> None:
"""Run the Docker Compose setup for Skyvern."""
console.print("\n[bold blue]Setting up Skyvern with Docker Compose...[/bold blue]")
+ capture_setup_event("docker-compose-start")
# Check for postgres container conflict
if check_postgres_container_conflict():
+ capture_setup_event(
+ "docker-port-conflict",
+ success=False,
+ error_type="port_conflict",
+ error_message="PostgreSQL container 'postgresql-container' already exists on port 5432",
+ extra_data={"port": 5432},
+ )
console.print(
Panel(
"[bold yellow]Warning: Existing PostgreSQL container detected![/bold yellow]\n\n"
@@ -70,6 +96,12 @@ def run_docker_compose_setup() -> None:
proceed = Confirm.ask("Do you want to continue anyway?", default=False)
if not proceed:
console.print("[yellow]Aborting Docker Compose setup. Please remove the container and try again.[/yellow]")
+ capture_setup_event(
+ "docker-compose-abort",
+ success=False,
+ error_type="user_abort",
+ error_message="User aborted due to port conflict",
+ )
raise typer.Exit(0)
# Configure LLM provider
@@ -90,7 +122,14 @@ def run_docker_compose_setup() -> None:
text=True,
)
console.print("✅ [green]Docker Compose started successfully.[/green]")
+ capture_setup_event("docker-compose-complete", success=True)
except subprocess.CalledProcessError as e:
+ capture_setup_event(
+ "docker-compose-fail",
+ success=False,
+ error_type="docker_compose_error",
+ error_message=e.stderr.strip() if e.stderr else str(e),
+ )
console.print(f"[bold red]Error starting Docker Compose: {e.stderr}[/bold red]")
raise typer.Exit(1)
@@ -187,7 +226,14 @@ def quickstart(
try:
subprocess.run(["playwright", "install", "chromium"], check=True, capture_output=True, text=True)
console.print("✅ [green]Chromium installation complete.[/green]")
+ capture_setup_event("playwright-install-complete", success=True)
except subprocess.CalledProcessError as e:
+ capture_setup_event(
+ "playwright-install-fail",
+ success=False,
+ error_type="playwright_install_error",
+ error_message=e.stderr.strip() if e.stderr else str(e),
+ )
console.print(f"[yellow]Warning: Failed to install Chromium: {e.stderr}[/yellow]")
else:
console.print("⏭️ [yellow]Skipping Chromium installation as requested.[/yellow]")
@@ -204,8 +250,15 @@ def quickstart(
)
except KeyboardInterrupt:
+ capture_setup_event(
+ "quickstart-interrupt",
+ success=False,
+ error_type="user_interrupt",
+ error_message="Quickstart interrupted by user",
+ )
console.print("\n[bold yellow]Quickstart process interrupted by user.[/bold yellow]")
raise typer.Exit(0)
except Exception as e:
+ capture_setup_error("quickstart-fail", e, error_type="quickstart_error")
console.print(f"[bold red]Error during quickstart: {str(e)}[/bold red]")
raise typer.Exit(1)
diff --git a/skyvern/cli/utils.py b/skyvern/cli/utils.py
index f17a6c8d0..16da69e33 100644
--- a/skyvern/cli/utils.py
+++ b/skyvern/cli/utils.py
@@ -4,6 +4,7 @@ import sys
import typer
+from skyvern.analytics import capture_setup_error, capture_setup_event
from skyvern.cli.console import console
from skyvern.utils.env_paths import resolve_backend_env_path
@@ -14,6 +15,7 @@ async def start_services(server_only: bool = False) -> None:
Args:
server_only: If True, only start the server, not the UI.
"""
+ capture_setup_event("services-start", extra_data={"server_only": server_only})
try:
# Start server in the background
server_process = await asyncio.create_subprocess_exec(
@@ -27,6 +29,7 @@ async def start_services(server_only: bool = False) -> None:
# Start UI in the background
ui_process = await asyncio.create_subprocess_exec(sys.executable, "-m", "skyvern.cli.commands", "run", "ui")
+ capture_setup_event("services-running", success=True, extra_data={"server_only": server_only})
console.print("\n🎉 [bold green]Skyvern is now running![/bold green]")
console.print("🌐 [bold]Access the UI at:[/bold] [cyan]http://localhost:8080[/cyan]")
console.print(f"🔑 [bold]Your API key is in {resolve_backend_env_path()} as SKYVERN_API_KEY[/bold]")
@@ -38,6 +41,7 @@ async def start_services(server_only: bool = False) -> None:
await server_process.wait()
except Exception as e:
+ capture_setup_error("services-start-fail", e, error_type="service_startup_error")
console.print(f"[bold red]Error starting services: {str(e)}[/bold red]")
logging.error("Startup failed", exc_info=True)
raise typer.Exit(1)
diff --git a/skyvern/utils/__init__.py b/skyvern/utils/__init__.py
index dfc00800d..d30f0232a 100644
--- a/skyvern/utils/__init__.py
+++ b/skyvern/utils/__init__.py
@@ -32,10 +32,19 @@ def setup_windows_event_loop_policy() -> None:
def migrate_db() -> None:
- alembic_cfg = Config()
- path = f"{REPO_ROOT_DIR}/alembic"
- alembic_cfg.set_main_option("script_location", path)
- command.upgrade(alembic_cfg, "head")
+ # Import here to avoid circular import (config -> utils -> analytics -> config)
+ from skyvern.analytics import capture_setup_error, capture_setup_event
+
+ capture_setup_event("migration-start")
+ try:
+ alembic_cfg = Config()
+ path = f"{REPO_ROOT_DIR}/alembic"
+ alembic_cfg.set_main_option("script_location", path)
+ command.upgrade(alembic_cfg, "head")
+ capture_setup_event("migration-complete", success=True)
+ except Exception as e:
+ capture_setup_error("migration-fail", e, error_type="alembic_migration_error")
+ raise
def detect_os() -> str: