Skip to content

feat: Add timestamps to error logs for enhanced debugging #740

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 2 commits into
base: main
Choose a base branch
from

Conversation

Vijaykv5
Copy link
Contributor

@Vijaykv5 Vijaykv5 commented Aug 12, 2025

Fixes #739

  • Enhanced logging configuration to include timestamps in all log messages (asyncio errors), so its easier to debug agent callback failures.

before :
ERROR:asyncio:Exception in callback EventConsumer.agent_task_callback() at /app/python/.venv/lib/python3.13/site-packages/a2a/server/events/event_consumer.py:153

after :

2024-01-15 14:30:26 - asyncio - ERROR - [2024-01-15 14:30:26] Asyncio exception in EventConsumer.agent_task_callback: Exception in callback EventConsumer.agent_task_callback()
Traceback (most recent call last):
  File "/app/python/.venv/lib/python3.13/site-packages/a2a/server/events/event_consumer.py", line 153, in agent_task_callback
    ...

cc : @linsun @peterj

@Copilot Copilot AI review requested due to automatic review settings August 12, 2025 10:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances logging configuration to include timestamps in error logs for better debugging of asyncio callback failures. The changes add structured logging with timestamp formatting and a custom asyncio exception handler.

  • Adds a configurable logging setup function with timestamp formatting for root, asyncio, and a2a loggers
  • Implements a custom asyncio exception handler that includes timestamps in error messages
  • Enables enhanced logging by default in the Docker environment

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
python/packages/kagent/src/kagent/cli.py Adds setup_logging_with_timestamps() function and calls it in the static command
python/packages/kagent-adk/src/kagent_adk/a2a.py Implements custom asyncio exception handler with timestamps and integrates it into the FastAPI app builder
python/Dockerfile Sets environment variable to enable enhanced logging by default

handler.setFormatter(formatter)
asyncio_logger.addHandler(handler)

#configure the a2a logger to include timestamps
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The comment is missing proper capitalization and spacing. It should be: '# Configure the a2a logger to include timestamps'

Suggested change
#configure the a2a logger to include timestamps
# Configure the a2a logger to include timestamps

Copilot uses AI. Check for mistakes.

else:
logger.error(f"[{timestamp}] Asyncio error in {context.get('source', 'unknown')}: {message}")

loop = asyncio.get_event_loop()
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

Using asyncio.get_event_loop() is deprecated and can raise RuntimeError if no event loop is running. Use asyncio.get_running_loop() inside an async context or asyncio.new_event_loop() to create a new one.

Suggested change
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()

Copilot uses AI. Check for mistakes.

Comment on lines 37 to 40
# Configure the root logger to include timestamps
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

Calling logging.basicConfig() multiple times or after other logging configuration may not work as expected. Consider checking if logging has already been configured to avoid conflicts.

Suggested change
# Configure the root logger to include timestamps
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# Configure the root logger to include timestamps, but only if not already configured
if not logging.getLogger().hasHandlers():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)

Copilot uses AI. Check for mistakes.

Signed-off-by: vijaykv5 <vijaykv2228@gmail.com>
Signed-off-by: vijaykv5 <vijaykv2228@gmail.com>
@Vijaykv5 Vijaykv5 force-pushed the fix/add-timestamps branch from 6b261b1 to 56155f4 Compare August 12, 2025 10:17
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.

[BUG] add timestamo to agent log?
1 participant