fix(proxy): remove per-chunk debug log in async_data_generator

Remove verbose_proxy_logger.debug that formatted every streaming chunk,
which triggered expensive Pydantic serialization on the hot path.
This commit is contained in:
Ishaan Jaffer 2026-02-18 12:33:27 -08:00
parent 437d504ef0
commit 7a233d5f06
2 changed files with 27 additions and 8 deletions

View file

@ -1955,15 +1955,10 @@ class CustomStreamWrapper:
hasattr(processed_chunk, "usage")
and getattr(processed_chunk, "usage", None) is not None
):
# Strip usage from the outgoing chunk so
# model_dump_json(exclude_none=True) drops it.
# The copy in self.chunks retains usage for
# calculate_total_usage().
# Set usage to None so model_dump_json(exclude_none=True)
# drops it. The original usage is already preserved in
# self.chunks (appended above) for calculate_total_usage().
processed_chunk.usage = None # type: ignore
# After nullifying usage, check if the chunk has any
# remaining content (delta, finish_reason, etc.).
# is_model_response_stream_empty sees usage=None and
# correctly skips it, only checking meaningful fields.
is_empty = is_model_response_stream_empty(
model_response=cast(ModelResponseStream, processed_chunk)
)

View file

@ -0,0 +1,24 @@
"""
Tests that PrometheusAuthMiddleware is a pure ASGI middleware (not BaseHTTPMiddleware).
BaseHTTPMiddleware wraps streaming responses with receive_or_disconnect per chunk,
which blocks the event loop and causes severe throughput degradation.
"""
from starlette.middleware.base import BaseHTTPMiddleware
from litellm.proxy.middleware.prometheus_auth_middleware import PrometheusAuthMiddleware
def test_is_not_base_http_middleware():
"""PrometheusAuthMiddleware must NOT inherit from BaseHTTPMiddleware."""
assert not issubclass(PrometheusAuthMiddleware, BaseHTTPMiddleware), (
"PrometheusAuthMiddleware should be a pure ASGI middleware, not BaseHTTPMiddleware. "
"BaseHTTPMiddleware causes severe streaming performance degradation."
)
def test_has_asgi_call_protocol():
"""PrometheusAuthMiddleware must implement the ASGI __call__ protocol."""
assert "__call__" in PrometheusAuthMiddleware.__dict__, (
"PrometheusAuthMiddleware must define __call__(self, scope, receive, send)"
)