Add logfire
All checks were successful
Build and Publish Docker Image / build (push) Successful in 46s
All checks were successful
Build and Publish Docker Image / build (push) Successful in 46s
This commit is contained in:
6
app.py
6
app.py
@@ -2,6 +2,7 @@ import io
|
||||
import logging
|
||||
import re
|
||||
|
||||
import logfire
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
@@ -9,7 +10,9 @@ from pydantic import BaseModel, Field
|
||||
from weasyprint import HTML
|
||||
|
||||
# Initialize logging
|
||||
logfire.configure()
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.basicConfig(handlers=[logfire.LogfireLoggingHandler()])
|
||||
|
||||
|
||||
class PdfRequest(BaseModel):
|
||||
@@ -18,6 +21,7 @@ class PdfRequest(BaseModel):
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
logfire.instrument_fastapi(app)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -78,7 +82,7 @@ async def pdf(body: PdfRequest):
|
||||
byte_string = HTML(string=body.html).write_pdf()
|
||||
except Exception as e:
|
||||
logging.error(f"Error generating PDF: {e}")
|
||||
raise HTTPException(status_code=400, detail="Invalid HTML input")
|
||||
raise HTTPException(status_code=400, detail="Invalid HTML input") from e
|
||||
|
||||
filename = sanitize_filename(body.filename.strip() if body.filename else "hinpdof")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user