Integrate posthog and log events to track usage (#17)
This commit is contained in:
@@ -8,6 +8,7 @@ import requests
|
||||
import structlog
|
||||
from playwright._impl._errors import TargetClosedError
|
||||
|
||||
from scripts import tracking
|
||||
from skyvern.exceptions import (
|
||||
BrowserStateMissingPage,
|
||||
FailedToSendWebhook,
|
||||
@@ -194,6 +195,7 @@ class ForgeAgent(Agent):
|
||||
await self.validate_step_execution(task, step)
|
||||
step, browser_state, detailed_output = await self._initialize_execution_state(task, step, workflow_run)
|
||||
step, detailed_output = await self.agent_step(task, step, browser_state, organization=organization)
|
||||
tracking.capture("skyvern-oss-agent-step-status", {"status": step.status})
|
||||
retry = False
|
||||
|
||||
# If the step failed, mark the step as failed and retry
|
||||
@@ -661,6 +663,18 @@ class ForgeAgent(Agent):
|
||||
"""
|
||||
send the task response to the webhook callback url
|
||||
"""
|
||||
# refresh the task from the db to get the latest status
|
||||
try:
|
||||
refreshed_task = await app.DATABASE.get_task(task_id=task.task_id, organization_id=task.organization_id)
|
||||
if not refreshed_task:
|
||||
LOG.error("Failed to get task from db when sending task response")
|
||||
raise TaskNotFound(task_id=task.task_id)
|
||||
except Exception as e:
|
||||
LOG.error("Failed to get task from db when sending task response", task_id=task.task_id, error=e)
|
||||
raise TaskNotFound(task_id=task.task_id) from e
|
||||
task = refreshed_task
|
||||
# log the task status as an event
|
||||
tracking.capture("skyvern-oss-agent-task-status", {"status": task.status})
|
||||
# Take one last screenshot and create an artifact before closing the browser to see the final state
|
||||
browser_state: BrowserState = await app.BROWSER_MANAGER.get_or_create_for_task(task)
|
||||
page = await browser_state.get_or_create_page()
|
||||
|
||||
Reference in New Issue
Block a user