Skip to content

Commit 8ffc669

Browse files
committed
Use current Starlette middleware conventions
Signed-off-by: Ed Snible <snible@us.ibm.com>
1 parent 3fd7973 commit 8ffc669

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

  • a2a/weather_service/src/weather_service

a2a/weather_service/src/weather_service/agent.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,16 @@ def run():
215215
# Add tracing middleware - creates root span with MLflow/GenAI attributes
216216
app.add_middleware(BaseHTTPMiddleware, dispatch=create_tracing_middleware())
217217

218+
class LogAuthorizationMiddleware(BaseHTTPMiddleware):
219+
async def dispatch(self, request, call_next):
220+
auth_header = request.headers.get("authorization", "No Authorization header")
221+
logger.info(
222+
f"🔐 Incoming request to {request.url.path} with Authorization: {auth_header[:80] + '...' if len(auth_header) > 80 else auth_header}"
223+
)
224+
response = await call_next(request)
225+
return response
226+
218227
# Add logging middleware
219-
@app.middleware("http")
220-
async def log_authorization_header(request, call_next):
221-
auth_header = request.headers.get("authorization", "No Authorization header")
222-
logger.info(
223-
f"🔐 Incoming request to {request.url.path} with Authorization: {auth_header[:80] + '...' if len(auth_header) > 80 else auth_header}"
224-
)
225-
response = await call_next(request)
226-
return response
228+
app.add_middleware(LogAuthorizationMiddleware)
227229

228230
uvicorn.run(app, host="0.0.0.0", port=8000)

0 commit comments

Comments
 (0)