A simplified version of django-devserver limited to SQL tracing and Ajax dump.
Project description
A simplified version of django-devserver limited to SQL tracing and Ajax dump.
Motivations
django-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.
Screenshots
Quickstart
Install django-query-tracer:
pip install django-query-tracer
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'query_tracer',
...
)
Add django-query-tracer’s middleware:
MIDDLEWARE_CLASSES = [
...
'query_tracer.middleware.QueryTracerMiddleware',
...
]
Settings
QUERYTRACER_MODULES
Selects 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_SQL
A 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_SQL
A 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_SQL
Disable SQL query truncation (used in SQLRealTimeModule) setting this to False
QUERYTRACER_AJAX_CONTENT_LENGTH
Ajax responses longer than this will not be logged.
Default: 300
QUERYTRACER_AJAX_PRETTY_PRINT
If set, try to format ajax requests and responses as intented JSON
QUERYTRACER_SQL_MIN_DURATION
Minimum time a query must execute to be shown, value is in MS
Default: None
Sample local setup for development
# Install query_tracer
INSTALLED_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 = 10000
QUERYTRACER_AJAX_PRETTY_PRINT = True
QUERYTRACER_TRUNCATE_SQL = False
QUERYTRACER_FILTER_IN_SQL = [
re.compile('sync_logs'),
re.compile('date_created'),
]
Features
See file “query_tracer/settings.py” for available options, and refer to django-devserver doc for usage/
Time module
A simple TimeModule module has been added to display the time required to process each Django view.
Utility functions
- query_traces.utils.trace.trace
Prints a text message or list, optionally prettified
- query_traces.utils.trace.prettyprint_query
Format and print a generic SQL query
- query_traces.utils.trace.prettyprint_queryset
Format and print a queryset’s query
- query_traces.utils.trace.trace_func
Prints function calls, showing actual parameters; to be used as decorator
- query_traces.utils.time.ms_from_timedelta
Returns timedelta in milliseconds
Credits
This project is a stripped down version of:
Tools used in rendering this package:
0.2.0
fix for Python 3.x
0.1.5
Mimic SQLSummaryModule on completion of SQLRealTimeModule
0.1.4
TimeModule added
0.1.3
Prepare for Python3
Enhanced sql summary logging
0.1.2
Default settings more suitable for production
0.1.1
Version comparison fix required after Django 1.10 to solve “maximum recursion depth exceeded on Django 1.10 #132” issue
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file django_query_tracer-0.2.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_query_tracer-0.2.2-py2.py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/38.4.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 006f8df79110cc2934e66c3e39ad10d6fdff9b3328744a2713955a176635d06d |
|
MD5 | 3044326790c63f099a1e832c67eb8879 |
|
BLAKE2b-256 | eb84beeacd4f8d1cd2cca0969ecb6247cd5ff44f73f3047caad4f429b3018ad1 |