Skip to content

Commit 74c2cf6

Browse files
authored
Merge pull request #202 from esnible/fix-weather-service
πŸ› Use current Starlette middleware conventions
2 parents 3fd7973 + d8a7d85 commit 74c2cf6

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)