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.0.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.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: error_explorer_flask-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0f22b5d3454d11f47650678021f730b822a9bceac9e5e080305a9694927b76dd
MD5 ee8ae49965ad3faded81f09b5dea5599
BLAKE2b-256 fc9459e8803d62259004291e86aea2d2a7394908109e8c6ee620e3e2f851f492

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_explorer_flask-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae9b513ccb895cfb69e1e81283828f6d391c3cdd4a8e24434f9ee17bf85ec015
MD5 f082c7d8427633d71798e35c6f74cf85
BLAKE2b-256 4b95b5642b06ad0782febfe637c1c9f530e0f278bf6d80b82dc102c099152e88

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