Skip to main content

A reusable Django app that captures exceptions with request context and stores them in the database, similar to a lightweight Sentry

Project description

Django Stacktrace

Install from PyPI:

pip install django-stacktrace

A reusable Django app that captures exceptions with request context and stores them in the database, similar to a lightweight Sentry. It is best suited for early-stage apps that do not yet need to invest in a full error tracking tool; for production-grade monitoring, Sentry is recommended.

Quick start

  1. Add the app:
    • django_stacktrace to INSTALLED_APPS
  2. Add middleware (signal fallback is disabled automatically when middleware is enabled):
    • django_stacktrace.middleware.StacktraceMiddleware in MIDDLEWARE
  3. Apply migrations:
    • python manage.py migrate
  4. Trigger a crash and inspect Crash events in the Django admin.

Manual capture

You can capture exceptions directly without middleware:

from django_stacktrace.event_store import store_crash_event

try:
    1 / 0
except Exception as exc:
    store_crash_event(exc=exc)

Settings

All settings live under a single STACKTRACE dictionary. Each key is optional.

STACKTRACE = {
    "ENABLED": True,
    "SAMPLE_RATE": 1.0,
    "RATE_LIMIT": 0,
    "CAPTURE_HEADERS": True,
    "CAPTURE_BODY": False,
    "MAX_PAYLOAD_BYTES": 64 * 1024,
    "REDACT_FIELDS": ["password", "token"],
    "REDACT_HEADERS": ["authorization", "cookie"],
    "USER_FIELD": "username",
}

Available keys:

  • ENABLED (default True)
  • SAMPLE_RATE (default 1.0, 0-1 sampling probability)
  • RATE_LIMIT (default 0, per-minute cap; 0 disables)
  • CAPTURE_HEADERS (default True)
  • CAPTURE_BODY (default False)
  • MAX_PAYLOAD_BYTES (default 65536)
  • REDACT_FIELDS (request keys to mask)
  • REDACT_HEADERS (header keys to mask)
  • USER_FIELD (user attribute for display name)

Settings reference

ENABLED

  • Type: bool
  • Purpose: Enable or disable crash capturing entirely.
  • Example: "ENABLED": False

SAMPLE_RATE

  • Type: float between 0.0 and 1.0
  • Purpose: Probabilistic sampling for high-volume apps.
  • Example: "SAMPLE_RATE": 0.1

RATE_LIMIT

  • Type: int
  • Purpose: Per-minute cap; 0 disables rate limiting.
  • Example: "RATE_LIMIT": 120

CAPTURE_HEADERS

  • Type: bool
  • Purpose: Include request headers in the captured event.
  • Example: "CAPTURE_HEADERS": True

CAPTURE_BODY

  • Type: bool
  • Purpose: Include request body in the captured event.
  • Example: "CAPTURE_BODY": False

MAX_PAYLOAD_BYTES

  • Type: int
  • Purpose: Max bytes kept from request body.
  • Example: "MAX_PAYLOAD_BYTES": 65536

REDACT_FIELDS

  • Type: list[str] or set[str]
  • Purpose: Request data keys to mask before storage.
  • Example: "REDACT_FIELDS": ["password", "token"]

REDACT_HEADERS

  • Type: list[str] or set[str]
  • Purpose: Header keys to mask before storage.
  • Example: "REDACT_HEADERS": ["authorization", "cookie"]

USER_FIELD

  • Type: str
  • Purpose: User attribute used for display name in the event.
  • Example: "USER_FIELD": "username"

Data model

Events are stored in django_stacktrace.CrashEvent with indexed fields like level, logger, error type, request path, user identifier, and traceback hash, plus a JSON payload for full context.

Backlog

  • Async storage path (Celery/queue support)
  • Logging integration for logging exceptions
  • Rate-limit options (per-user/IP limits, key prefix)
  • Body size controls (per-content-type limits, truncation)
  • Filtering hooks (ignore exceptions or URLs)
  • Admin UI improvements (grouping, search, trends)
  • Export and retention tools (cleanup, CSV export)

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

django_stacktrace-0.2.2.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

django_stacktrace-0.2.2-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file django_stacktrace-0.2.2.tar.gz.

File metadata

  • Download URL: django_stacktrace-0.2.2.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_stacktrace-0.2.2.tar.gz
Algorithm Hash digest
SHA256 686f5e54d1e3fb886482249a7f20a0e0d0f7d2d0dbb26be045ca2d674cfe9701
MD5 202c789dd8cb490e4e27a7717cd2621f
BLAKE2b-256 f5bff68ec7d3cace37d02b889973b81dedb85e5709d35af8d051d4edb2a9e3c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_stacktrace-0.2.2.tar.gz:

Publisher: release.yml on marselbeqiri/django-stacktrace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_stacktrace-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_stacktrace-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 df4f69c673dbf456a0e6b3261c2f65ac9b8b04c590645d72f45dcf6524e776b4
MD5 0c8ba768661dde55448db10f0d67505d
BLAKE2b-256 e50de947a3dd58858a784fa39fd64a92c851c543238027ecd9982e7442203b56

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_stacktrace-0.2.2-py3-none-any.whl:

Publisher: release.yml on marselbeqiri/django-stacktrace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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