Skip to content

Automate browser based workflows with AI

Add entrypoint field to global log context (#4973)

Shuchang Zhengd87a229e2b97
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/ActionCard.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/ActionCard.tsx
index 32c6837d6..d6154c374 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/ActionCard.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/ActionCard.tsx
@@ -8,13 +8,12 @@ import {
} from "@/components/ui/tooltip";
import { Separator } from "@/components/ui/separator";
import { ActionTypePill } from "@/routes/tasks/detail/ActionTypePill";
-import { cn } from "@/util/utils";
import {
CheckCircledIcon,
CrossCircledIcon,
LightningBoltIcon,
} from "@radix-ui/react-icons";
-import { useCallback } from "react";
+import { RunCard } from "./RunCard";
type Props = {
action: ActionsApiResponse;
@@ -31,29 +30,12 @@ function ActionCard({ action, onClick, active, index }: Props) {
action.status === Status.Completed ||
action.status === Status.Skipped;
- const refCallback = useCallback((element: HTMLDivElement | null) => {
- if (element && active) {
- element.scrollIntoView({
- behavior: "smooth",
- block: "start",
- });
- }
- // this should only run once at mount.
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
-
return (
- <div
- className={cn(
- "flex cursor-pointer rounded-lg border-2 border-transparent bg-slate-elevation3 hover:border-slate-50",
- {
- "border-l-destructive": !success,
- "border-l-success": success,
- "border-slate-50": active,
- },
- )}
+ <RunCard
+ active={active}
+ status={success ? "success" : "failure"}
onClick={onClick}
- ref={refCallback}
+ className="flex"
>
<div className="flex-1 space-y-2 p-4 pl-5">
<div className="flex justify-between">
@@ -102,7 +84,7 @@ function ActionCard({ action, onClick, active, index }: Props) {
</>
)}
</div>
- </div>
+ </RunCard>
);
}
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/RunCard.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/RunCard.tsx
new file mode 100644
index 000000000..db7f61806
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/RunCard.tsx
@@ -0,0 +1,68 @@
+import { cn } from "@/util/utils";
+import { useEffect, useRef } from "react";
+
+type RunCardStatus = "success" | "failure";
+
+type RunCardProps = {
+ active?: boolean;
+ status?: RunCardStatus;
+ onClick?: React.MouseEventHandler<HTMLDivElement>;
+ className?: string;
+ children: React.ReactNode;
+};
+
+function RunCard({
+ active,
+ status,
+ onClick,
+ className,
+ children,
+}: RunCardProps) {
+ const ref = useRef<HTMLDivElement | null>(null);
+
+ useEffect(() => {
+ if (ref.current && active) {
+ ref.current.scrollIntoView({
+ behavior: "smooth",
+ block: "start",
+ });
+ }
+ }, [active]);
+
+ return (
+ <div
+ className={cn(
+ "bg-slate-elevation3",
+ status != null
+ ? "rounded-lg border-2 border-transparent"
+ : "rounded-md border",
+ {
+ "cursor-pointer hover:border-slate-50": !!onClick,
+ "border-l-destructive": status === "failure",
+ "border-l-success": status === "success",
+ "border-slate-50": active,
+ },
+ className,
+ )}
+ onClick={onClick}
+ onKeyDown={
+ onClick
+ ? (e) => {
+ if (e.key === "Enter" || e.key === " ") {
+ e.preventDefault();
+ e.currentTarget.click();
+ }
+ }
+ : undefined
+ }
+ role={onClick ? "button" : undefined}
+ tabIndex={onClick ? 0 : undefined}
+ ref={ref}
+ >
+ {children}
+ </div>
+ );
+}
+
+export { RunCard };
+export type { RunCardProps, RunCardStatus };
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/ThoughtCard.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/ThoughtCard.tsx
index 2460db963..4ec04543e 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/ThoughtCard.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/ThoughtCard.tsx
@@ -1,9 +1,8 @@
import { StatusPill } from "@/components/ui/status-pill";
import { QuestionMarkIcon } from "@radix-ui/react-icons";
import { ObserverThought } from "../types/workflowRunTypes";
-import { cn } from "@/util/utils";
import { BrainIcon } from "@/components/icons/BrainIcon";
-import { useCallback } from "react";
+import { RunCard } from "./RunCard";
type Props = {
active: boolean;
@@ -12,29 +11,11 @@ type Props = {
};
function ThoughtCard({ thought, onClick, active }: Props) {
- const refCallback = useCallback((element: HTMLDivElement | null) => {
- if (element && active) {
- element.scrollIntoView({
- behavior: "smooth",
- block: "start",
- });
- }
- // this should only run once at mount.
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
-
return (
- <div
- className={cn(
- "space-y-3 rounded-md border bg-slate-elevation3 p-4 hover:border-slate-50",
- {
- "border-slate-50": active,
- },
- )}
- onClick={() => {
- onClick(thought);
- }}
- ref={refCallback}
+ <RunCard
+ active={active}
+ onClick={() => onClick(thought)}
+ className="space-y-3 p-4"
>
<div className="flex justify-between">
<div className="flex gap-3">
@@ -51,7 +32,7 @@ function ThoughtCard({ thought, onClick, active }: Props) {
{thought.answer || thought.thought}
</div>
)}
- </div>
+ </RunCard>
);
}
diff --git a/skyvern/forge/sdk/forge_log.py b/skyvern/forge/sdk/forge_log.py
index 72bae8075..5c8e18193 100644
--- a/skyvern/forge/sdk/forge_log.py
+++ b/skyvern/forge/sdk/forge_log.py
@@ -1,4 +1,6 @@
import logging
+import sys
+from pathlib import Path
from types import TracebackType
import structlog
@@ -16,6 +18,50 @@ LOGGING_LEVEL_MAP: dict[str, int] = {
"CRITICAL": logging.CRITICAL,
}
+# Resolved once at setup time and injected into every log event.
+_entrypoint: str = "unknown"
+
+
+def _get_entrypoint() -> str:
+ """Derive a human-readable entrypoint name for the current process.
+
+ For ``python -m skyvern.forge`` → ``skyvern.forge``
+ For ``python scripts/take_screenshot_worker.py`` → ``take_screenshot_worker``
+ """
+ # For -m invocations, __spec__ gives the clean module name.
+ main_mod = sys.modules.get("__main__")
+ spec = getattr(main_mod, "__spec__", None) if main_mod else None
+ spec_name = getattr(spec, "name", None) if spec else None
+ if spec_name and spec_name != "__main__":
+ if spec_name.endswith(".__main__"):
+ spec_name = spec_name[: -len(".__main__")]
+ return spec_name
+
+ # For direct script / uvicorn-reload invocations, use sys.argv[0].
+ if sys.argv and sys.argv[0] not in ("-c", "-m"):
+ argv0 = Path(sys.argv[0])
+ # Handle __main__.py paths (e.g. /path/to/skyvern/forge/__main__.py → skyvern.forge)
+ if argv0.name == "__main__.py":
+ # Walk up through Python packages (directories with __init__.py)
+ parts: list[str] = []
+ current = argv0.parent
+ while (current / "__init__.py").exists():
+ parts.append(current.name)
+ current = current.parent
+ if parts:
+ return ".".join(reversed(parts))
+ # Namespace package (no __init__.py) — use the directory name
+ return argv0.parent.name
+ return argv0.stem
+
+ return "unknown"
+
+
+def _add_entrypoint(logger: logging.Logger, method_name: str, event_dict: EventDict) -> EventDict:
+ """Inject the process entrypoint into every log event (runs for both JSON and console)."""
+ event_dict["entrypoint"] = _entrypoint
+ return event_dict
+
def add_kv_pairs_to_msg(logger: logging.Logger, method_name: str, event_dict: EventDict) -> EventDict:
"""
@@ -51,7 +97,7 @@ def add_kv_pairs_to_msg(logger: logging.Logger, method_name: str, event_dict: Ev
if context.browser_container_task_arn:
event_dict["browser_container_task_arn"] = context.browser_container_task_arn
- # Add env to the log
+ # Add process-level context to the log
event_dict["env"] = settings.ENV
event_dict["version"] = __version__
@@ -126,8 +172,6 @@ def add_error_processor(logger: logging.Logger, method_name: str, event_dict: Ev
"""
A custom processor extending error logs with additional info
"""
- import sys # noqa: PLC0415
-
exc_info = event_dict.get("exc_info")
if exc_info:
@@ -169,7 +213,6 @@ def _generate_exception_hash(exc_type: type, tb: TracebackType) -> str:
error from the same location always produces the same hash.
"""
import hashlib # noqa: PLC0415
- from pathlib import Path # noqa: PLC0415
hasher = hashlib.sha256()
@@ -274,6 +317,9 @@ def setup_logger() -> None:
"""
Setup the logger with the specified format
"""
+ global _entrypoint # noqa: PLW0603
+ _entrypoint = _get_entrypoint()
+
# logging.config.dictConfig(logging_config)
renderer = structlog.processors.JSONRenderer() if settings.JSON_LOGGING else CustomConsoleRenderer()
additional_processors = (
@@ -309,6 +355,7 @@ def setup_logger() -> None:
processors=[
structlog.stdlib.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
+ _add_entrypoint,
add_error_processor,
structlog.processors.format_exc_info,
]