[Frontend] Add --log-error-stack to print stack trace for error response (#22960)

Signed-off-by: Chen Zhang <zhangch99@outlook.com>
This commit is contained in:
Chen Zhang
2025-08-27 04:58:59 +00:00
committed by GitHub
parent 644d57d531
commit 3210264421
13 changed files with 51 additions and 8 deletions
@@ -5,6 +5,7 @@ import io
import json
import sys
import time
import traceback
from collections.abc import AsyncGenerator, Iterable, Mapping, Sequence
from concurrent.futures import ThreadPoolExecutor
from http import HTTPStatus
@@ -205,6 +206,7 @@ class OpenAIServing:
request_logger: Optional[RequestLogger],
return_tokens_as_token_ids: bool = False,
enable_force_include_usage: bool = False,
log_error_stack: bool = False,
):
super().__init__()
@@ -222,6 +224,7 @@ class OpenAIServing:
self._async_tokenizer_pool: dict[AnyTokenizer,
AsyncMicrobatchTokenizer] = {}
self.log_error_stack = log_error_stack
def _get_async_tokenizer(self, tokenizer) -> AsyncMicrobatchTokenizer:
"""
@@ -412,6 +415,12 @@ class OpenAIServing:
message: str,
err_type: str = "BadRequestError",
status_code: HTTPStatus = HTTPStatus.BAD_REQUEST) -> ErrorResponse:
if self.log_error_stack:
exc_type, _, _ = sys.exc_info()
if exc_type is not None:
traceback.print_exc()
else:
traceback.print_stack()
return ErrorResponse(error=ErrorInfo(
message=message, type=err_type, code=status_code.value))