Skip to content

feat(plugins): add thread-safe LogCollectorPlugin for event logging #2427

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ivanmkc
Copy link
Collaborator

@ivanmkc ivanmkc commented Aug 7, 2025

This commit introduces the LogCollectorPlugin, a plugin that collects execution logs from ADK callbacks in asynchronous environments. Logs are organized by session ID for retrieval.

The plugin uses asyncio.Lock to ensure thread-safe logging. Logs are stored in a defaultdict(list) indexed by session ID and can be retrieved with the get_logs_by_session method.

The plugin implements the following callback hooks to log contextual data:

  • on_user_message
  • before_run, after_run
  • before_agent, after_agent
  • before_model, after_model, on_model_error
  • before_tool, after_tool, on_tool_error
  • on_event

Each log entry includes the callback type and relevant data, such as invocation ID, agent name, tool name, function call ID, arguments, and results or errors.

@adk-bot
Copy link
Collaborator

adk-bot commented Aug 7, 2025

Hello @ivanmkc, thank you for your contribution!

To help us review this PR, please address the following points from our contribution guidelines:

  • Associate an Issue: All PRs, other than small documentation or typo fixes, should have an associated issue. If one doesn't exist, please create one and link it to this PR.
  • Add a Testing Plan: Please include a testing plan section in your PR description to detail how you've tested these changes.
  • Fix Failing Checks: The pyink-check, isort-check, and test (3.11) checks are currently failing. Please fix these issues so we can proceed with the review.

You can find more details in our contribution guidelines.

Response from ADK Triaging Agent

This commit introduces the `LogCollectorPlugin`, a plugin that collects execution logs from ADK callbacks in asynchronous environments. Logs are organized by session ID for retrieval.

The plugin uses `asyncio.Lock` to ensure thread-safe logging. Logs are stored in a `defaultdict(list)` indexed by session ID and can be retrieved with the `get_logs_by_session` method.

The plugin implements the following callback hooks to log contextual data:
- `on_user_message`
- `before_run`, `after_run`
- `before_agent`, `after_agent`
- `before_model`, `after_model`, `on_model_error`
- `before_tool`, `after_tool`, `on_tool_error`
- `on_event`

Each log entry includes the callback type and relevant data, such as invocation ID, agent name, tool name, function call ID, arguments, and results or errors.
@ivanmkc ivanmkc force-pushed the imkc--tool_log_collector_plugin.py branch from ffb7094 to 4696b68 Compare August 8, 2025 22:41
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