Skip to content

Commit

Permalink
Add ENABLE_LOG_ARTIFACTS env variable; Disable log artifacts by default
Browse files Browse the repository at this point in the history
  • Loading branch information
satansdeer committed Dec 17, 2024
1 parent 63829fa commit 9eda7ca
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ PORT=8000
# Analytics configuration:
# Distinct analytics ID (a UUID is generated if left blank).
ANALYTICS_ID="anonymous"

# Enable recording skyvern logs as artifacts
ENABLE_LOG_ARTIFACTS=false
5 changes: 4 additions & 1 deletion skyvern-frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ VITE_ARTIFACT_API_BASE_URL=http://localhost:9090
VITE_WSS_BASE_URL=ws://localhost:8000/api/v1

# your api key - for x-api-key header
VITE_SKYVERN_API_KEY=YOUR_API_KEY
VITE_SKYVERN_API_KEY=YOUR_API_KEY

# Enable recording skyvern logs as artifacts
VITE_ENABLE_LOG_ARTIFACTS=false
15 changes: 11 additions & 4 deletions skyvern-frontend/src/routes/tasks/detail/StepArtifacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { Artifact } from "./Artifact";

const enable_log_artifacts =
import.meta.env.VITE_ENABLE_LOG_ARTIFACTS === "true";

type Props = {
id: string;
stepProps: StepApiResponse;
Expand Down Expand Up @@ -111,7 +114,9 @@ function StepArtifacts({ id, stepProps }: Props) {
<TabsTrigger value="llm_response_parsed">Action List</TabsTrigger>
<TabsTrigger value="html_raw">HTML (Raw)</TabsTrigger>
<TabsTrigger value="llm_request">LLM Request (Raw)</TabsTrigger>
<TabsTrigger value="skyvern_log">Skyvern Log</TabsTrigger>
{enable_log_artifacts && (
<TabsTrigger value="skyvern_log">Skyvern Log</TabsTrigger>
)}
</TabsList>
<TabsContent value="info">
<div className="flex flex-col gap-6 p-4">
Expand Down Expand Up @@ -213,9 +218,11 @@ function StepArtifacts({ id, stepProps }: Props) {
<TabsContent value="llm_request">
{llmRequest ? <Artifact type="json" artifacts={llmRequest} /> : null}
</TabsContent>
<TabsContent value="skyvern_log">
{skyvernLog ? <Artifact type="text" artifacts={skyvernLog} /> : null}
</TabsContent>
{enable_log_artifacts && (
<TabsContent value="skyvern_log">
{skyvernLog ? <Artifact type="text" artifacts={skyvernLog} /> : null}
</TabsContent>
)}
</Tabs>
);
}
Expand Down
2 changes: 2 additions & 0 deletions skyvern/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class Settings(BaseSettings):

SVG_MAX_LENGTH: int = 100000

ENABLE_LOG_ARTIFACTS: bool = False

def is_cloud_environment(self) -> bool:
"""
:return: True if env is not local, else False
Expand Down
18 changes: 17 additions & 1 deletion skyvern/forge/sdk/log_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import structlog

from skyvern.config import settings

from skyvern.forge import app
from skyvern.forge.sdk.artifact.models import ArtifactType, LogEntityType
from skyvern.forge.sdk.core import skyvern_context
Expand All @@ -10,7 +12,6 @@

LOG = structlog.get_logger()


def primary_key_from_log_entity_type(log_entity_type: LogEntityType) -> str:
if log_entity_type == LogEntityType.STEP:
return "step_id"
Expand All @@ -25,6 +26,9 @@ def primary_key_from_log_entity_type(log_entity_type: LogEntityType) -> str:


async def save_step_logs(step_id: str) -> None:
if not settings.ENABLE_LOG_ARTIFACTS:
return

context = skyvern_context.ensure_context()
log = context.log
organization_id = context.organization_id
Expand All @@ -41,6 +45,9 @@ async def save_step_logs(step_id: str) -> None:


async def save_task_logs(task_id: str) -> None:
if not settings.ENABLE_LOG_ARTIFACTS:
return

context = skyvern_context.ensure_context()
log = context.log
organization_id = context.organization_id
Expand All @@ -57,6 +64,9 @@ async def save_task_logs(task_id: str) -> None:


async def save_workflow_run_logs(workflow_run_id: str) -> None:
if not settings.ENABLE_LOG_ARTIFACTS:
return

context = skyvern_context.ensure_context()
log = context.log
organization_id = context.organization_id
Expand All @@ -73,6 +83,9 @@ async def save_workflow_run_logs(workflow_run_id: str) -> None:


async def save_workflow_run_block_logs(workflow_run_block_id: str) -> None:
if not settings.ENABLE_LOG_ARTIFACTS:
return

context = skyvern_context.ensure_context()
log = context.log
organization_id = context.organization_id
Expand Down Expand Up @@ -100,6 +113,9 @@ async def _save_log_artifacts(
workflow_run_block_id: str | None = None,
) -> None:
try:
if not settings.ENABLE_LOG_ARTIFACTS:
return

log_json = json.dumps(log, cls=SkyvernJSONLogEncoder, indent=2)

log_artifact = await app.DATABASE.get_artifact_by_entity_id(
Expand Down

0 comments on commit 9eda7ca

Please sign in to comment.