|
1 | 1 | """ |
2 | | -The Django middleware will trace requests, database calls and template |
| 2 | +The Django integration will trace requests, database calls and template |
3 | 3 | renders. |
4 | 4 |
|
5 | 5 | To install the Django tracing middleware, add it to the list of your |
6 | | -application's installed in middleware in settings.py:: |
| 6 | +installed apps and in your middleware classes in ``settings.py``:: |
7 | 7 |
|
| 8 | + INSTALLED_APPS = [ |
| 9 | + # ... |
| 10 | +
|
| 11 | + # the order is not important |
| 12 | + 'ddtrace.contrib.django', |
| 13 | + ] |
8 | 14 |
|
9 | 15 | MIDDLEWARE_CLASSES = ( |
10 | | - ... |
| 16 | + # the tracer must be the first middleware |
11 | 17 | 'ddtrace.contrib.django.TraceMiddleware', |
12 | 18 | ... |
13 | 19 | ) |
14 | 20 |
|
15 | | - DATADOG_SERVICE = 'my-app' |
| 21 | +The configuration of this integration is all namespaced inside a single |
| 22 | +Django setting, named ``DATADOG_APM``. For example, your ``settings.py`` |
| 23 | +may contain:: |
| 24 | +
|
| 25 | + DATADOG_APM = { |
| 26 | + 'DEFAULT_SERVICE': 'my-django-app', |
| 27 | + } |
| 28 | +
|
| 29 | +If you need to access to the tracing settings, you should:: |
| 30 | +
|
| 31 | + from ddtrace.contrib.django.conf import settings as dd_settings |
| 32 | +
|
| 33 | + tracer = dd_settings.DEFAULT_TRACER |
| 34 | + tracer.trace("something") |
| 35 | + # your code ... |
| 36 | +
|
| 37 | +The available settings are: |
16 | 38 |
|
| 39 | +* ``DEFAULT_TRACER`` (default ``ddtrace.tracer``): set the default tracer |
| 40 | + instance that is used to trace Django internals. By default the ``ddtrace`` |
| 41 | + tracer is used. |
| 42 | +* ``DEFAULT_SERVICE`` (default: ``django``): set the service name used by the |
| 43 | + tracer. Usually this configuration must be updated with a meaningful name. |
| 44 | +* ``ENABLED``: (default: ``not django_settings.DEBUG``): set if the tracer |
| 45 | + is enabled or not. When a tracer is disabled, Django internals are not |
| 46 | + automatically instrumented and the requests are not traced even if the |
| 47 | + ``TraceMiddleware`` is properly installed. This settings cannot be changed |
| 48 | + at runtime and a restart is required. By default the tracer is disabled |
| 49 | + when in ``DEBUG`` mode, enabled otherwise. |
17 | 50 | """ |
18 | 51 | from ..util import require_modules |
19 | 52 |
|
|
0 commit comments