Flask error tracking

Flask error tracking in one line

Initialize ErrorLens before you create your Flask app and every unhandled exception is reported with its traceback, the request and the route — no extension or error handler to write.

Set up

pip install errorlens
app.py
import errorlens
from flask import Flask

errorlens.init(dsn="https://<key>@errorlens.io/<project-id>", traces_sample_rate=0.2)

app = Flask(__name__)

@app.get("/orders/<int:order_id>")
def order(order_id):
    return load_order(order_id)

What is captured

  • Exceptions raised in views, including those Flask turns into 500 responses
  • Request method, URL, headers and route (/orders/<int:order_id>)
  • Per-request context: users and tags set in one request never leak into another
  • Transactions per route with SQLAlchemy query spans and outgoing HTTP calls
  • Streaming responses, which are timed until the last chunk is sent

Flask error logging, upgraded

app.logger.exception() still works — ERROR log records become ErrorLens events and lower levels become breadcrumbs. What you gain is grouping, alerts, releases and the request context next to each traceback.

Passwords, tokens, API keys, cookies and card numbers are removed in your app and again on the server before anything is stored — see data scrubbing.

Frequently asked questions

Do I need a Flask extension?

No. Calling errorlens.init() before creating the app is enough; the Flask integration is detected automatically.

Does it work with Gunicorn and uWSGI?

Yes. The SDK is fork-safe: its background sender restarts in each worker process.

Start tracking errors in minutes

Free hosted plan with 5,000 errors a month, or self-host with no limits. No credit card.