mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-15 00:07:28 +00:00
API: Add ability to use request IDs
Identify which request is being processed to help users disambiguate which logs correspond to which request. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from uuid import uuid4
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from loguru import logger
|
||||
|
||||
@@ -25,6 +26,15 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def add_request_id(request: Request, call_next):
|
||||
"""Middleware to append an ID to a request"""
|
||||
|
||||
request.state.id = uuid4().hex
|
||||
response = await call_next(request)
|
||||
return response
|
||||
|
||||
|
||||
def setup_app():
|
||||
"""Includes the correct routers for startup"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user