Skip to main content

Error Explorer SDK for Django - Automatic error tracking and monitoring

Project description

Error Explorer Django SDK

Automatic error tracking and monitoring for Django applications.

Installation

pip install error-explorer-django

Quick Start

1. Add to INSTALLED_APPS

# settings.py
INSTALLED_APPS = [
    ...
    'error_explorer_django',
]

2. Add Middleware

# settings.py
MIDDLEWARE = [
    'error_explorer_django.middleware.ErrorExplorerMiddleware',
    ...  # Should be early in the list to catch all errors
]

3. Configure

# settings.py
ERROR_EXPLORER = {
    'token': 'your_project_token',
    'environment': 'production',  # or 'staging', 'development'
    'release': '1.0.0',
}

That's it! Errors will be automatically captured and sent to Error Explorer.

Configuration Options

ERROR_EXPLORER = {
    # Required
    'token': 'your_project_token',

    # Optional - Environment & Release
    'environment': 'production',
    'release': '1.0.0',
    'project': 'my-django-app',

    # Optional - HMAC Authentication
    'endpoint': 'https://your-server.com/api/v1/webhook',
    'hmac_secret': 'your_hmac_secret',

    # Optional - Behavior
    'debug': False,                  # Enable debug mode
    'sample_rate': 1.0,             # 0.0 to 1.0 (100%)
    'max_breadcrumbs': 50,          # Max breadcrumbs to keep
    'attach_stacktrace': True,      # Include stack traces
    'send_default_pii': False,      # Include PII (email, etc.)

    # Optional - Capture Settings
    'capture_user': True,           # Capture authenticated user
    'capture_signals': True,        # Capture Django signals
    'capture_logging': True,        # Capture log messages
    'capture_404': False,           # Capture 404 errors
    'capture_403': False,           # Capture 403 errors
    'capture_cli': False,           # Capture in management commands

    # Optional - Data Scrubbing
    'scrub_fields': [
        'password',
        'secret',
        'token',
        'api_key',
        'credit_card',
    ],
}

Logging Integration

Capture log messages as breadcrumbs and errors:

# settings.py
LOGGING = {
    'version': 1,
    'handlers': {
        'error_explorer': {
            'class': 'error_explorer_django.logging.ErrorExplorerHandler',
            'level': 'WARNING',
        },
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console', 'error_explorer'],
            'level': 'INFO',
        },
        'myapp': {
            'handlers': ['console', 'error_explorer'],
            'level': 'DEBUG',
        },
    },
}

Event Filtering with before_send

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

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

    # Remove sensitive data
    if "extra" in event and "api_response" in event["extra"]:
        event["extra"]["api_response"] = "[REDACTED]"

    # Add custom data
    event["tags"] = event.get("tags", {})
    event["tags"]["deployment_id"] = os.environ.get("DEPLOYMENT_ID", "unknown")

    return event

ERROR_EXPLORER = {
    'token': 'your_project_token',
    'before_send': before_send,
}

Manual Usage

You can also use Error Explorer manually:

from error_explorer import ErrorExplorer, Breadcrumb, User

# Add custom breadcrumb
ErrorExplorer.add_breadcrumb(Breadcrumb(
    message="User clicked checkout",
    category="user.action",
    data={"cart_total": 99.99},
))

# Set user context (overrides auto-detected user)
ErrorExplorer.set_user(User(
    id="user_123",
    email="user@example.com",
    plan="pro",
))

# Set tags for filtering
ErrorExplorer.set_tags({
    "feature": "checkout",
    "ab_test": "new_flow",
})

# Capture exception manually
try:
    process_payment()
except PaymentError as e:
    ErrorExplorer.capture_exception(e)

# Capture message
ErrorExplorer.capture_message("Payment processed", level="info")

What's Captured Automatically

Request/Response

  • HTTP method, path, query string
  • Response status code
  • Safe headers (User-Agent, Referer, etc.)
  • Client IP address

User Context

  • User ID
  • Username
  • Full name
  • Email (if send_default_pii=True)

Django Signals

  • User login/logout
  • Failed login attempts
  • Database connections

Breadcrumbs

  • All incoming requests
  • All responses
  • Log messages (if logging handler is configured)
  • Auth events

Testing

Disable Error Explorer in tests:

# settings.py or conftest.py
ERROR_EXPLORER = {
    'token': 'test_token',
    'capture_signals': False,
    'capture_logging': False,
}

Or in pytest:

# conftest.py
@pytest.fixture(autouse=True)
def reset_error_explorer():
    from error_explorer import ErrorExplorer
    ErrorExplorer.reset()
    yield
    ErrorExplorer.reset()

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_django-1.2.0.tar.gz (14.2 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_django-1.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for error_explorer_django-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a49f1448aa6bf7dff8c0926f3f06a5c20cb946899bde6eadd9e7752f1e8b6199
MD5 06d3eb632015738ae8ec92518d32badc
BLAKE2b-256 d18a2867f25487fdda19c9e1c925790d5a2f134aeec3425c0cdc08167ee8bd84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_explorer_django-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d1b6790c7cc40ad09be1325ea7ee3422e2beefab12b89e10475eb2f3d97506e
MD5 67c1180502e75515bad0c111c88880d9
BLAKE2b-256 c2d2090d8aa821410d17d4a9557ec2c0515b5af13da136e95d851884b739a305

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