├── .gitattributes ├── .gitignore ├── AUTHORS.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── Procfile ├── README.rst ├── app.json ├── demo.py ├── docs ├── Makefile ├── _ext │ └── djangodocs.py ├── _static │ ├── github.png │ └── twitter.png ├── _templates │ └── layout.html ├── authors.rst ├── conf.py ├── history.rst ├── index.rst ├── make.bat ├── requirements.txt └── server-config.rst ├── request_id ├── __init__.py ├── apps.py ├── conf.py ├── defaults.py ├── local.py ├── logging.py ├── middleware.py ├── models.py ├── templatetags │ ├── __init__.py │ └── request_id.py └── wsgi.py ├── requirements.txt ├── runtime.txt ├── setup.cfg ├── setup.py └── tests └── templates └── base.html /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | __pycache__ 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | .idea 38 | 39 | # Complexity 40 | output/*.html 41 | output/*/index.html 42 | 43 | # Sphinx 44 | docs/_build 45 | 46 | *.sqlite 47 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Filip Wasilewski 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | .. :changelog: 2 | 3 | History 4 | ------- 5 | 6 | 1.0.0 (2016-10-23) 7 | ++++++++++++++++++ 8 | 9 | * Django 1.10 compatibility 10 | 11 | 12 | 0.1.0 (2014-01-30) 13 | ++++++++++++++++++ 14 | 15 | * First release 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Filip Wasilewski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | include requirements.txt 7 | recursive-include request_id *.html *.png *.gif *js *jpg *jpeg *svg *py -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: flake8 demo test coverage dist publish 2 | 3 | flake8: 4 | flake8 5 | 6 | demo: 7 | python demo.py 8 | 9 | run: 10 | waitress-serve --listen=127.0.0.1:8000 demo:application 11 | 12 | dist: 13 | python setup.py sdist bdist_wheel 14 | 15 | publish: 16 | python setup.py sdist bdist_wheel upload 17 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: waitress-serve --port=$PORT demo:application -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | django-request-id 3 | ================= 4 | 5 | 6 | .. image:: https://img.shields.io/pypi/l/dj-cmd.svg 7 | :target: https://raw.githubusercontent.com/nigma/django-request-id/master/LICENSE 8 | :alt: License 9 | 10 | .. image:: https://img.shields.io/pypi/v/django-request-id.svg 11 | :target: https://pypi.python.org/pypi/django-request-id/ 12 | :alt: Latest PyPI version 13 | 14 | .. image:: https://img.shields.io/pypi/wheel/django-request-id.svg 15 | :target: https://pypi.python.org/pypi/django-request-id/ 16 | :alt: Supports Wheel format 17 | 18 | Augments each request with unique ``request_id`` attribute and provides 19 | request id logging helpers. 20 | 21 | Developed and used at `en.ig.ma software shop `_. 22 | 23 | 24 | Quickstart 25 | ---------- 26 | 27 | 1. Include ``django-request-id`` in your ``requirements.txt`` file. 28 | 29 | 2. Add ``request_id`` to ``INSTALLED_APPS`` (necessary only if you are 30 | going to use the ``{% request_id %}`` template tag). 31 | 32 | 3. Add ``request_id.middleware.RequestIdMiddleware`` at the top of 33 | the ``MIDDLEWARE`` Django setting. 34 | 35 | 4. The app integrates with the standard Python/Django logging by defining 36 | a filter that puts a ``request_id`` variable in scope of every log message. 37 | 38 | First add a filter definition to the Django ``LOGGING`` settings: 39 | 40 | .. code-block:: python 41 | 42 | "filters": { 43 | "request_id": { 44 | "()": "request_id.logging.RequestIdFilter" 45 | } 46 | } 47 | 48 | Then enable the filter for related handlers: 49 | 50 | .. code-block:: python 51 | 52 | "handlers": { 53 | "console": { 54 | ... 55 | "filters": ["request_id"], 56 | } 57 | } 58 | 59 | And finally modify formatter output format to include the ``%(request_id)`` placeholder: 60 | 61 | .. code-block:: python 62 | 63 | "formatters": { 64 | "console": { 65 | "format": "%(asctime)s - %(levelname)-5s [%(name)s] request_id=%(request_id)s %(message)s" 66 | } 67 | } 68 | 69 | A full Django logging config example may look like this: 70 | 71 | .. code-block:: python 72 | 73 | 74 | LOGGING= { 75 | "version": 1, 76 | "disable_existing_loggers": False, 77 | "filters": { 78 | "request_id": { 79 | "()": "request_id.logging.RequestIdFilter" 80 | } 81 | }, 82 | "formatters": { 83 | "console": { 84 | "format": "%(asctime)s - %(levelname)-5s [%(name)s] request_id=%(request_id)s %(message)s", 85 | "datefmt": "%H:%M:%S" 86 | } 87 | }, 88 | "handlers": { 89 | "console": { 90 | "level": "DEBUG", 91 | "filters": ["request_id"], 92 | "class": "logging.StreamHandler", 93 | "formatter": "console" 94 | } 95 | }, 96 | "loggers": { 97 | "": { 98 | "level": "DEBUG", 99 | "handlers": ["console"] 100 | } 101 | } 102 | } 103 | 104 | 5. Make sure that your web server adds a ``X-Request-ID`` header to each request 105 | (and logs it in the server log for further matching of the server and app log entries). 106 | 107 | - Heroku handles this `automatically `_. 108 | - On Nginx you may require a separate module (see 109 | `nginx_requestid `_ or 110 | `nginx-x-rid-header `_). 111 | - On Apache you need to ``a2enmod`` the `unique_id `_ 112 | module and set ``REQUEST_ID_HEADER = "UNIQUE_ID"`` in the Django project 113 | settings. 114 | 115 | If you can't generate the `X-Request-Id` header at the web server level then 116 | simply set ``REQUEST_ID_HEADER = None`` in your project settings and the 117 | app will generate a unique id value automatically instead of retrieving 118 | it from the wsgi environment. 119 | 120 | For more info on server configs see 121 | `server-config `_. 122 | 123 | Dependencies 124 | ------------ 125 | 126 | None. 127 | 128 | Documentation and demo 129 | ---------------------- 130 | 131 | The full documentation is at http://django-request-id.rtfd.org. 132 | 133 | There's also an instant demo example that can be run from the cloned repository:: 134 | 135 | python demo.py 136 | 137 | See the integration in action on Heroku: 138 | 139 | .. image:: https://www.herokucdn.com/deploy/button.svg 140 | :alt: Deply 141 | :target: https://heroku.com/deploy?template=https://github.com/nigma/django-request-id 142 | 143 | License 144 | ------- 145 | 146 | ``django-request-id`` is released under the MIT license. 147 | 148 | Other Resources 149 | --------------- 150 | 151 | - GitHub repository - https://github.com/nigma/django-request-id 152 | - PyPi Package site - http://pypi.python.org/pypi/django-request-id 153 | 154 | 155 | Commercial Support 156 | ------------------ 157 | 158 | This app and many other help us build better software 159 | and focus on delivering quality projects faster. 160 | We would love to help you with your next project so get in touch 161 | by dropping an email at en@ig.ma. 162 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Django Request Id app demo", 3 | "description": "Demo integration of request-id header logging on Heroku", 4 | "keywords": [ 5 | "django", 6 | "request-id" 7 | ], 8 | "website": "https://github.com/nigma/django-request-id", 9 | "repository": "https://github.com/nigma/django-request-id", 10 | "success_url": "/", 11 | "formation": { 12 | "web": { 13 | "quantity": 1, 14 | "size": "Free" 15 | } 16 | }, 17 | "addons": [ 18 | "papertrail:choklad" 19 | ] 20 | } -------------------------------------------------------------------------------- /demo.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | Demo script. Run: 6 | 7 | python.exe demo.py 8 | """ 9 | 10 | from __future__ import absolute_import, division, print_function, unicode_literals 11 | 12 | import logging 13 | import os 14 | 15 | import django 16 | from django.conf import settings 17 | from django.conf.urls import url 18 | from django.core.wsgi import get_wsgi_application 19 | 20 | basename = os.path.splitext(os.path.basename(__file__))[0] 21 | 22 | middleware_settings_name = 'MIDDLEWARE' if django.VERSION[:2] >= (1, 10) else 'MIDDLEWARE_CLASSES' 23 | 24 | 25 | def rel(*path): 26 | return os.path.abspath( 27 | os.path.join(os.path.dirname(__file__), *path) 28 | ).replace('\\', '/') 29 | 30 | 31 | if not settings.configured: 32 | settings.configure( 33 | DEBUG=True, 34 | TIMEZONE='UTC', 35 | INSTALLED_APPS=['request_id'], 36 | ROOT_URLCONF=basename, 37 | WSGI_APPLICATION='{}.application'.format(basename), 38 | TEMPLATES=[ 39 | { 40 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 41 | 'DIRS': [rel('tests', 'templates')], 42 | 'OPTIONS': { 43 | 'context_processors': [ 44 | 'django.template.context_processors.request' 45 | ], 46 | }, 47 | }, 48 | ], 49 | LOGGING={ 50 | 'version': 1, 51 | 'disable_existing_loggers': False, 52 | 'filters': { 53 | 'request_id': { 54 | '()': 'request_id.logging.RequestIdFilter' 55 | } 56 | }, 57 | 'formatters': { 58 | 'console': { 59 | 'format': '%(asctime)s - %(levelname)-5s [%(name)s] request_id=%(request_id)s %(message)s', 60 | 'datefmt': '%H:%M:%S' 61 | } 62 | }, 63 | 'handlers': { 64 | 'console': { 65 | 'level': 'DEBUG', 66 | 'filters': ['request_id'], 67 | 'class': 'logging.StreamHandler', 68 | 'formatter': 'console' 69 | } 70 | }, 71 | 'loggers': { 72 | '': { 73 | 'level': 'DEBUG', 74 | 'handlers': ['console'] 75 | } 76 | } 77 | }, 78 | **{ 79 | middleware_settings_name: ['request_id.middleware.RequestIdMiddleware'] 80 | } 81 | ) 82 | 83 | # App 84 | 85 | from django.views.generic.base import TemplateView 86 | from request_id import get_current_request_id 87 | 88 | logger = logging.getLogger('view') 89 | 90 | 91 | class HelloView(TemplateView): 92 | template_name = 'base.html' 93 | 94 | def get(self, request, *args, **kwargs): 95 | logger.info('handling request') 96 | return super(HelloView, self).get(request, *args, **kwargs) 97 | 98 | def get_context_data(self, **kwargs): 99 | logger.info('preparing context data') 100 | return super(HelloView, self).get_context_data( 101 | current_request_val=get_current_request_id(), 102 | **kwargs 103 | ) 104 | 105 | def render_to_response(self, context, **response_kwargs): 106 | logger.info('rendering template') 107 | return super(HelloView, self).render_to_response(context, **response_kwargs) 108 | 109 | 110 | urlpatterns = [ 111 | url(r'^$', HelloView.as_view()) 112 | ] 113 | 114 | # WSGI 115 | 116 | from request_id.wsgi import AddRequestIdHeaderMiddleware 117 | 118 | application = AddRequestIdHeaderMiddleware(get_wsgi_application()) 119 | 120 | if __name__ == '__main__': 121 | from django.core.management import call_command 122 | 123 | call_command('runserver', '8000') 124 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-request-id.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-request-id.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/django-request-id" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-request-id" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." -------------------------------------------------------------------------------- /docs/_ext/djangodocs.py: -------------------------------------------------------------------------------- 1 | def setup(app): 2 | app.add_crossref_type( 3 | directivename = "setting", 4 | rolename = "setting", 5 | indextemplate = "pair: %s; setting", 6 | ) 7 | -------------------------------------------------------------------------------- /docs/_static/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nigma/django-request-id/0850e04e91b616b9aa8443959edf4a73a62289e4/docs/_static/github.png -------------------------------------------------------------------------------- /docs/_static/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nigma/django-request-id/0850e04e91b616b9aa8443959edf4a73a62289e4/docs/_static/twitter.png -------------------------------------------------------------------------------- /docs/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {# TEMPLATE VAR SETTINGS #} 2 | {%- set url_root = pathto('', 1) %} 3 | {%- if url_root == '#' %}{% set url_root = '' %}{% endif %} 4 | {%- if not embedded and docstitle %} 5 | {%- set titlesuffix = " — "|safe + docstitle|e %} 6 | {%- else %} 7 | {%- set titlesuffix = "" %} 8 | {%- endif %} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {% block htmltitle %} 17 | {{ title|striptags|e }}{{ titlesuffix }} 18 | {% endblock %} 19 | 20 | {# FAVICON #} 21 | {% if favicon %} 22 | 23 | {% endif %} 24 | 25 | {# CSS #} 26 | 27 | 28 | {# JS #} 29 | {% if not embedded %} 30 | 31 | 40 | {%- for scriptfile in script_files %} 41 | 42 | {%- endfor %} 43 | 44 | {% if use_opensearch %} 45 | 46 | {% endif %} 47 | 48 | {% endif %} 49 | 50 | {# RTD hosts these file themselves, so just load on non RTD builds #} 51 | {% if not READTHEDOCS %} 52 | 53 | 54 | {% endif %} 55 | 56 | {% for cssfile in css_files %} 57 | 58 | {% endfor %} 59 | 60 | {%- block linktags %} 61 | {%- if hasdoc('about') %} 62 | 64 | {%- endif %} 65 | {%- if hasdoc('genindex') %} 66 | 68 | {%- endif %} 69 | {%- if hasdoc('search') %} 70 | 71 | {%- endif %} 72 | {%- if hasdoc('copyright') %} 73 | 74 | {%- endif %} 75 | 76 | {%- if parents %} 77 | 78 | {%- endif %} 79 | {%- if next %} 80 | 81 | {%- endif %} 82 | {%- if prev %} 83 | 84 | {%- endif %} 85 | {%- endblock %} 86 | {%- block extrahead %} {% endblock %} 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
95 | 96 | {# SIDE NAV, TOGGLES ON MOBILE #} 97 | 122 | 123 |
124 | 125 | {# MOBILE NAV, TRIGGLES SIDE NAV ON TOGGLE #} 126 | 130 | 131 | 132 | {# PAGE CONTENT #} 133 |
134 |
135 | {% include "breadcrumbs.html" %} 136 | {% block body %}{% endblock %} 137 | {% include "footer.html" %} 138 |
139 |
140 | 141 |
142 | 143 |
144 | {% include "versions.html" %} 145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # django-request-id documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Jan 12 20:56:38 2014. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys 16 | import os 17 | import datetime 18 | import jinja2.filters 19 | 20 | # If extensions (or modules to document with autodoc) are in another directory, 21 | # add these directories to sys.path here. If the directory is relative to the 22 | # documentation root, use os.path.abspath to make it absolute, like shown here. 23 | #sys.path.insert(0, os.path.abspath('.')) 24 | 25 | cwd = os.path.abspath(os.path.dirname(__file__)) 26 | parent = os.path.dirname(cwd) 27 | ext = os.path.join(cwd, "_ext") 28 | sys.path.extend([parent, ext]) 29 | 30 | import django.conf 31 | django.conf.settings.configure() 32 | 33 | import request_id 34 | 35 | # -- General configuration ------------------------------------------------ 36 | 37 | # If your documentation needs a minimal Sphinx version, state it here. 38 | #needs_sphinx = '1.0' 39 | 40 | # Add any Sphinx extension module names here, as strings. They can be 41 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 42 | # ones. 43 | extensions = ['djangodocs', 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx'] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix of source filenames. 49 | source_suffix = '.rst' 50 | 51 | # The encoding of source files. 52 | #source_encoding = 'utf-8-sig' 53 | 54 | # The master toctree document. 55 | master_doc = 'index' 56 | 57 | # General information about the project. 58 | project = 'django-request-id' 59 | copyright = jinja2.filters.do_mark_safe('%s, Filip Wasilewski' % datetime.date.today().year) 60 | 61 | # The version info for the project you're documenting, acts as replacement for 62 | # |version| and |release|, also used in various other places throughout the 63 | # built documents. 64 | # 65 | # The short X.Y version. 66 | version = request_id.__version__ 67 | # The full version, including alpha/beta/rc tags. 68 | release = request_id.__version__ 69 | 70 | # The language for content autogenerated by Sphinx. Refer to documentation 71 | # for a list of supported languages. 72 | #language = None 73 | 74 | # There are two options for replacing |today|: either, you set today to some 75 | # non-false value, then it is used: 76 | #today = '' 77 | # Else, today_fmt is used as the format for a strftime call. 78 | #today_fmt = '%B %d, %Y' 79 | 80 | # List of patterns, relative to source directory, that match files and 81 | # directories to ignore when looking for source files. 82 | exclude_patterns = ['_build'] 83 | 84 | # The reST default role (used for this markup: `text`) to use for all 85 | # documents. 86 | #default_role = None 87 | 88 | # If true, '()' will be appended to :func: etc. cross-reference text. 89 | #add_function_parentheses = True 90 | 91 | # If true, the current module name will be prepended to all description 92 | # unit titles (such as .. function::). 93 | #add_module_names = True 94 | 95 | # If true, sectionauthor and moduleauthor directives will be shown in the 96 | # output. They are ignored by default. 97 | #show_authors = False 98 | 99 | # The name of the Pygments (syntax highlighting) style to use. 100 | pygments_style = 'sphinx' 101 | 102 | # A list of ignored prefixes for module index sorting. 103 | modindex_common_prefix = [ 104 | "request_id." 105 | ] 106 | 107 | # If true, keep warnings as "system message" paragraphs in the built documents. 108 | #keep_warnings = False 109 | 110 | 111 | # -- Options for HTML output ---------------------------------------------- 112 | 113 | # The theme to use for HTML and HTML Help pages. See the documentation for 114 | # a list of builtin themes. 115 | 116 | try: 117 | import sphinx_rtd_theme 118 | html_theme = 'sphinx_rtd_theme' 119 | html_theme_path = [ 120 | os.path.abspath(os.path.join(os.path.dirname(__file__), "_templates")), 121 | sphinx_rtd_theme.get_html_theme_path() 122 | ] 123 | except ImportError: 124 | html_theme = 'default' 125 | 126 | # Theme options are theme-specific and customize the look and feel of a theme 127 | # further. For a list of options available for each theme, see the 128 | # documentation. 129 | #html_theme_options = {} 130 | 131 | # Add any paths that contain custom themes here, relative to this directory. 132 | #html_theme_path = [] 133 | 134 | # The name for this set of Sphinx documents. If None, it defaults to 135 | # " v documentation". 136 | #html_title = None 137 | 138 | # A shorter title for the navigation bar. Default is the same as html_title. 139 | #html_short_title = None 140 | 141 | # The name of an image file (relative to this directory) to place at the top 142 | # of the sidebar. 143 | #html_logo = None 144 | 145 | # The name of an image file (within the static path) to use as favicon of the 146 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 147 | # pixels large. 148 | #html_favicon = None 149 | 150 | # Add any paths that contain custom static files (such as style sheets) here, 151 | # relative to this directory. They are copied after the builtin static files, 152 | # so a file named "default.css" will overwrite the builtin "default.css". 153 | html_static_path = ['_static'] 154 | 155 | # Add any extra paths that contain custom files (such as robots.txt or 156 | # .htaccess) here, relative to this directory. These files are copied 157 | # directly to the root of the documentation. 158 | #html_extra_path = [] 159 | 160 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 161 | # using the given strftime format. 162 | #html_last_updated_fmt = '%b %d, %Y' 163 | 164 | # If true, SmartyPants will be used to convert quotes and dashes to 165 | # typographically correct entities. 166 | #html_use_smartypants = True 167 | 168 | # Custom sidebar templates, maps document names to template names. 169 | #html_sidebars = {} 170 | 171 | # Additional templates that should be rendered to pages, maps page names to 172 | # template names. 173 | #html_additional_pages = {} 174 | 175 | # If false, no module index is generated. 176 | #html_domain_indices = True 177 | 178 | # If false, no index is generated. 179 | #html_use_index = True 180 | 181 | # If true, the index is split into individual pages for each letter. 182 | #html_split_index = False 183 | 184 | # If true, links to the reST sources are added to the pages. 185 | #html_show_sourcelink = True 186 | 187 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 188 | #html_show_sphinx = True 189 | 190 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 191 | #html_show_copyright = True 192 | 193 | # If true, an OpenSearch description file will be output, and all pages will 194 | # contain a tag referring to it. The value of this option must be the 195 | # base URL from which the finished HTML is served. 196 | #html_use_opensearch = '' 197 | 198 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 199 | #html_file_suffix = None 200 | 201 | # Output file base name for HTML help builder. 202 | htmlhelp_basename = 'django-request-iddoc' 203 | 204 | 205 | # -- Options for LaTeX output --------------------------------------------- 206 | 207 | latex_elements = { 208 | # The paper size ('letterpaper' or 'a4paper'). 209 | #'papersize': 'letterpaper', 210 | 211 | # The font size ('10pt', '11pt' or '12pt'). 212 | #'pointsize': '10pt', 213 | 214 | # Additional stuff for the LaTeX preamble. 215 | #'preamble': '', 216 | } 217 | 218 | # Grouping the document tree into LaTeX files. List of tuples 219 | # (source start file, target name, title, 220 | # author, documentclass [howto, manual, or own class]). 221 | latex_documents = [ 222 | ('index', 'django-request-id.tex', u'django-request-id Documentation', 223 | u'Filip Wasilewski', 'manual'), 224 | ] 225 | 226 | # The name of an image file (relative to this directory) to place at the top of 227 | # the title page. 228 | #latex_logo = None 229 | 230 | # For "manual" documents, if this is true, then toplevel headings are parts, 231 | # not chapters. 232 | #latex_use_parts = False 233 | 234 | # If true, show page references after internal links. 235 | #latex_show_pagerefs = False 236 | 237 | # If true, show URL addresses after external links. 238 | #latex_show_urls = False 239 | 240 | # Documents to append as an appendix to all manuals. 241 | #latex_appendices = [] 242 | 243 | # If false, no module index is generated. 244 | #latex_domain_indices = True 245 | 246 | 247 | # -- Options for manual page output --------------------------------------- 248 | 249 | # One entry per manual page. List of tuples 250 | # (source start file, name, description, authors, manual section). 251 | man_pages = [ 252 | ('index', 'django-request-id', u'django-request-id Documentation', 253 | [u'Filip Wasilewski'], 1) 254 | ] 255 | 256 | # If true, show URL addresses after external links. 257 | #man_show_urls = False 258 | 259 | 260 | # -- Options for Texinfo output ------------------------------------------- 261 | 262 | # Grouping the document tree into Texinfo files. List of tuples 263 | # (source start file, target name, title, author, 264 | # dir menu entry, description, category) 265 | texinfo_documents = [ 266 | ('index', 'django-request-id', u'django-request-id Documentation', 267 | u'Filip Wasilewski', 'django-request-id', 'One line description of project.', 268 | 'Miscellaneous'), 269 | ] 270 | 271 | # Documents to append as an appendix to all manuals. 272 | #texinfo_appendices = [] 273 | 274 | # If false, no module index is generated. 275 | #texinfo_domain_indices = True 276 | 277 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 278 | #texinfo_show_urls = 'footnote' 279 | 280 | # If true, do not generate a @detailmenu in the "Top" node's menu. 281 | #texinfo_no_detailmenu = False 282 | 283 | # Links to Python's docs should reference the most recent version of the 2.x 284 | # branch, which is located at this URL. 285 | intersphinx_mapping = { 286 | 'python': ('http://docs.python.org/', None), 287 | 'sphinx': ('http://sphinx-doc.org/', None), 288 | 'django': ('http://docs.djangoproject.com/en/1.6/', 'http://docs.djangoproject.com/en/1.6/_objects/'), 289 | } 290 | 291 | # Python's docs don't change every week. 292 | intersphinx_cache_limit = 2 # days 293 | 294 | autodoc_member_order = 'bysource' 295 | autodoc_default_flags = ['undoc-members'] 296 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. django-request-id documentation master file, created by 2 | sphinx-quickstart on Sun Jan 12 20:56:38 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to django-request-id's documentation! 7 | ============================================= 8 | 9 | .. include:: ../README.rst 10 | 11 | Content 12 | ------- 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | 17 | server-config 18 | authors 19 | history 20 | 21 | 22 | Indices and tables 23 | ================== 24 | 25 | * :ref:`genindex` 26 | * :ref:`modindex` 27 | * :ref:`search` 28 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\django-request-id.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\django-request-id.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx_rtd_theme>=0.1.5 2 | Django>=1.6 3 | -------------------------------------------------------------------------------- /docs/server-config.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | Web server configs 3 | ================== 4 | 5 | Heroku 6 | ------ 7 | 8 | If the `X-Request-ID` header is not passed automatically you may need to 9 | enable it using the labs command: 10 | 11 | .. code-block:: bash 12 | 13 | heroku labs:enable http-request-id 14 | 15 | See `http-request-id `_ for more info. 16 | 17 | The ``request_id`` will also appear in the Heroku Dyno logs so it is easy to match 18 | application logs with Heroku request logs. 19 | 20 | Nginx 21 | ----- 22 | 23 | There's no built-in option in Nginx to generate a unique request id, but there 24 | are several modules that provide this functionality: 25 | 26 | - `nginx_requestid `_ 27 | - `nginx-x-rid-header `_ 28 | 29 | Unfortunately this require Nginx binary recompilation. 30 | 31 | Alternatively, if your Nginx has Lua scripting enabled, you can generate a random id 32 | and add it to server logs using the following snippets: 33 | 34 | .. code-block:: nginx 35 | 36 | http { 37 | ... 38 | 39 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 40 | '$status $body_bytes_sent "$http_referer" ' 41 | '"$http_user_agent" "$http_x_forwarded_for" ' 42 | 'request_id=$request_id'; 43 | ... 44 | } 45 | 46 | .. code-block:: lua 47 | 48 | server { 49 | listen 80; 50 | server_name localhost; 51 | 52 | access_log logs/host.access.log main; 53 | 54 | location / { 55 | set_by_lua $request_id ' 56 | local function random_id() 57 | local charset = "0123456789abcdefghijklmnopqrstuvwxyz" 58 | local template = "xxxx-xxxxxxxx-xxxxxxxx" 59 | local range = charset:len() 60 | return string.gsub(template, "x", function (c) 61 | return string.char(charset:byte(math.random(1, range))) 62 | end) 63 | end 64 | local request_id = random_id() 65 | ngx.req.set_header("X-Request-Id", request_id) 66 | return request_id 67 | '; 68 | 69 | ... 70 | } 71 | 72 | Apache 73 | ------ 74 | 75 | On Apache you need to ``a2enmod`` the `unique_id `_ 76 | module and set ``REQUEST_ID_HEADER = "UNIQUE_ID"`` in the Django project 77 | settings. 78 | 79 | Standalone 80 | ---------- 81 | 82 | If you can't generate the `X-Request-Id` header at the web server level then 83 | simply set ``REQUEST_ID_HEADER = None`` in your project settings and the 84 | app will generate a unique id value automatically instead of retrieving 85 | it from the wsgi environment. 86 | 87 | You can also use the :class:`request_id.wsgi.AddRequestIdHeaderMiddleware` WSGI 88 | middleware for that purpose. 89 | -------------------------------------------------------------------------------- /request_id/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | from uuid import uuid4 6 | 7 | from .local import Local, release_local # NOQA 8 | 9 | __version__ = '1.0.0' 10 | 11 | default_app_config = 'request_id.apps.RequestIdConfig' 12 | 13 | local = Local() 14 | 15 | 16 | def generate_request_id(): 17 | return str(uuid4()) 18 | 19 | 20 | def get_current_request_id(): 21 | try: 22 | return local.request_id 23 | except AttributeError: 24 | return '' 25 | 26 | 27 | __all__ = ['get_current_request_id'] 28 | -------------------------------------------------------------------------------- /request_id/apps.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | from django.apps import AppConfig 6 | 7 | 8 | class RequestIdConfig(AppConfig): 9 | name = 'request_id' 10 | -------------------------------------------------------------------------------- /request_id/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | from django.conf import settings 6 | 7 | from .defaults import DEFAULT_REQUEST_ID_HEADER_NAME 8 | 9 | REQUEST_ID_HEADER = getattr(settings, 'REQUEST_ID_HEADER', DEFAULT_REQUEST_ID_HEADER_NAME) 10 | """ 11 | Default header name as defined in 12 | `heroku request-id `_ 13 | """ 14 | -------------------------------------------------------------------------------- /request_id/defaults.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | DEFAULT_REQUEST_ID_HEADER_NAME = 'HTTP_X_REQUEST_ID' 6 | -------------------------------------------------------------------------------- /request_id/local.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Based on https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/local.py 5 | 6 | Copyright (c) 2013 by the Werkzeug Team, see 7 | https://github.com/mitsuhiko/werkzeug/blob/master/AUTHORS for more details. 8 | """ 9 | 10 | from __future__ import absolute_import, division, print_function, unicode_literals 11 | 12 | __all__ = ['Local', 'release_local'] 13 | 14 | try: 15 | from greenlet import getcurrent as get_ident 16 | except ImportError: 17 | try: 18 | # noinspection PyCompatibility 19 | from thread import get_ident 20 | except ImportError: 21 | # noinspection PyCompatibility 22 | from _thread import get_ident 23 | 24 | 25 | class Local(object): 26 | __slots__ = ('__storage__', '__ident_func__') 27 | 28 | def __init__(self): 29 | object.__setattr__(self, '__storage__', {}) 30 | object.__setattr__(self, '__ident_func__', get_ident) 31 | 32 | def __iter__(self): 33 | return iter(self.__storage__.items()) 34 | 35 | def __release_local__(self): 36 | self.__storage__.pop(self.__ident_func__(), None) 37 | 38 | def __getattr__(self, name): 39 | try: 40 | return self.__storage__[self.__ident_func__()][name] 41 | except KeyError: 42 | raise AttributeError(name) 43 | 44 | def __setattr__(self, name, value): 45 | ident = self.__ident_func__() 46 | storage = self.__storage__ 47 | try: 48 | storage[ident][name] = value 49 | except KeyError: 50 | storage[ident] = {name: value} 51 | 52 | def __delattr__(self, name): 53 | try: 54 | del self.__storage__[self.__ident_func__()][name] 55 | except KeyError: 56 | raise AttributeError(name) 57 | 58 | 59 | def release_local(local): 60 | local.__release_local__() 61 | -------------------------------------------------------------------------------- /request_id/logging.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | import logging 6 | 7 | from . import get_current_request_id 8 | 9 | 10 | class RequestIdFilter(logging.Filter): 11 | def filter(self, record): 12 | record.request_id = get_current_request_id() 13 | return True 14 | -------------------------------------------------------------------------------- /request_id/middleware.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | from . import generate_request_id, local, release_local 6 | from .conf import REQUEST_ID_HEADER 7 | 8 | 9 | def get_request_id(request): 10 | if hasattr(request, 'request_id'): 11 | return request.request_id 12 | elif REQUEST_ID_HEADER: 13 | return request.META.get(REQUEST_ID_HEADER, '') 14 | else: 15 | return generate_request_id() 16 | 17 | 18 | class RequestIdMiddleware(object): 19 | def __init__(self, get_response=None): 20 | self.get_response = get_response 21 | 22 | def __call__(self, request): 23 | request_id = get_request_id(request) 24 | request.request_id = request_id 25 | local.request_id = request_id 26 | 27 | response = self.get_response(request) 28 | 29 | release_local(local) 30 | 31 | return response 32 | 33 | # Compatibility methods for Django <1.10 34 | def process_request(self, request): 35 | request_id = get_request_id(request) 36 | request.request_id = request_id 37 | local.request_id = request_id 38 | 39 | def process_response(self, request, response): 40 | release_local(local) 41 | return response 42 | -------------------------------------------------------------------------------- /request_id/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | -------------------------------------------------------------------------------- /request_id/templatetags/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | -------------------------------------------------------------------------------- /request_id/templatetags/request_id.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | from django.template import Library 6 | 7 | from .. import get_current_request_id 8 | 9 | register = Library() 10 | 11 | 12 | @register.simple_tag(takes_context=True, name='request_id') 13 | def get_request_id(context): 14 | if 'request' in context: 15 | request = context['request'] 16 | if hasattr(request, 'request_id'): 17 | return request.request_id 18 | return get_current_request_id() 19 | -------------------------------------------------------------------------------- /request_id/wsgi.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import, division, print_function, unicode_literals 4 | 5 | from . import generate_request_id 6 | from .defaults import DEFAULT_REQUEST_ID_HEADER_NAME 7 | 8 | 9 | class AddRequestIdHeaderMiddleware(object): 10 | """ 11 | X-Request-ID header is usually added by the web server. We will emulate 12 | this behaviour here. 13 | """ 14 | 15 | HEADER_NAME = DEFAULT_REQUEST_ID_HEADER_NAME 16 | 17 | def __init__(self, app): 18 | self.app = app 19 | 20 | def __call__(self, environ, start_response): 21 | environ.setdefault(self.HEADER_NAME, generate_request_id()) 22 | return self.app(environ, start_response) 23 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | django 2 | 3 | # Only for Heroku demo 4 | waitress 5 | -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.5.2 -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max_line_length = 119 3 | exclude = docs/* 4 | ignore = E402 5 | statistics = True 6 | 7 | [metadata] 8 | license-file = LICENSE 9 | 10 | [wheel] 11 | universal = 1 12 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import sys 6 | 7 | try: 8 | from setuptools import setup 9 | except ImportError: 10 | from distutils.core import setup 11 | 12 | version = "1.0.0" 13 | 14 | if sys.argv[-1] == "publish": 15 | os.system("python setup.py sdist bdist_wheel upload") 16 | print("You probably want to also tag the version now:") 17 | print(" git tag -a %s -m 'version %s'" % (version, version)) 18 | print(" git push --tags") 19 | sys.exit() 20 | 21 | readme = open("README.rst").read() 22 | history = open("HISTORY.rst").read().replace(".. :changelog:", "") 23 | 24 | setup( 25 | name="django-request-id", 26 | version=version, 27 | description="""Augment each request with unique id for logging purposes""", 28 | license="MIT", 29 | author="Filip Wasilewski", 30 | author_email="en@ig.ma", 31 | url="https://github.com/nigma/django-request-id", 32 | long_description=readme + "\n\n" + history, 33 | packages=[ 34 | "request_id", 35 | ], 36 | include_package_data=True, 37 | install_requires=[ 38 | "django", 39 | ], 40 | zip_safe=True, 41 | keywords="django request-id", 42 | classifiers=[ 43 | "Development Status :: 5 - Production/Stable", 44 | "Environment :: Web Environment", 45 | "Framework :: Django", 46 | "Framework :: Django :: 1.8", 47 | "Framework :: Django :: 1.9", 48 | "Framework :: Django :: 1.10", 49 | "Intended Audience :: Developers", 50 | "License :: OSI Approved :: MIT License", 51 | "Operating System :: OS Independent", 52 | "Programming Language :: Python :: 2", 53 | "Programming Language :: Python :: 2.7", 54 | "Programming Language :: Python :: 3", 55 | "Programming Language :: Python :: 3.3", 56 | "Programming Language :: Python :: 3.4", 57 | "Programming Language :: Python :: 3.5", 58 | "Topic :: Software Development", 59 | "Topic :: Software Development :: Libraries :: Python Modules" 60 | ], 61 | ) 62 | -------------------------------------------------------------------------------- /tests/templates/base.html: -------------------------------------------------------------------------------- 1 | {% load request_id %} 2 | 3 | 4 | 5 | Request Id test 6 | 7 | 8 |
 9 | request.request_id:       {{ request.request_id }}
10 | get_current_request_id(): {{ current_request_val }}
11 | {{ "{% request_id %}" }}:         {% request_id %}
12 | 
13 | 14 | --------------------------------------------------------------------------------