Integrate posthog and log events to track usage (#17)

This commit is contained in:
Kerem Yilmaz
2024-03-04 15:24:18 -08:00
committed by GitHub
parent 7322eac7b9
commit 879bc616d3
9 changed files with 112 additions and 1 deletions

View File

@@ -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()