Skip to content

Commit 1254950

Browse files
mcanavesbmermet
authored andcommitted
[django] add settings to disable django db and cache
1 parent 6f5025c commit 1254950

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

ddtrace/contrib/django/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
be useful if you want to use the Django integration, but you want to trace only
5959
particular functions or views. If set to False, the request middleware will be
6060
disabled even if present.
61+
* ``DATABASE_AUTO_INSTRUMENT`` (default: ``True``): if set to false database will not
62+
be instrumented. Only is configurable when ``AUTO_INSTRUMENT`` is set to true.
63+
* ``CACHE_AUTO_INSTRUMENT`` (default: ``True``): if set to false cache will not
64+
be instrumented. Only is configurable when ``AUTO_INSTRUMENT`` is set to true.
6165
* ``AGENT_HOSTNAME`` (default: ``localhost``): define the hostname of the trace agent.
6266
* ``AGENT_PORT`` (default: ``8126``): define the port of the trace agent.
6367
"""

ddtrace/contrib/django/apps.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,20 @@ def ready(self):
4949
if settings.AUTO_INSTRUMENT:
5050
# trace Django internals
5151
insert_exception_middleware()
52-
try:
53-
patch_db(tracer)
54-
except Exception:
55-
log.exception('error patching Django database connections')
5652

5753
try:
5854
patch_template(tracer)
5955
except Exception:
6056
log.exception('error patching Django template rendering')
6157

62-
try:
63-
patch_cache(tracer)
64-
except Exception:
65-
log.exception('error patching Django cache')
58+
if settings.DATABASE_AUTO_INSTRUMENT:
59+
try:
60+
patch_db(tracer)
61+
except Exception:
62+
log.exception('error patching Django database connections')
63+
64+
if settings.CACHE_AUTO_INSTRUMENT:
65+
try:
66+
patch_cache(tracer)
67+
except Exception:
68+
log.exception('error patching Django cache')

ddtrace/contrib/django/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
'AGENT_HOSTNAME': 'localhost',
2626
'AGENT_PORT': 8126,
2727
'AUTO_INSTRUMENT': True,
28+
'DATABASE_AUTO_INSTRUMENT': True,
29+
'CACHE_AUTO_INSTRUMENT': True,
2830
'DEFAULT_DATABASE_PREFIX': '',
2931
'DEFAULT_SERVICE': 'django',
3032
'ENABLED': True,

0 commit comments

Comments
 (0)