Skip to content

FastAPI Integration

Lumberjack provides seamless integration with FastAPI applications through automatic instrumentation, async request tracing, and comprehensive error handling.

Terminal window
# Install with FastAPI support
uv add 'lumberjack_sdk[fastapi]'
from fastapi import FastAPI
from lumberjack_sdk import Lumberjack, LumberjackFastAPI
import logging
app = FastAPI(title="My API")
# Initialize Lumberjack first
Lumberjack.init(project_name="my-fastapi-app")
# Auto-instrument FastAPI
LumberjackFastAPI.instrument(app)
@app.get("/")
async def root():
logging.info("Root endpoint called")
return {"message": "Hello World"}
@app.get("/users/{user_id}")
async def get_user(user_id: int):
logging.info(f"Getting user {user_id}")
# Automatic request tracing and logging
return {"user_id": user_id}