feat(admin): add safe processing monitor and operation correlation
This commit is contained in:
@@ -20,6 +20,7 @@ import torch
|
||||
import threading
|
||||
import time
|
||||
import zipfile
|
||||
from uuid import UUID
|
||||
from urllib import request as urllib_request
|
||||
from urllib.error import URLError, HTTPError
|
||||
from contextvars import ContextVar
|
||||
@@ -66,6 +67,16 @@ async def require_service_token(request: Request, call_next):
|
||||
{"detail": "Invalid or missing service token."},
|
||||
status_code=401,
|
||||
)
|
||||
operation_id = None
|
||||
supplied_id = request.headers.get("X-Operation-Id", "")
|
||||
if len(supplied_id) == 36:
|
||||
try:
|
||||
parsed_id = UUID(supplied_id)
|
||||
if parsed_id.int:
|
||||
operation_id = str(parsed_id)
|
||||
except ValueError:
|
||||
pass
|
||||
request.state.operation_id = operation_id
|
||||
allowed = (
|
||||
EXTERNAL_AI_ENABLED
|
||||
and request.headers.get(EXTERNAL_AI_ALLOWED_HEADER, "").strip().lower() == "true"
|
||||
@@ -78,6 +89,8 @@ async def require_service_token(request: Request, call_next):
|
||||
state_token = _route_state.set(state)
|
||||
try:
|
||||
response = await call_next(request)
|
||||
if operation_id:
|
||||
response.headers["X-Operation-Id"] = operation_id
|
||||
if request.url.path.startswith("/cv/"):
|
||||
if state["provider"]:
|
||||
response.headers["X-Ai-Provider"] = state["provider"]
|
||||
|
||||
Reference in New Issue
Block a user