File tree Expand file tree Collapse file tree 4 files changed +25
-16
lines changed Expand file tree Collapse file tree 4 files changed +25
-16
lines changed Original file line number Diff line number Diff line change @@ -23,19 +23,20 @@ def ready(self):
2323 Tracing capabilities must be enabled in this function so that
2424 all Django internals are properly configured.
2525 """
26- tracer = settings .DEFAULT_TRACER
27-
28- # define the service details
29- tracer .set_service_info (
30- service = settings .DEFAULT_SERVICE ,
31- app = 'django' ,
32- app_type = AppTypes .web ,
33- )
34-
35- try :
36- # trace Django internals
37- patch_template (tracer )
38- patch_db (tracer )
39- except Exception :
40- # TODO[manu]: we can provide better details there
41- log .exception ('error patching Django internals' )
26+ if settings .ENABLED :
27+ tracer = settings .DEFAULT_TRACER
28+
29+ # define the service details
30+ tracer .set_service_info (
31+ service = settings .DEFAULT_SERVICE ,
32+ app = 'django' ,
33+ app_type = AppTypes .web ,
34+ )
35+
36+ try :
37+ # trace Django internals
38+ patch_template (tracer )
39+ patch_db (tracer )
40+ except Exception :
41+ # TODO[manu]: we can provide better details there
42+ log .exception ('error patching Django internals' )
Original file line number Diff line number Diff line change 2525DEFAULTS = {
2626 'DEFAULT_TRACER' : 'ddtrace.tracer' ,
2727 'DEFAULT_SERVICE' : 'django' ,
28+ 'ENABLED' : not django_settings .DEBUG ,
2829}
2930
3031# List of settings that may be in string import notation.
Original file line number Diff line number Diff line change 88
99# 3p
1010from django .apps import apps
11+ from django .core .exceptions import MiddlewareNotUsed
1112
1213
1314log = logging .getLogger (__name__ )
@@ -17,6 +18,11 @@ class TraceMiddleware(object):
1718 """
1819 Middleware that traces Django requests
1920 """
21+ def __init__ (self ):
22+ # disable the middleware if the tracer is not enabled
23+ if not settings .ENABLED :
24+ raise MiddlewareNotUsed
25+
2026 def process_request (self , request ):
2127 tracer = settings .DEFAULT_TRACER
2228
Original file line number Diff line number Diff line change 6767DATADOG_APM = {
6868 # tracer with a DummyWriter
6969 'DEFAULT_TRACER' : 'tests.contrib.django.utils.tracer' ,
70+ 'ENABLED' : True ,
7071}
You can’t perform that action at this time.
0 commit comments