-
Notifications
You must be signed in to change notification settings - Fork 243
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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'
#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() |
There was a problem hiding this comment.
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.
loop = asyncio.get_event_loop() | |
loop = asyncio.get_event_loop_policy().get_event_loop() |
Copilot uses AI. Check for mistakes.
# 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' | ||
) |
There was a problem hiding this comment.
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.
# 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>
6b261b1
to
56155f4
Compare
Fixes #739
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 :
cc : @linsun @peterj