Package: django-error-reporting
Django Error ReportingGlobal error reporting framework for Django, Sentry, and DataDogRequirementsPython>= 3.6django>= 2.2.9sentrysdk>= 1.5.4ddtrace>=0.59.0django-datadog-logger>= 0.5.0InstallationInstalldjango-error-reporting:pip install django-error-reportingAdd it to yourINSTALLED_APPS:INSTALLED_APPS=(..."django_error_reporting.apps.DjangoErrorReportingConfig",...)Add this to yourMIDDLEWARE:MIDDLEWARE=(..."django_error_reporting.middleware.ErrorReportingMiddleware")For DataDog implementationsAdd this to yourINSTALLED_APPS:INSTALLED_APPS=(..."ddtrace.contrib.django",)Add this to yourMIDDLEWARE:MIDDLEWARE=(..."django_error_reporting.middleware.DataDogExceptionMiddleware",)Log IngestionIf you plan on implementing log ingestion, you'll also have to do the following:Add this to yourINSTALLED_APPS:INSTALLED_APPS=(..."django_datadog_logger")And this to yourMIDDLEWARE:MIDDLEWARE=(..."django_datadog_logger.middleware.error_log.ErrorLoggingMiddleware","django_datadog_logger.middleware.request_log.RequestLoggingMiddleware",)SettingsGeneralDER_ENABLED_INTEGRATIONSTuple of enabled integrations.Default:("datadog", "sentry")DER_INCLUDE_REQUEST_TAGSIndicates whether event tags related to the request should be added.These will include:http.headers.ip_address- remote IP address (seeDER_HEADERS_IP_ADDRESS)DER_HEADERS_IP_ADDRESSIfDER_INCLUDE_REQUEST_TAGSis enabled, this defines the IP address header. This needs to correspond to a HTTP header in the format accepted byrequest.META.Defaults toREMOTE_ADDR.DER_HEADER_TAGSA dictionary of headers to convert to event tags in the format of{<tag name>: <META name>}where<META name>is the key acccepted byrequest.META.In general, it would be preferable to set these tags via ddtrace'sDD_TRACE_HEADER_TAGSenvironment variable.Defaults toNone.SentryDER_SENTRY_DSNYour Sentry DSN.Default:NoneDER_SENTRY_INTEGRATIONSList of Sentry integrations.Default:[]DER_SENTRY_TRACES_SAMPLE_RATEFloat for sample rate.Default:0.0DER_SENTRY_ENVEnvironment name for Sentry.Default:localDER_SENTRY_REQUEST_BODIESRequest bodies setting.Default:alwaysDER_SENTRY_RELEASERelease.Default:"0".DER_SENTRY_DEBUGIndicates if Sentry should use debug mode.Defaults tosettings.DEBUG.General LoggingDER_LOGGING_LEVELMinimum logging level for logs output by DER.Defaults toERROR.DataDogDataDog LoggingDER_SETUP_DATADOG_LOGGINGIndicates whether to setup DataDog logging usingdjango-datadog-logger.DER_DATADOG_LOGGING_LEVELMinimum logging level for logs output for DataDog.Defaults toDER_LOGGING_LEVEL.DER_DATADOG_LOGGING_TO_CONSOLEIndicates whether to send all DataDog logs to console.Defaults toFalseDER_DATADOG_LOGGING_FILELog file for DataDog. This must correspond toDefaults toNonewhich disables file logging.Sentry LoggingDER_SENTRY_LOGGING_LEVELMinimum logging level for logs output for Sentry.Defaults toDER_LOGGING_LEVEL.On ReadyWhen the app is loaded (i.e.,ready()is called), it will do the following:Load default settings into the project settingsIf DataDog integration is enabled:Verify installed apps and middleware were added and throwNotImplementedErrorfor missing.If DataDog logging is enabled:Verify installed apps and middleware were added and throwNotImplementedErrorfor missing.SetLOGGINGwith formatters, handlers, and loggers.If Sentry integration is enabled:VerifyDER_SENTRY_DSNis set and throwNotImplementedErrorif missing.Initialize Sentry.MiddlewareErrorReportingMiddlewareThis middleware adds event tags (usingadd_event_tag) for each request.It also adds atrace_idto the session which is a unique identifier for a request. If using AWS load balancers, it will use the trace ID from it; otherwise,uuid.uuid4()is used.To add app-specific tags, you can set a callback withERROR_REPORTING_TAGGING_CALLBACKwhich should accept aRequestinstance and theadd_event_tagfunction as arguments.DataDogExceptionMiddlewareWhen an exception is captured, this middleware will set the appropriate span tags on the root span of the trace.This middleware should be added as late as possible.ContribFor each implementation, there is a module incontriband it must contain asetup()function which will be called duringready()to initialize and perform start-up tasks.Utilitiesadd_event_tag(name, value, dd_scope=None)Adds an event tag to the data sent to Sentry and/or DataDog.print_debug(msg)Ifsettings.DEBUGisTrue, printmsg.