|
24 | 24 | from fastapi.exceptions import RequestValidationError
|
25 | 25 | from fastapi.middleware.cors import CORSMiddleware
|
26 | 26 | from fastapi.responses import JSONResponse, Response, StreamingResponse
|
| 27 | +from starlette.concurrency import iterate_in_threadpool |
27 | 28 | from starlette.datastructures import State
|
28 | 29 | from starlette.routing import Mount
|
29 | 30 | from typing_extensions import assert_never
|
@@ -846,6 +847,21 @@ async def add_request_id(request: Request, call_next):
|
846 | 847 | response.headers["X-Request-Id"] = request_id
|
847 | 848 | return response
|
848 | 849 |
|
| 850 | + if envs.VLLM_DEBUG_LOG_API_SERVER_RESPONSE: |
| 851 | + logger.warning("CAUTION: Enabling log response in the API Server. " |
| 852 | + "This can include sensitive information and should be " |
| 853 | + "avoided in production.") |
| 854 | + |
| 855 | + @app.middleware("http") |
| 856 | + async def log_response(request: Request, call_next): |
| 857 | + response = await call_next(request) |
| 858 | + response_body = [ |
| 859 | + section async for section in response.body_iterator |
| 860 | + ] |
| 861 | + response.body_iterator = iterate_in_threadpool(iter(response_body)) |
| 862 | + logger.info("response_body={%s}", response_body[0].decode()) |
| 863 | + return response |
| 864 | + |
849 | 865 | for middleware in args.middleware:
|
850 | 866 | module_path, object_name = middleware.rsplit(".", 1)
|
851 | 867 | imported = getattr(importlib.import_module(module_path), object_name)
|
|
0 commit comments