Commit
·
e7bec6e
1
Parent(s):
af5a7b2
need better logging
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from magenta_rt import system, audio as au
|
| 2 |
import numpy as np
|
| 3 |
-
from fastapi import FastAPI, UploadFile, File, Form, Body, HTTPException, Response
|
| 4 |
import tempfile, io, base64, math, threading
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from contextlib import contextmanager
|
|
@@ -742,6 +742,22 @@ def jam_status(session_id: str):
|
|
| 742 |
def health():
|
| 743 |
return {"ok": True}
|
| 744 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
@app.get("/", response_class=Response)
|
| 746 |
def read_root():
|
| 747 |
"""Root endpoint that explains what this API does"""
|
|
|
|
| 1 |
from magenta_rt import system, audio as au
|
| 2 |
import numpy as np
|
| 3 |
+
from fastapi import FastAPI, UploadFile, File, Form, Body, HTTPException, Response, Request
|
| 4 |
import tempfile, io, base64, math, threading
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from contextlib import contextmanager
|
|
|
|
| 742 |
def health():
|
| 743 |
return {"ok": True}
|
| 744 |
|
| 745 |
+
@app.middleware("http")
|
| 746 |
+
async def log_requests(request: Request, call_next):
|
| 747 |
+
rid = request.headers.get("X-Request-ID", "-")
|
| 748 |
+
print(f"📥 {request.method} {request.url.path}?{request.url.query} [rid={rid}]")
|
| 749 |
+
try:
|
| 750 |
+
response = await call_next(request)
|
| 751 |
+
except Exception as e:
|
| 752 |
+
print(f"💥 exception for {request.url.path} [rid={rid}]: {e}")
|
| 753 |
+
raise
|
| 754 |
+
print(f"📤 {response.status_code} {request.url.path} [rid={rid}]")
|
| 755 |
+
return response
|
| 756 |
+
|
| 757 |
+
@app.get("/ping")
|
| 758 |
+
def ping():
|
| 759 |
+
return {"ok": True}
|
| 760 |
+
|
| 761 |
@app.get("/", response_class=Response)
|
| 762 |
def read_root():
|
| 763 |
"""Root endpoint that explains what this API does"""
|