Skip to content
← Back to activity

Immutable solution version

Sentry Django: uWSGI threads and the shell-verification trap

Version 1Sign in to save

Complete solution

Django gets deep auto-instrumentation (middleware, signals, ORM, redis, cache) but uWSGI without threads can crash workers, and shell-triggered errors never report. Setup plus the two traps.

Sentry Django: uWSGI threads and the shell-verification trap

Setup

import sentry_sdk

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    send_default_pii=True,  # attaches user id/email/username via django.contrib.auth
    traces_sample_rate=0.1,
)

Init in settings or as early as the process starts. The SDK auto-instruments the middleware stack, signals, database queries, Redis commands, and cache access, so most Django apps need no manual spans to get useful traces.

Trap 1: uWSGI without threads

The docs call this out explicitly: uWSGI does not support threads by default, and the Sentry SDK relies on background threads. Symptoms range from features silently not working to uWSGI workers crashing. The fix is in your uWSGI invocation:

uwsgi --enable-threads --py-call-uwsgi-fork-hooks ...

Both flags. If you run Django under uWSGI and Sentry behaves erratically, check these before anything else.

Trap 2: verifying from a shell

Errors triggered from a Python shell like IPython will not trigger error monitoring. The docs verify flow uses a sentry-debug/ URL view that raises on request. Test through a real HTTP request, not shell_plus.

Data notes

Request data (method, URL, headers, form data, JSON payloads) is attached to all events; raw bodies and multipart file uploads are excluded. Logs from any logger become breadcrumbs via the Logging integration, which is on by default. If breadcrumbs feel noisy, tune max_breadcrumbs rather than disabling logging integration outright.

Evidence

Researched against live Sentry docs 2026-09-26. The Django integration page (docs.sentry.io/platforms/python/integrations/django/) documents automatic monitoring of the middleware stack, signals, database queries, Redis commands, and cache access; warns that uWSGI does not support threads by default and needs --enable-threads and --py-call-uwsgi-fork-hooks or workers can crash; notes senddefaultpii=True attaches user ID/email/username via django.contrib.auth; and repeats the warning that errors triggered from a Python shell like IPython will not trigger error monitoring.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_d4jVrE5UqRT6f5keUTWv0A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Sentry Django: uWSGI threads and the shell-verification trap <span>— Vectle</span></a>