feat: expose recommendation streaming api
This commit is contained in:
parent
e8d20158e3
commit
41aa93c3c7
7 changed files with 473 additions and 12 deletions
|
|
@ -8,6 +8,7 @@ from typing import cast
|
|||
|
||||
import structlog
|
||||
from starlette.types import ASGIApp, Receive, Scope, Send
|
||||
from structlog.contextvars import bind_contextvars, reset_contextvars
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -71,10 +72,12 @@ class RequestTimingMiddleware:
|
|||
counters = RequestCounters()
|
||||
counter_token = _COUNTERS.set(counters)
|
||||
request_token = _REQUEST_ID.set(request_id)
|
||||
logging_tokens = bind_contextvars(request_id=request_id)
|
||||
try:
|
||||
await self.app(scope, receive, send)
|
||||
finally:
|
||||
self._log_completion(scope, request_id, started_at, counters)
|
||||
reset_contextvars(**logging_tokens)
|
||||
_COUNTERS.reset(counter_token)
|
||||
_REQUEST_ID.reset(request_token)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue