From 8ffc669b18018043d187314f4264b7b0712f3289 Mon Sep 17 00:00:00 2001 From: Ed Snible Date: Wed, 25 Mar 2026 15:39:22 -0500 Subject: [PATCH 1/2] Use current Starlette middleware conventions Signed-off-by: Ed Snible --- .../src/weather_service/agent.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/a2a/weather_service/src/weather_service/agent.py b/a2a/weather_service/src/weather_service/agent.py index a8cffeb4..c8226654 100644 --- a/a2a/weather_service/src/weather_service/agent.py +++ b/a2a/weather_service/src/weather_service/agent.py @@ -215,14 +215,16 @@ def run(): # Add tracing middleware - creates root span with MLflow/GenAI attributes app.add_middleware(BaseHTTPMiddleware, dispatch=create_tracing_middleware()) + class LogAuthorizationMiddleware(BaseHTTPMiddleware): + async def dispatch(self, request, call_next): + auth_header = request.headers.get("authorization", "No Authorization header") + logger.info( + f"🔐 Incoming request to {request.url.path} with Authorization: {auth_header[:80] + '...' if len(auth_header) > 80 else auth_header}" + ) + response = await call_next(request) + return response + # Add logging middleware - @app.middleware("http") - async def log_authorization_header(request, call_next): - auth_header = request.headers.get("authorization", "No Authorization header") - logger.info( - f"🔐 Incoming request to {request.url.path} with Authorization: {auth_header[:80] + '...' if len(auth_header) > 80 else auth_header}" - ) - response = await call_next(request) - return response + app.add_middleware(LogAuthorizationMiddleware) uvicorn.run(app, host="0.0.0.0", port=8000) From d8a7d85f01ec47e23c320637d6af77fe84af4139 Mon Sep 17 00:00:00 2001 From: Ed Snible Date: Wed, 25 Mar 2026 15:43:46 -0500 Subject: [PATCH 2/2] Format with ruff Signed-off-by: Ed Snible --- a2a/weather_service/src/weather_service/agent.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/a2a/weather_service/src/weather_service/agent.py b/a2a/weather_service/src/weather_service/agent.py index c8226654..b7574beb 100644 --- a/a2a/weather_service/src/weather_service/agent.py +++ b/a2a/weather_service/src/weather_service/agent.py @@ -216,13 +216,13 @@ def run(): app.add_middleware(BaseHTTPMiddleware, dispatch=create_tracing_middleware()) class LogAuthorizationMiddleware(BaseHTTPMiddleware): - async def dispatch(self, request, call_next): - auth_header = request.headers.get("authorization", "No Authorization header") - logger.info( - f"🔐 Incoming request to {request.url.path} with Authorization: {auth_header[:80] + '...' if len(auth_header) > 80 else auth_header}" - ) - response = await call_next(request) - return response + async def dispatch(self, request, call_next): + auth_header = request.headers.get("authorization", "No Authorization header") + logger.info( + f"🔐 Incoming request to {request.url.path} with Authorization: {auth_header[:80] + '...' if len(auth_header) > 80 else auth_header}" + ) + response = await call_next(request) + return response # Add logging middleware app.add_middleware(LogAuthorizationMiddleware)