fix sync on oss side (#4797)

This commit is contained in:
Shuchang Zheng
2026-02-18 15:41:33 -08:00
committed by GitHub
parent bf92eea8ea
commit da175fee70
3 changed files with 27 additions and 17 deletions

View File

@@ -1,12 +1,16 @@
import functools
import importlib.metadata import importlib.metadata
import platform import platform
from typing import Any, Dict from typing import Any, Dict
import structlog
import typer import typer
from posthog import Posthog from posthog import Posthog
from skyvern.config import settings from skyvern.config import settings
LOG = structlog.get_logger(__name__)
posthog = Posthog( posthog = Posthog(
"phc_bVT2ugnZhMHRWqMvSRHPdeTjaPxQqT3QSsI3r5FlQR5", "phc_bVT2ugnZhMHRWqMvSRHPdeTjaPxQqT3QSsI3r5FlQR5",
host="https://app.posthog.com", host="https://app.posthog.com",
@@ -23,7 +27,9 @@ def get_oss_version() -> str:
return "unknown" return "unknown"
@functools.lru_cache(maxsize=1)
def analytics_metadata() -> Dict[str, Any]: def analytics_metadata() -> Dict[str, Any]:
# Cached: all fields are process-lifetime constants. Do not add dynamic fields here.
return { return {
"os": platform.system().lower(), "os": platform.system().lower(),
"oss_version": get_oss_version(), "oss_version": get_oss_version(),
@@ -38,26 +44,15 @@ def capture(
event: str, event: str,
data: dict[str, Any] | None = None, data: dict[str, Any] | None = None,
) -> None: ) -> None:
# If telemetry is disabled, don't send any data
if not settings.SKYVERN_TELEMETRY: if not settings.SKYVERN_TELEMETRY:
return return
distinct_id = settings.ANALYTICS_ID
payload: dict[str, Any] = data or {}
try: try:
distinct_id = settings.ANALYTICS_ID
payload: dict[str, Any] = data or {}
posthog.capture(distinct_id=distinct_id, event=event, properties=payload) posthog.capture(distinct_id=distinct_id, event=event, properties=payload)
except Exception as e: except Exception:
payload.update( LOG.debug("analytics capture failed", event=event, exc_info=True)
{
"capture_error": str(e),
}
)
posthog.capture(
distinct_id=distinct_id,
event="failure",
properties=payload,
)
# This is the main function that will be called by the typer CLI. This is separate from capture because typer # This is the main function that will be called by the typer CLI. This is separate from capture because typer

View File

@@ -5,6 +5,8 @@ from dataclasses import dataclass, field
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import Any from typing import Any
from skyvern import analytics
class ErrorCode: class ErrorCode:
NO_ACTIVE_BROWSER = "NO_ACTIVE_BROWSER" NO_ACTIVE_BROWSER = "NO_ACTIVE_BROWSER"
@@ -63,6 +65,19 @@ def make_result(
warnings: list[str] | None = None, warnings: list[str] | None = None,
error: dict[str, Any] | None = None, error: dict[str, Any] | None = None,
) -> dict[str, Any]: ) -> dict[str, Any]:
analytics.capture(
"mcp_tool_call",
data={
**analytics.analytics_metadata(),
"tool": action,
"ok": ok,
# "total" is set by Timer.__exit__; None for early-return paths before Timer starts
"timing_ms": (timing_ms or {}).get("total"),
"error_code": error.get("code") if error else None,
"browser_mode": browser_context.mode if browser_context else None,
"session_id": browser_context.session_id if browser_context else None,
},
)
return { return {
"ok": ok, "ok": ok,
"action": action, "action": action,

View File

@@ -394,7 +394,7 @@ if settings.ENABLE_ANTHROPIC:
"anthropic/claude-opus-4-6", "anthropic/claude-opus-4-6",
["ANTHROPIC_API_KEY"], ["ANTHROPIC_API_KEY"],
supports_vision=True, supports_vision=True,
add_assistant_prefix=True, add_assistant_prefix=False, # Claude 4.6 does not support assistant message prefill
max_completion_tokens=64000, max_completion_tokens=64000,
temperature=1, # Claude 4.6 only supports temperature=1 temperature=1, # Claude 4.6 only supports temperature=1
), ),
@@ -544,7 +544,7 @@ if settings.ENABLE_BEDROCK:
"bedrock/us.anthropic.claude-opus-4-6-v1", "bedrock/us.anthropic.claude-opus-4-6-v1",
["AWS_REGION"], ["AWS_REGION"],
supports_vision=True, supports_vision=True,
add_assistant_prefix=True, add_assistant_prefix=False, # Claude 4.6 does not support assistant message prefill
max_completion_tokens=64000, max_completion_tokens=64000,
temperature=1, # Claude 4.6 only supports temperature=1 temperature=1, # Claude 4.6 only supports temperature=1
), ),