0
0
Djangoframework~10 mins

Monitoring and error tracking in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Django logging module.

Django
import [1]
Drag options to blanks, or click blank then click option'
Asys
Bos
Clogging
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like os or sys instead of logging.
2fill in blank
medium

Complete the code to configure a logger named 'django' in Django settings.

Django
"""
LOGGING = {
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': '[1]',
        },
    },
}
"""
Drag options to blanks, or click blank then click option'
ADEBUG
BWARNING
CINFO
DERROR
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing ERROR or WARNING which show fewer details.
3fill in blank
hard

Fix the error in the code to send error logs to Sentry in Django.

Django
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn=[1],
    integrations=[DjangoIntegration()],
    traces_sample_rate=1.0,
    send_default_pii=True
)
Drag options to blanks, or click blank then click option'
A'your-dsn-url-here'
Byour-dsn-url-here
Cdsn='your-dsn-url-here'
Ddsn: 'your-dsn-url-here'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the DSN string.
4fill in blank
hard

Fill both blanks to create a custom logging filter that only allows ERROR level logs.

Django
class ErrorFilter(logging.Filter):
    def filter(self, record):
        return record.levelno [1] logging.ERROR

LOGGING = {
    'filters': {
        'error_only': {
            '()': ErrorFilter,
        },
    },
    'handlers': {
        'error_console': {
            'class': 'logging.StreamHandler',
            'filters': ['[2]'],
        },
    },
}
Drag options to blanks, or click blank then click option'
A==
B>=
Cerror_only
Derror_filter
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '==' to filter only ERROR level.
Mismatching filter names.
5fill in blank
hard

Fill both blanks to define a dictionary comprehension that maps each app name to its error count if count is greater than zero.

Django
error_counts = {app:count for app, count in app_errors.items() if count [1] 0}
filtered_errors = {k: v for k, v in error_counts.items() if v [2] 0}
Drag options to blanks, or click blank then click option'
A:
B>
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in dict comprehension.
Using '==' instead of '!=' in filtering.