Package: django-query-tracer
A simplified version of django-devserver limited to SQL tracing and Ajax dump.Motivationsdjango-devserver is a very nice and usefull package, but the project isn’t very active,
and occasional problems related to new Django versions stay unfixed for long time even
when a solution is available as PR.Being mostly interested in tracing db queries, I finally decided to package a
stripped down version of the project.ScreenshotsQuickstartInstall django-query-tracer:pip install django-query-tracerAdd it to yourINSTALLED_APPS:INSTALLED_APPS=(...'query_tracer',...)Add django-query-tracer’s middleware:MIDDLEWARE_CLASSES=[...'query_tracer.middleware.QueryTracerMiddleware',...]SettingsQUERYTRACER_MODULESSelects active modules.Default: []Example:QUERYTRACER_MODULES = [
    'query_tracer.modules.sql.SQLRealTimeModule',
    'query_tracer.modules.sql.SQLSummaryModule',
    'query_tracer.modules.ajax.AjaxDumpModule',
    'query_tracer.modules.time.TimeModule',
]QUERYTRACER_FILTER_OUT_SQLA list of regex patterns to filter out SQL queries.Queries matching any of the given patterns will be excluded from log.Example:QUERYTRACER_FILTER_OUT_SQL [
    re.compile('djkombu_\w+'),  # Filter all queries related to Celery
]QUERYTRACER_FILTER_IN_SQLA list of regex patterns to filter in SQL queries.Only queries matching all patterns will be included in the log.Example:QUERYTRACER_FILTER_IN_SQL = [
    re.compile('sync_logs'),
    re.compile('date_created'),
]DEVSERVER_TRUNCATE_SQLDisable SQL query truncation (used in SQLRealTimeModule) setting this to FalseQUERYTRACER_AJAX_CONTENT_LENGTHAjax responses longer than this will not be logged.Default: 300QUERYTRACER_AJAX_PRETTY_PRINTIf set, try to format ajax requests and responses as intented JSONQUERYTRACER_SQL_MIN_DURATIONMinimum time a query must execute to be shown, value is in MSDefault: NoneSample local setup for development# Install query_tracerINSTALLED_APPS.append('query_tracer')MIDDLEWARE_CLASSES+=['query_tracer.middleware.QueryTracerMiddleware',]QUERYTRACER_MODULES=('query_tracer.modules.sql.SQLRealTimeModule','query_tracer.modules.sql.SQLSummaryModule','query_tracer.modules.ajax.AjaxDumpModule','query_tracer.modules.time.TimeModule',)#QUERYTRACER_AJAX_CONTENT_LENGTH = 10000QUERYTRACER_AJAX_PRETTY_PRINT=TrueQUERYTRACER_TRUNCATE_SQL=FalseQUERYTRACER_FILTER_IN_SQL=[re.compile('sync_logs'),re.compile('date_created'),]FeaturesSee file “query_tracer/settings.py” for available options, and refer todjango-devserver docfor usage/Time moduleA simpleTimeModulemodule has been added to display the time required to
process each Django view.Utility functionsquery_traces.utils.trace.tracePrints a text message or list, optionally prettifiedquery_traces.utils.trace.prettyprint_queryFormat and print a generic SQL queryquery_traces.utils.trace.prettyprint_querysetFormat and print a queryset’s queryquery_traces.utils.trace.trace_funcPrints function calls, showing actual parameters;
to be used as decoratorquery_traces.utils.time.ms_from_timedeltaReturns timedelta in millisecondsCreditsThis project is a stripped down version of:django-devserverTools used in rendering this package:Cookiecuttercookiecutter-djangopackage0.2.0fix for Python 3.x0.1.5Mimic SQLSummaryModule on completion of SQLRealTimeModule0.1.4TimeModule added0.1.3Prepare for Python3Enhanced sql summary logging0.1.2Default settings more suitable for production0.1.1Version comparison fix required after Django 1.10 to solve “maximum recursion depth exceeded on Django 1.10 #132” issue