Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shu/maksimi/record logs new #1399

Closed
wants to merge 44 commits into from
Closed

Conversation

wintonzheng
Copy link
Contributor

@wintonzheng wintonzheng commented Dec 17, 2024


Important

Introduces a new logging system for Skyvern, including log artifact types, context management, and frontend integration for efficient log handling and display.

  • Logging System:
    • Introduces SkyvernLog and SkyvernLogRaw artifact types.
    • Adds SkyvernLogEncoder and SkyvernJSONLogEncoder for log serialization.
    • Implements save_step_logs, save_task_logs, and save_workflow_run_logs in log_artifacts.py to store logs.
    • Updates forge_log.py to include skyvern_logs_processor for context-based logging.
  • Backend Changes:
    • Modifies agent.py to call save_step_logs and save_task_logs during task and step updates.
    • Adds create_log_artifact method in manager.py for log artifact creation.
    • Updates client.py to handle log artifacts retrieval by entity ID.
  • Frontend Integration:
    • Adds Skyvern Log tab in StepArtifacts.tsx to display logs.
    • Updates ScrollableActionList.tsx to fetch artifacts using new endpoint structure.
  • API Enhancements:
    • Adds /entity_type/entity_id/artifacts endpoint in agent_protocol.py for fetching artifacts by entity type and ID.

This description was created by Ellipsis for 63829fa. It will automatically update as commits are pushed.

@wintonzheng wintonzheng mentioned this pull request Dec 17, 2024
8 tasks
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to d18b852 in 6 minutes and 15 seconds

More details
  • Looked at 933 lines of code in 16 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. skyvern/forge/sdk/db/client.py:812
  • Draft comment:
    Ensure that at least one filter is applied in get_artifacts_by_entity_id to avoid full table scans and potential performance issues.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_5m0vLQP0KJqVXjLJ


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

from skyvern.forge.sdk.db.id import generate_artifact_id
from skyvern.forge.sdk.models import Step
from skyvern.forge.sdk.schemas.observers import ObserverCruise, ObserverThought

LOG = structlog.get_logger(__name__)

PRIMARY_KEY = Literal[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an Enum instead of Literal for PRIMARY_KEY to define a set of constant values. Literal is not intended for use as a type for function parameters.

@@ -70,3 +74,13 @@ def serialize_datetime_to_isoformat(self, value: datetime) -> str:
observer_thought_id: str | None = None
signed_url: str | None = None
organization_id: str | None = None

def __getitem__(self, key: str) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __getitem__ method should handle cases where the attribute does not exist to avoid runtime errors. Consider using getattr(self, key, default) to provide a default value if the attribute is not found.

@@ -13,6 +13,7 @@ class SkyvernContext:
max_steps_override: int | None = None
tz_info: ZoneInfo | None = None
totp_codes: dict[str, str | None] = field(default_factory=dict)
log: list[dict] = field(default_factory=list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a structured log entry class for the log attribute in SkyvernContext to ensure consistency in log entry formatting.

@@ -54,6 +54,21 @@ def add_kv_pairs_to_msg(logger: logging.Logger, method_name: str, event_dict: Ev
return event_dict


def skyvern_logs_processor(logger: logging.Logger, method_name: str, event_dict: EventDict) -> EventDict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider implementing a mechanism to limit the size of the log list in skyvern_logs_processor to prevent excessive memory usage.

@wintonzheng wintonzheng force-pushed the shu/maksimi/record-logs-new branch from fcadd70 to 63829fa Compare December 17, 2024 04:08
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on 63829fa in 58 seconds

More details
  • Looked at 472 lines of code in 7 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. skyvern/forge/agent.py:53
  • Draft comment:
    Duplicate import of save_step_logs and save_task_logs. Remove the redundant import statement.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. skyvern/forge/sdk/artifact/manager.py:205
  • Draft comment:
    PRIMARY_KEY type alias is removed but still used in update_artifact_data. Ensure the type is correctly defined or updated.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. skyvern/forge/sdk/log_artifacts.py:27
  • Draft comment:
    Ensure context is always available when calling save_step_logs, save_task_logs, save_workflow_run_logs, and save_workflow_run_block_logs since with_skyvern_context decorator is removed.
  • Reason this comment was not posted:
    Comment did not seem useful.
4. skyvern/forge/sdk/routes/agent_protocol.py:530
  • Draft comment:
    Review the # type: ignore comment on get_artifacts_by_entity_id to ensure type safety and correctness.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_2IwAvw71rovhxq9W


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants