Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 9 of 10 · Django Deployment & DevOps
Interview question

How do you handle Django logging and error tracking in production (Sentry, structured logging)? प्रोडक्शन में Django लॉगिंग और एरर ट्रैकिंग को कैसे हैंडल करें (Sentry, स्ट्रक्चर्ड लॉगिंग)?

Answer

With DEBUG=False in production, Django no longer shows detailed error pages to users, which is correct for security but means errors are invisible unless explicitly captured somewhere. Django's built-in LOGGING setting configures handlers and loggers to write structured log output (to console, file, or a log aggregation service) at appropriate levels — INFO for normal operation, WARNING for recoverable issues, ERROR for exceptions.

Sentry is the most widely used error-tracking integration: its Django SDK automatically captures unhandled exceptions with a full stack trace, the request that triggered them, and relevant context (user, environment, release version), grouping repeated occurrences of the same error and alerting the team, which is far more actionable than scanning raw log files after the fact.

import sentry_sdk
sentry_sdk.init(
    dsn=env('SENTRY_DSN'),
    traces_sample_rate=0.1,
    environment=env('ENVIRONMENT', default='production'),
)

DEBUG=False प्रोडक्शन में होने पर, Django अब यूज़र्स को विस्तृत एरर पेज नहीं दिखाता। Django की बिल्ट-इन LOGGING सेटिंग उचित स्तरों पर स्ट्रक्चर्ड लॉग आउटपुट लिखने के लिए हैंडलर्स और लॉगर्स कॉन्फिगर करती है।

Sentry सबसे व्यापक रूप से उपयोग की जाने वाली एरर-ट्रैकिंग इंटीग्रेशन है: इसका Django SDK स्वचालित रूप से पूर्ण स्टैक ट्रेस के साथ अनहैंडल्ड एक्सेप्शन को कैप्चर करता है।

import sentry_sdk
sentry_sdk.init(
    dsn=env('SENTRY_DSN'),
    traces_sample_rate=0.1,
)

Was this answer clear?