Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.225s · 70.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.9s · import 0.214s · 71MB
70MB installed
● package 70MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RequestIdMiddleware
✓ from django_datadog_logger.middleware.request_id import RequestIdMiddleware
ErrorLoggingMiddleware
✓ from django_datadog_logger.middleware.error_log import ErrorLoggingMiddleware
RequestLoggingMiddleware
✓ from django_datadog_logger.middleware.request_log import RequestLoggingMiddleware
DatadogJSONFormatter
✓ from django_datadog_logger.formatters.datadog import DatadogJSONFormatter
This quickstart configures `django-datadog-logger` by adding its middleware components to your Django project's `settings.py` to capture request IDs, errors, and access logs. It then sets up a `LOGGING` dictionary to use the `DatadogJSONFormatter` for structured, JSON-formatted output, directing logs to both console and a file for consumption by the Datadog Agent. Remember to set the `LOG_DIR` environment variable or adjust the filename for log storage.
import os
# settings.py
MIDDLEWARE = [
'django_datadog_logger.middleware.request_id.RequestIdMiddleware',
# ... other middlewares ...
'django_datadog_logger.middleware.error_log.ErrorLoggingMiddleware',
'django_datadog_logger.middleware.request_log.RequestLoggingMiddleware',
]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'datadog_json': {
'()': 'django_datadog_logger.formatters.datadog.DatadogJSONFormatter',
'format': '%(levelname)s %(asctime)s %(name)s %(message)s',
},
},
'handlers': {
'datadog_file': {
'class': 'logging.FileHandler',
'filename': os.path.join(os.environ.get('LOG_DIR', './'), 'datadog.log'),
'formatter': 'datadog_json',
'level': 'INFO',
},
'console': {
'class': 'logging.StreamHandler',
'formatter': 'datadog_json',
'level': 'DEBUG',
}
},
'loggers': {
'': {
'handlers': ['console', 'datadog_file'],
'level': 'INFO',
'propagate': True
},
'django': {
'handlers': ['console', 'datadog_file'],
'level': 'INFO',
'propagate': False,
}
}
}
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'django_datadog_logger.middleware.request_id'
The `django-datadog-logger` package is either not installed in your environment or the import path specified in your `settings.py` is incorrect.
fixRun `pip install django-datadog-logger` to install the package, and double-check the middleware paths in your `settings.py` against the official documentation.
Logs in Datadog appear as plain text, or specific log attributes (like `request_id`, `status_code`) are not being parsed correctly into structured fields.
Your Django `LOGGING` configuration is not using `DatadogJSONFormatter`, or your Datadog Agent is not configured to process JSON-formatted logs from the specified log file/stream.
fixEnsure the formatter for your Datadog-bound handlers is set to `'()': 'django_datadog_logger.formatters.datadog.DatadogJSONFormatter'`. If using file-based logging, verify your Datadog Agent's `conf.yaml` includes `source: python` and that `log_processing_rules` are correctly configured for JSON.
Asynchronous views or ASGI applications are not producing logs with request context (e.g., missing `request_id`) or are encountering unexpected errors related to logging middleware.
You are likely running in an ASGI environment with an older version of `django-datadog-logger` that lacks native async middleware support. Prior to `v0.9.0`, middleware might not correctly interact with async request/response cycles.
fixUpgrade to `django-datadog-logger==0.9.0` or a newer version. This version adds `async_capable = True` and `__acall__` implementations to the middleware classes to properly handle ASGI requests.
Upgrade
Version history
0.9.0latest on PyPI · released Mar 18, 2026
Audit
Dependencies
DjangorequiredCore framework dependency; officially supports Django 4.2, 5.2, 6.0.
ddtraceoptionalRecommended for full APM integration and automatic trace/span ID injection into logs.