Skip to content

Commit 1863359

Browse files
kdziedzic70Krzysztof Dziedzicishymko
authored
test: improved itk logging (#977)
# Description New version of itk https://github.com/a2aproject/a2a-samples/releases/tag/itk-v.015-alpha improves log readabiulity for debugging by spliting the logs of individual tested agents into separate files if the `ITK_LOG_LEVEL` environmental variable is set to "DEBUG" This PR integrates the change into python's sdk CI and updates the instruction on how to set debugging mode for tests Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Follow the [`CONTRIBUTING` Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [x] Ensure the tests and linter pass (Run `bash scripts/format.sh` from the repository root to format) - [x] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕 Co-authored-by: Krzysztof Dziedzic <dziedzick@google.com> Co-authored-by: Ivan Shymko <ishymko@google.com>
1 parent d667e4f commit 1863359

5 files changed

Lines changed: 42 additions & 4 deletions

File tree

.github/workflows/itk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
run: bash run_itk.sh
2929
working-directory: itk
3030
env:
31-
A2A_SAMPLES_REVISION: itk-v.0.11-alpha
31+
A2A_SAMPLES_REVISION: itk-v.015-alpha

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ docs/ai/ai_learnings.md
1818
itk/a2a-samples/
1919
itk/pyproto/
2020
itk/instruction.proto
21+
itk/logs/

itk/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You must set the `A2A_SAMPLES_REVISION` environment variable to specify which re
3636

3737
Example:
3838
```bash
39-
export A2A_SAMPLES_REVISION=itk-v.0.11-alpha
39+
export A2A_SAMPLES_REVISION=itk-v.015-alpha
4040
```
4141

4242
### 2. Execute Tests
@@ -52,3 +52,22 @@ The script will:
5252
- Checkout the specified revision.
5353
- Build the ITK service Docker image.
5454
- Run the tests and output results.
55+
56+
## Debugging
57+
58+
To enable debug logging and persist logs for inspection:
59+
60+
1. Set the `ITK_LOG_LEVEL` environment variable to `DEBUG`:
61+
```bash
62+
export ITK_LOG_LEVEL=DEBUG
63+
```
64+
2. Run the test script:
65+
```bash
66+
./run_itk.sh
67+
```
68+
69+
When run in `DEBUG` mode:
70+
- The `logs/` directory will be created in this directory (if it doesn't exist).
71+
- The `logs/` directory will be mounted to the container.
72+
- The test execution will produce detailed logs in `logs/` (e.g., `agent_current.log`).
73+
- The `logs/` directory will **not** be removed during cleanup.

itk/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
import base64
44
import logging
5+
import os
56
import uuid
67

78
import grpc
@@ -36,7 +37,8 @@
3637
from a2a.utils import TransportProtocol
3738

3839

39-
logging.basicConfig(level=logging.INFO)
40+
log_level = os.environ.get('ITK_LOG_LEVEL', 'INFO').upper()
41+
logging.basicConfig(level=log_level)
4042
logger = logging.getLogger(__name__)
4143

4244

@@ -352,8 +354,9 @@ async def main_async(http_port: int, grpc_port: int) -> None:
352354
grpc_port,
353355
)
354356

357+
uvicorn_log_level = os.environ.get('ITK_LOG_LEVEL', 'INFO').lower()
355358
config = uvicorn.Config(
356-
app, host='127.0.0.1', port=http_port, log_level='info'
359+
app, host='127.0.0.1', port=http_port, log_level=uvicorn_log_level
357360
)
358361
uvicorn_server = uvicorn.Server(config)
359362

itk/run_itk.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
set -ex
33

4+
# Set default log level
5+
export ITK_LOG_LEVEL="${ITK_LOG_LEVEL:-INFO}"
6+
47
# Initialize default exit code
58
RESULT=1
69

@@ -63,9 +66,21 @@ ITK_DIR=$(pwd)
6366
# Stop existing container if any
6467
docker rm -f itk-service || true
6568

69+
# Create logs directory if debug
70+
if [ "${ITK_LOG_LEVEL^^}" = "DEBUG" ]; then
71+
mkdir -p "$ITK_DIR/logs"
72+
fi
73+
74+
DOCKER_MOUNT_LOGS=""
75+
if [ "${ITK_LOG_LEVEL^^}" = "DEBUG" ]; then
76+
DOCKER_MOUNT_LOGS="-v $ITK_DIR/logs:/app/logs"
77+
fi
78+
6679
docker run -d --name itk-service \
6780
-v "$A2A_PYTHON_ROOT:/app/agents/repo" \
6881
-v "$ITK_DIR:/app/agents/repo/itk" \
82+
$DOCKER_MOUNT_LOGS \
83+
-e ITK_LOG_LEVEL="$ITK_LOG_LEVEL" \
6984
-p 8000:8000 \
7085
itk_service
7186

0 commit comments

Comments
 (0)