Skip to main content

Error Explorer SDK for Flask

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

error_explorer_flask-1.2.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

error_explorer_flask-1.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file error_explorer_flask-1.2.0.tar.gz.

File metadata

  • Download URL: error_explorer_flask-1.2.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for error_explorer_flask-1.2.0.tar.gz
Algorithm Hash digest
SHA256 6c3feb0bb01e2bf0f72af1ab62e8c74f603ef2e1729e8edf8f496d5655179605
MD5 49cf481891d3d59ad391ddc191b85076
BLAKE2b-256 5a77844a2dc11979411b9346c87cbac2b9fedf3adec4fc867177f5ccd665dfa9

See more details on using hashes here.

File details

Details for the file error_explorer_flask-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for error_explorer_flask-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92320268045988af6fcc8717440fa6d648b38b8e72701f8e941a8587a26ad622
MD5 551b5fc8aadd65d6cb8f4114942d02ae
BLAKE2b-256 e2d28d95f4ac2454d6ed5561515e5f546ebfdecbb28c33a12cf55cf2e7a50977

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page