From ed7bff1ff32683fc9c620c38ed529105668e9897 Mon Sep 17 00:00:00 2001 From: Krzysztof Dziedzic Date: Thu, 16 Apr 2026 10:42:17 +0000 Subject: [PATCH] improved itk logging --- .github/workflows/itk.yaml | 2 +- .gitignore | 1 + itk/README.md | 21 ++++++++++++++++++++- itk/main.py | 7 +++++-- itk/run_itk.sh | 15 +++++++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.github/workflows/itk.yaml b/.github/workflows/itk.yaml index 3a2c58143..f846e2d7c 100644 --- a/.github/workflows/itk.yaml +++ b/.github/workflows/itk.yaml @@ -28,4 +28,4 @@ jobs: run: bash run_itk.sh working-directory: itk env: - A2A_SAMPLES_REVISION: itk-v.0.11-alpha + A2A_SAMPLES_REVISION: itk-v.015-alpha diff --git a/.gitignore b/.gitignore index bc3689e5a..14bccd39b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ docs/ai/ai_learnings.md itk/a2a-samples/ itk/pyproto/ itk/instruction.proto +itk/logs/ diff --git a/itk/README.md b/itk/README.md index 63ec68fad..eaa5f254a 100644 --- a/itk/README.md +++ b/itk/README.md @@ -36,7 +36,7 @@ You must set the `A2A_SAMPLES_REVISION` environment variable to specify which re Example: ```bash -export A2A_SAMPLES_REVISION=itk-v.0.11-alpha +export A2A_SAMPLES_REVISION=itk-v.015-alpha ``` ### 2. Execute Tests @@ -52,3 +52,22 @@ The script will: - Checkout the specified revision. - Build the ITK service Docker image. - Run the tests and output results. + +## Debugging + +To enable debug logging and persist logs for inspection: + +1. Set the `ITK_LOG_LEVEL` environment variable to `DEBUG`: + ```bash + export ITK_LOG_LEVEL=DEBUG + ``` +2. Run the test script: + ```bash + ./run_itk.sh + ``` + +When run in `DEBUG` mode: +- The `logs/` directory will be created in this directory (if it doesn't exist). +- The `logs/` directory will be mounted to the container. +- The test execution will produce detailed logs in `logs/` (e.g., `agent_current.log`). +- The `logs/` directory will **not** be removed during cleanup. diff --git a/itk/main.py b/itk/main.py index 7be7a5a20..5ce062fac 100644 --- a/itk/main.py +++ b/itk/main.py @@ -2,6 +2,7 @@ import asyncio import base64 import logging +import os import uuid import grpc @@ -36,7 +37,8 @@ from a2a.utils import TransportProtocol -logging.basicConfig(level=logging.INFO) +log_level = os.environ.get('ITK_LOG_LEVEL', 'INFO').upper() +logging.basicConfig(level=log_level) logger = logging.getLogger(__name__) @@ -352,8 +354,9 @@ async def main_async(http_port: int, grpc_port: int) -> None: grpc_port, ) + uvicorn_log_level = os.environ.get('ITK_LOG_LEVEL', 'INFO').lower() config = uvicorn.Config( - app, host='127.0.0.1', port=http_port, log_level='info' + app, host='127.0.0.1', port=http_port, log_level=uvicorn_log_level ) uvicorn_server = uvicorn.Server(config) diff --git a/itk/run_itk.sh b/itk/run_itk.sh index 80e96f9c2..2d9371c14 100755 --- a/itk/run_itk.sh +++ b/itk/run_itk.sh @@ -1,6 +1,9 @@ #!/bin/bash set -ex +# Set default log level +export ITK_LOG_LEVEL="${ITK_LOG_LEVEL:-INFO}" + # Initialize default exit code RESULT=1 @@ -63,9 +66,21 @@ ITK_DIR=$(pwd) # Stop existing container if any docker rm -f itk-service || true +# Create logs directory if debug +if [ "${ITK_LOG_LEVEL^^}" = "DEBUG" ]; then + mkdir -p "$ITK_DIR/logs" +fi + +DOCKER_MOUNT_LOGS="" +if [ "${ITK_LOG_LEVEL^^}" = "DEBUG" ]; then + DOCKER_MOUNT_LOGS="-v $ITK_DIR/logs:/app/logs" +fi + docker run -d --name itk-service \ -v "$A2A_PYTHON_ROOT:/app/agents/repo" \ -v "$ITK_DIR:/app/agents/repo/itk" \ + $DOCKER_MOUNT_LOGS \ + -e ITK_LOG_LEVEL="$ITK_LOG_LEVEL" \ -p 8000:8000 \ itk_service