Skip to content

Commit 566796b

Browse files
committed
feat: Hide agent-card access log, remove /health
We use the agent-card as health endpoint and this one should not polute the logs.
1 parent 47d80ee commit 566796b

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

adk/agenticlayer/agent_to_a2a.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from a2a.server.apps import A2AStarletteApplication
77
from a2a.server.request_handlers import DefaultRequestHandler
88
from a2a.server.tasks import InMemoryTaskStore
9+
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
910
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutor
1011
from google.adk.a2a.utils.agent_card_builder import AgentCardBuilder
1112
from google.adk.agents.base_agent import BaseAgent
@@ -17,13 +18,16 @@
1718
from google.adk.sessions.in_memory_session_service import InMemorySessionService
1819
from opentelemetry.instrumentation.starlette import StarletteInstrumentor
1920
from starlette.applications import Starlette
20-
from starlette.requests import Request
21-
from starlette.responses import JSONResponse
22-
from starlette.routing import Route
2321

2422
from .callback_tracer_plugin import CallbackTracerPlugin
2523

2624

25+
class HealthCheckFilter(logging.Filter):
26+
def filter(self, record: logging.LogRecord) -> bool:
27+
# Check if the log message contains the well known path of the card, which is used for health checks
28+
return record.getMessage().find(AGENT_CARD_WELL_KNOWN_PATH) == -1
29+
30+
2731
def to_a2a(agent: BaseAgent) -> Starlette:
2832
"""Convert an ADK agent to a A2A Starlette application.
2933
This is an adaption of google.adk.a2a.utils.agent_to_a2a.
@@ -44,6 +48,10 @@ def to_a2a(agent: BaseAgent) -> Starlette:
4448
setup_adk_logger(log_level) # type: ignore
4549
logger = logging.getLogger(__name__)
4650

51+
# Filter out health check logs from uvicorn access logger
52+
uvicorn_access_logger = logging.getLogger("uvicorn.access")
53+
uvicorn_access_logger.addFilter(HealthCheckFilter())
54+
4755
async def create_runner() -> Runner:
4856
"""Create a runner for the agent."""
4957
return Runner(
@@ -65,10 +73,6 @@ async def create_runner() -> Runner:
6573

6674
request_handler = DefaultRequestHandler(agent_executor=agent_executor, task_store=task_store)
6775

68-
# Add a simple health check endpoint for readiness/liveness probes
69-
def health(_: Request) -> JSONResponse:
70-
return JSONResponse(content={"status": "healthy"})
71-
7276
# Get the agent card URL from environment variable *only*
7377
# At this point, we don't know the applications port and the host is unknown when running in k8s or similar
7478
# A2A_AGENT_CARD_URL is deprecated but still supported for backwards compatibility
@@ -100,7 +104,7 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:
100104
yield
101105

102106
# Create a Starlette app that will be configured during startup
103-
starlette_app = Starlette(lifespan=lifespan, routes=[Route("/health", health)])
107+
starlette_app = Starlette(lifespan=lifespan)
104108

105109
# Instrument the Starlette app with OpenTelemetry
106110
StarletteInstrumentor().instrument_app(starlette_app)

adk/tests/test_a2a_starlette.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ def client(self, starlette_app: Starlette) -> TestClient:
2323
"""Create a test client."""
2424
return TestClient(starlette_app)
2525

26-
def test_health_endpoint(self, client: TestClient) -> None:
27-
"""Test that the health check endpoint works."""
28-
response = client.get("/health")
29-
assert response.status_code == 200
30-
data = response.json()
31-
assert data["status"] == "healthy"
32-
3326
def test_agent_card_endpoint(self, starlette_app: Starlette, client: TestClient) -> None:
3427
"""Test that the agent card is available at /.well-known/agent-card.json"""
3528

0 commit comments

Comments
 (0)