Skip to main content

Error Explorer Flask SDK

Official Flask integration for Error Explorer error tracking.

Installation

pip install error-explorer-flask

Quick Start

from flask import Flask
from error_explorer import ErrorExplorer
from error_explorer_flask import ErrorExplorerFlask

# Initialize Error Explorer
ErrorExplorer.init({
    "token": "your-project-token",
    "environment": "production",
})

# Create Flask app and extension
app = Flask(__name__)
error_explorer = ErrorExplorerFlask(app)

@app.route("/")
def hello():
    return "Hello, World!"

if __name__ == "__main__":
    app.run()

Factory Pattern

from flask import Flask
from error_explorer_flask import ErrorExplorerFlask

error_explorer = ErrorExplorerFlask()

def create_app():
    app = Flask(__name__)
    error_explorer.init_app(app)
    return app

Configuration

Configure the extension via Flask's config:

app.config["ERROR_EXPLORER"] = {
    # Capture user info from Flask-Login
    "capture_user": True,

    # Send PII (email, IP address)
    "send_default_pii": False,

    # Capture 404 errors
    "capture_404": False,

    # Capture 403 errors
    "capture_403": False,
}

Features

Automatic Error Capture

All unhandled exceptions are automatically captured and sent to Error Explorer:

@app.route("/error")
def trigger_error():
    raise ValueError("Something went wrong")
    # This is automatically captured

Request Breadcrumbs

HTTP requests are automatically logged as breadcrumbs:

→ GET /api/users
← 200 OK

Flask-Login Integration

If you use Flask-Login, user context is automatically captured:

from flask_login import login_user

@app.route("/login")
def login():
    user = User.query.get(1)
    login_user(user)
    # User context is now attached to all errors

Logging Handler

Use the logging handler to capture log messages:

import logging
from error_explorer_flask import ErrorExplorerHandler

# Add handler to root logger
handler = ErrorExplorerHandler(level=logging.WARNING)
logging.getLogger().addHandler(handler)

# Now WARNING and above are captured
logging.warning("This will be a breadcrumb")
logging.error("This will be captured as an event")

Event Filtering with before_send

Use the before_send callback to filter or modify events before they're sent:

def before_send(event):
    # Drop events from health check endpoints
    if event.get("request", {}).get("url", "").startswith("/health"):
        return None  # Drop the event

    # Add custom tags
    event["tags"] = event.get("tags", {})
    event["tags"]["service"] = "flask-api"

    return event

ErrorExplorer.init({
    "token": "your-token",
    "before_send": before_send,
})

Manual Error Capture

from error_explorer import ErrorExplorer

@app.route("/process")
def process():
    try:
        risky_operation()
    except Exception as e:
        ErrorExplorer.get_client().capture_exception(e)
        return "Error occurred", 500

Adding Context

from error_explorer import ErrorExplorer, Breadcrumb

@app.route("/checkout")
def checkout():
    client = ErrorExplorer.get_client()

    # Add custom breadcrumb
    client.add_breadcrumb(Breadcrumb(
        message="User started checkout",
        category="checkout",
        data={"cart_items": 5}
    ))

    # Set additional context
    client.set_context("order", {
        "total": 99.99,
        "currency": "USD"
    })

    return process_checkout()

License

MIT

Release files for error-explorer-flask 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for error-explorer-flask 1.2.0
File Size Uploaded
error_explorer_flask-1.2.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for error-explorer-flask 1.2.0
File Interpreter ABI Platform
error_explorer_flask-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / error_explorer_flask-1.2.0.tar.gz

Download URL error_explorer_flask-1.2.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6c3feb0bb01e2bf0f72af1ab62e8c74f603ef2e1729e8edf8f496d5655179605
BLAKE2b-256 checksum
How to use checksums
5a77844a2dc11979411b9346c87cbac2b9fedf3adec4fc867177f5ccd665dfa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / error_explorer_flask-1.2.0-py3-none-any.whl

Download URL error_explorer_flask-1.2.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92320268045988af6fcc8717440fa6d648b38b8e72701f8e941a8587a26ad622
BLAKE2b-256 checksum
How to use checksums
e2d28d95f4ac2454d6ed5561515e5f546ebfdecbb28c33a12cf55cf2e7a50977
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page