ccproxy.observability.streaming_response¶
ccproxy.observability.streaming_response
¶
FastAPI StreamingResponse with automatic access logging on completion.
This module provides a reusable StreamingResponseWithLogging class that wraps any async generator and handles access logging when the stream completes, eliminating code duplication between different streaming endpoints.
StreamingResponseWithLogging
¶
Bases: StreamingResponse
FastAPI StreamingResponse that triggers access logging on completion.
This class wraps a streaming response generator to automatically trigger access logging when the stream completes (either successfully or with an error). This eliminates the need for manual access logging in individual stream processors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
AsyncGenerator[bytes, None] | AsyncIterator[bytes]
|
The async generator producing streaming content |
required |
request_context
|
RequestContext
|
The request context for access logging |
required |
metrics
|
PrometheusMetrics | None
|
Optional PrometheusMetrics instance for recording metrics |
None
|
status_code
|
int
|
HTTP status code for the response |
200
|
**kwargs
|
Any
|
Additional arguments passed to StreamingResponse |
{}
|