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")

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.1.1.tar.gz (8.5 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.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: error_explorer_flask-1.1.1.tar.gz
  • Upload date:
  • Size: 8.5 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.1.1.tar.gz
Algorithm Hash digest
SHA256 f8abfebcb9e59f5e0ef9f072adc4e53523ad7932c9e8abdb529b9f89cae3755f
MD5 938ae356ef432fb95c5fafedfb912de8
BLAKE2b-256 eae58f7b77c038f214c0940339dcc3bfed8d94f203e681ef4d42565c3e151306

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_explorer_flask-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 684300eba56b8f9b0f8132a4967de97df954b129581737a6630e343d60c7d1dc
MD5 4e4759a3fb9041675a599f2f4ee1d762
BLAKE2b-256 f083df6d8420a85423c0e688e84360ab9d6ecbb6675a9b82dc7242a0d0322402

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