FastAPI Performance Monitoring
Errors, logs, and traces for your FastAPI applications. Scout's Python agent instruments FastAPI endpoints automatically, detects N+1 queries in SQLAlchemy, monitors background tasks, and catches memory bloat. Requires Python 3.8+ on Linux or macOS.
Errors, Logs, and Traces in One View for FastAPI Apps
Scout connects FastAPI endpoint exceptions to the full request trace and surrounding log lines in a single view. When an endpoint raises an exception, you see the error, the trace with per-operation timing, and the log context together. No switching between separate error tracking and APM tools.
Error Monitoring
Automatic exception capture across FastAPI endpoints and background tasks. Errors are linked to the originating trace with full request context, including path parameters and query parameters, so you see which endpoints are affected.
Log Management
Log output is enriched with trace context and forwarded alongside performance data. Filter logs by trace ID to see exactly what your FastAPI application was doing before, during, and after an issue.
App Traces
Transaction tracing with code-level visibility into FastAPI endpoint handlers, SQLAlchemy queries, dependency injection calls, and external HTTP requests. Detailed backtraces show the exact line of code responsible for slow responses.
N+1 Detection in SQLAlchemy for FastAPI
Scout automatically detects N+1 query patterns in SQLAlchemy within FastAPI endpoint handlers without configuration. The agent monitors database queries, identifies repeated query patterns triggered by lazy loading or loops, and shows the exact code location and performance impact of each N+1. Supports PostgreSQL, MySQL, SQLite, MariaDB, Oracle, MS SQL, and CockroachDB.
What Scout Instruments in Your FastAPI App
Scout auto-instruments FastAPI using ASGI middleware. SQLAlchemy queries, Requests and UrlLib3 HTTP client calls, ElasticSearch, PyMongo, and Redis are all captured automatically. Background tasks registered with FastAPI's BackgroundTasks appear with timing and error tracking. No manual spans or decorators required.
Works with the FastAPI frameworks you already use
Scout auto-instruments the frameworks and libraries in your stack. No manual configuration required.
Web Framework
- FastAPI
- Starlette
Task Queues
- Celery
- Dramatiq
- Huey
- RQ
Databases
- SQLAlchemy
- PyMongo
- Redis
- ElasticSearch
Other
- Requests
Memory Bloat Detection for FastAPI
FastAPI applications can accumulate memory over time, especially in endpoints handling large payloads or streaming responses. Scout detects memory bloat at the transaction level, showing which endpoints and background tasks are responsible for memory growth. This goes beyond host-level metrics by identifying the specific code paths causing the increase.
Query Your FastAPI App Data from AI Assistants and the Terminal
Scout offers hosted and local MCP servers with 17 tools, a Go CLI available via Homebrew with TOON format for LLM output, and a public API. Query your FastAPI application's errors, traces, SQLAlchemy N+1 insights, and endpoint performance from Claude Code, Cursor, or the terminal.
MCP Server
Hosted or local MCP server with 17 tools covering apps, endpoints, traces, errors, insights, background jobs, and usage data. Works with Claude Code, Cursor, VS Code Copilot, and any MCP-enabled assistant.
Scout CLI
Go binary available via Homebrew. Query app metrics, endpoint performance, traces, error groups, and insights from the terminal. Outputs human-friendly tables or TOON format for LLM consumption.
Public API
Full programmatic access to your monitoring data for building custom integrations, dashboards, or automation workflows.
Add Scout to Your FastAPI App
Get Scout running on your FastAPI app in under 3 minutes.
Install the package:
pip install scout-apmAdd ScoutApmMiddleware to your FastAPI app and configure your Scout key.
Deploy and see data in 5 minutes.
FastAPI Monitoring FAQ
What is the best monitoring tool for FastAPI?
Scout Monitoring provides integrated errors, logs, and traces for FastAPI applications. The Python agent instruments FastAPI via ASGI middleware, detects N+1 queries in SQLAlchemy automatically, tracks memory bloat at the transaction level, and connects exceptions to the full request trace. Scout is built for Python teams that want all their monitoring signals in one place.
What is the best APM for FastAPI?
Scout is a Python APM that instruments FastAPI via ASGI middleware with no changes to your endpoint handlers. SQLAlchemy query tracking with N+1 detection, error capture, log management, and memory bloat analysis are all included. The agent requires Python 3.8+ and runs on Linux and macOS.
How do I monitor FastAPI async endpoints?
Scout instruments FastAPI at the ASGI middleware level, so async endpoint handlers are monitored the same way as sync handlers. Every request appears as a transaction in Scout with timing broken down by SQLAlchemy queries, HTTP client calls, and application code. The agent is compatible with asyncio and does not block the event loop.
How do I detect slow queries in FastAPI with SQLAlchemy?
Scout automatically instruments SQLAlchemy within FastAPI endpoint handlers. Every query appears in the request trace with timing, and N+1 patterns are identified automatically with the code location and total performance impact. Both sync and async SQLAlchemy sessions are supported. Supports PostgreSQL, MySQL, SQLite, MariaDB, and CockroachDB.
Does Scout support error monitoring for FastAPI?
Yes. Scout captures exceptions from FastAPI endpoints automatically, including HTTPException and custom exception handlers. Each error is linked to the request trace and surrounding log context so you see the error, the full trace, and the log lines together in one view.
How do I add Scout to a FastAPI app?
Install the package with pip install scout-apm, add the ScoutApmMiddleware to your FastAPI application, set your Scout key and app name in the configuration, and deploy. The middleware instruments all endpoints, SQLAlchemy queries, and background tasks automatically.
Does Scout work with Pydantic and FastAPI dependency injection?
Scout instruments at the ASGI layer and captures timing for the full request lifecycle, which includes Pydantic validation and dependency resolution. Individual Pydantic validators and dependencies do not appear as separate spans, but the total time they consume is included in the endpoint transaction time.
Can I use Scout with Claude Code or Cursor for FastAPI debugging?
Yes. Scout offers hosted and local MCP servers with 17 tools that work with Claude Code, Cursor, VS Code Copilot, and any MCP-enabled assistant. You can query your FastAPI application's slow endpoint traces, SQLAlchemy N+1 insights, and error rates in natural language from your editor. The Scout CLI, available via Homebrew, gives terminal access to the same data in TOON format for LLM consumption.