Skip to content

PoC for Structured Debug Logging - #384

Merged
MFA-X-AI merged 2 commits into
masterfrom
paul/debug_logging
Feb 27, 2025
Merged

MFA-X-AI merged 2 commits into
masterfrom
paul/debug_logging

Conversation

@treo

@treo treo commented Feb 24, 2025 •

Copy link
Copy Markdown
Member

Description

Sometimes it is quite hard to know what exactly is going on during the execution of a Xircuits file.

This implements a proof of concept for a structured debug logger. It outputs its log in a json lines format that is readable by json log tools like fblog.

For example:
image
The execution of a simple xircuits file like this produces the following output:

{"timestamp": "2025-02-24T18:02:48.109280", "level": "DEBUG", "type": "before_execution", "component": {"class": "ConcatString", "id": "3d8d1923-f750-4c77-875f-2922a2efcceb", "inputs": {"a": "Hello ", "b": "World!"}}, "ctx": {"args": "Namespace()"}}
{"timestamp": "2025-02-24T18:02:48.109280", "level": "DEBUG", "type": "after_execution", "component": {"class": "ConcatString", "id": "3d8d1923-f750-4c77-875f-2922a2efcceb", "outputs": {"out": "Hello World!"}}, "ctx": {"args": "Namespace()"}}
{"timestamp": "2025-02-24T18:02:48.109280", "level": "DEBUG", "type": "before_execution", "component": {"class": "AgentNumpyMemory", "id": "270fc40c-7462-4335-b8a4-f810bbb95738", "inputs": {}}, "ctx": {"args": "Namespace()"}}
{"timestamp": "2025-02-24T18:02:48.110280", "level": "DEBUG", "type": "after_execution", "component": {"class": "AgentNumpyMemory", "id": "270fc40c-7462-4335-b8a4-f810bbb95738", "outputs": {"memory": "<xai_components.xai_agent.agent_components.NumpyMemoryImpl object at 0x0000024B6008EA60>"}}, "ctx": {"args": "Namespace()"}}

And a tool like fblog turns this into:
image

This implementation has a couple caveats:

  • This currently only works with Components that use the SubGraphExecutor for execution of its subflows. In principle all components should use the subgraph executor for it, but it isn't guaranteed.
  • The context is always a repr of the context, as it may contain non-serializable objects
  • If a component outputs non-serializable objects, the debug logging will crash.

There are two environment variables to enable and configure debug logging:

  1. XIRCUITS_DEBUG=true enables the debug logging. In that case it will simply write to stderr
  2. XIRCUITS_DEBUG_FILE=<path> selects where the debug log should be written to.

Pull Request Type

  • Xircuits Core (Jupyterlab Related changes)
  • Xircuits Canvas (Custom RD Related changes)
  • Xircuits Component Library
  • Xircuits Project Template
  • Testing Automation
  • Documentation
  • Others (Please Specify)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Tests

Logging to stderr

Create a xircuits file and run it with XIRCUITS_DEBUG=true set. You'll see debugging output right on the terminal.

Logging to a File

Create a xircuits file and run it with XIRCUITS_DEBUG=true and XIRCUITS_DEBUG_FILE=debug.jsonl set. You'll see no debug output on the terminal, instead a file is created and you can find the debug output there.

Tested on?

  • Windows
  • Linux
  • Mac
  • Others (State here -> xxx )

@github-actions

Copy link
Copy Markdown

Binder 👈 Launch a binder notebook on branch XpressAI/xircuits/paul/debug_logging

This allows us to make ctx also structured and not crash on non-serializable outputs
@MFA-X-AI
MFA-X-AI merged commit 091f00f into master Feb 27, 2025
@MFA-X-AI
MFA-X-AI deleted the paul/debug_logging branch February 27, 2025 06:28
@treo treo mentioned this pull request Mar 5, 2025
2 of 11 tasks
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.

2 participants