We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
DatabaseError with ddtrace
```
Traceback (most recent call last):
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/signup/views/signup.py", line 199, in edu_school_reg
    token = EDUVerifyToken.objects.create_token(email=email, domain=domain, name=data['name'], plan_family=data['plan_family'], action=action, upgrade_email=upgrade_email, user_id=user_id, school_data=school_data)
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/signup/models.py", line 69, in create_token
    token.save()
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/signup/models.py", line 99, in save
    super(EDUVerifyToken, self).save(**kwargs)
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 734, in save
    force_update=force_update, update_fields=update_fields)
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 759, in save_base
    with transaction.atomic(using=using, savepoint=False):
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/transaction.py", line 150, in __enter__
    if not connection.get_autocommit():
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 286, in get_autocommit
    self.ensure_connection()
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 121, in connect
    self.init_connection_state()
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 282, in init_connection_state
    with self.cursor() as cursor:
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/ddtrace/contrib/django/db.py", line 35, in cursor
    return TracedCursor(tracer, conn, conn._datadog_original_cursor())
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 160, in cursor
    self.validate_thread_sharing()
  File "/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 421, in validate_thread_sharing
    % (self.alias, self._thread_ident, thread.get_ident()))
DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 40345840 and this is thread id 76693744.
```

ddtrace created a `DatabaseWrapper` in a different thread. And an exception is raised when the save called on the model.

Current dependencies
```
gunicorn==19.3
MySQL-python==1.2.5
ddtrace==0.11.0
datadog==0.19.0
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ddtrace/contrib/django/conf.py`
Content:
```
1 """
2 Settings for Datadog tracer are all namespaced in the DATADOG_TRACE setting.
3 For example your project's `settings.py` file might look like this:
4 
5 DATADOG_TRACE = {
6     'TRACER': 'myapp.tracer',
7 }
8 
9 This module provides the `setting` object, that is used to access
10 Datadog settings, checking for user settings first, then falling
11 back to the defaults.
12 """
13 from __future__ import unicode_literals
14 
15 import os
16 import importlib
17 import logging
18 
19 from django.conf import settings as django_settings
20 
21 from django.test.signals import setting_changed
22 
23 
24 log = logging.getLogger(__name__)
25 
26 # List of available settings with their defaults
27 DEFAULTS = {
28     'AGENT_HOSTNAME': 'localhost',
29     'AGENT_PORT': 8126,
30     'AUTO_INSTRUMENT': True,
31     'INSTRUMENT_CACHE': True,
32     'INSTRUMENT_DATABASE': True,
33     'INSTRUMENT_TEMPLATE': True,
34     'DEFAULT_DATABASE_PREFIX': '',
35     'DEFAULT_SERVICE': 'django',
36     'ENABLED': True,
37     'DISTRIBUTED_TRACING': False,
38     'TAGS': {},
39     'TRACER': 'ddtrace.tracer',
40 }
41 
42 # List of settings that may be in string import notation.
43 IMPORT_STRINGS = (
44     'TRACER',
45 )
46 
47 # List of settings that have been removed
48 REMOVED_SETTINGS = ()
49 
50 
51 def import_from_string(val, setting_name):
52     """
53     Attempt to import a class from a string representation.
54     """
55     try:
56         # Nod to tastypie's use of importlib.
57         parts = val.split('.')
58         module_path, class_name = '.'.join(parts[:-1]), parts[-1]
59         module = importlib.import_module(module_path)
60         return getattr(module, class_name)
61     except (ImportError, AttributeError) as e:
62         msg = 'Could not import "{}" for setting "{}". {}: {}.'.format(
63                 val, setting_name,
64                 e.__class__.__name__, e
65         )
66 
67         raise ImportError(msg)
68 
69 
70 class DatadogSettings(object):
71     """
72     A settings object, that allows Datadog settings to be accessed as properties.
73     For example:
74 
75         from ddtrace.contrib.django.conf import settings
76 
77         tracer = settings.TRACER
78 
79     Any setting with string import paths will be automatically resolved
80     and return the class, rather than the string literal.
81     """
82     def __init__(self, user_settings=None, defaults=None, import_strings=None):
83         if user_settings:
84             self._user_settings = self.__check_user_settings(user_settings)
85 
86         self.defaults = defaults or DEFAULTS
87         if os.environ.get('DATADOG_ENV'):
88             self.defaults['TAGS'].update({'env': os.environ.get('DATADOG_ENV')})
89         if os.environ.get('DATADOG_SERVICE_NAME'):
90             self.defaults['DEFAULT_SERVICE'] = os.environ.get('DATADOG_SERVICE_NAME')
91         if os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME'):
92             self.defaults['AGENT_HOSTNAME'] = os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME')
93         if os.environ.get('DATADOG_TRACE_AGENT_PORT'):
94             # if the agent port is a string, the underlying library that creates the socket
95             # stops working
96             try:
97                 port = int(os.environ.get('DATADOG_TRACE_AGENT_PORT'))
98             except ValueError:
99                 log.warning('DATADOG_TRACE_AGENT_PORT is not an integer value; default to 8126')
100             else:
101                 self.defaults['AGENT_PORT'] = port
102 
103         self.import_strings = import_strings or IMPORT_STRINGS
104 
105     @property
106     def user_settings(self):
107         if not hasattr(self, '_user_settings'):
108             self._user_settings = getattr(django_settings, 'DATADOG_TRACE', {})
109 
110         # TODO[manu]: prevents docs import errors; provide a better implementation
111         if 'ENABLED' not in self._user_settings:
112             self._user_settings['ENABLED'] = not django_settings.DEBUG
113         return self._user_settings
114 
115     def __getattr__(self, attr):
116         if attr not in self.defaults:
117             raise AttributeError('Invalid setting: "{}"'.format(attr))
118 
119         try:
120             # Check if present in user settings
121             val = self.user_settings[attr]
122         except KeyError:
123             # Otherwise, fall back to defaults
124             val = self.defaults[attr]
125 
126         # Coerce import strings into classes
127         if attr in self.import_strings:
128             val = import_from_string(val, attr)
129 
130         # Cache the result
131         setattr(self, attr, val)
132         return val
133 
134     def __check_user_settings(self, user_settings):
135         SETTINGS_DOC = 'http://pypi.datadoghq.com/trace/docs/#module-ddtrace.contrib.django'
136         for setting in REMOVED_SETTINGS:
137             if setting in user_settings:
138                 raise RuntimeError(
139                     'The "{}" setting has been removed, check "{}".'.format(setting, SETTINGS_DOC)
140                 )
141         return user_settings
142 
143 
144 settings = DatadogSettings(None, DEFAULTS, IMPORT_STRINGS)
145 
146 
147 def reload_settings(*args, **kwargs):
148     """
149     Triggers a reload when Django emits the reloading signal
150     """
151     global settings
152     setting, value = kwargs['setting'], kwargs['value']
153     if setting == 'DATADOG_TRACE':
154         settings = DatadogSettings(value, DEFAULTS, IMPORT_STRINGS)
155 
156 
157 setting_changed.connect(reload_settings)
158
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ddtrace/contrib/django/conf.py b/ddtrace/contrib/django/conf.py
--- a/ddtrace/contrib/django/conf.py
+++ b/ddtrace/contrib/django/conf.py
@@ -18,8 +18,6 @@
 
 from django.conf import settings as django_settings
 
-from django.test.signals import setting_changed
-
 
 log = logging.getLogger(__name__)
 
@@ -152,6 +150,3 @@
     setting, value = kwargs['setting'], kwargs['value']
     if setting == 'DATADOG_TRACE':
         settings = DatadogSettings(value, DEFAULTS, IMPORT_STRINGS)
-
-
-setting_changed.connect(reload_settings)

{"golden_diff": "diff --git a/ddtrace/contrib/django/conf.py b/ddtrace/contrib/django/conf.py\n--- a/ddtrace/contrib/django/conf.py\n+++ b/ddtrace/contrib/django/conf.py\n@@ -18,8 +18,6 @@\n \n from django.conf import settings as django_settings\n \n-from django.test.signals import setting_changed\n-\n \n log = logging.getLogger(__name__)\n \n@@ -152,6 +150,3 @@\n     setting, value = kwargs['setting'], kwargs['value']\n     if setting == 'DATADOG_TRACE':\n         settings = DatadogSettings(value, DEFAULTS, IMPORT_STRINGS)\n-\n-\n-setting_changed.connect(reload_settings)\n", "issue": "DatabaseError with ddtrace\n```\r\nTraceback (most recent call last):\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/core/handlers/base.py\", line 132, in get_response\r\n    response = wrapped_callback(request, *callback_args, **callback_kwargs)\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/signup/views/signup.py\", line 199, in edu_school_reg\r\n    token = EDUVerifyToken.objects.create_token(email=email, domain=domain, name=data['name'], plan_family=data['plan_family'], action=action, upgrade_email=upgrade_email, user_id=user_id, school_data=school_data)\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/signup/models.py\", line 69, in create_token\r\n    token.save()\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/signup/models.py\", line 99, in save\r\n    super(EDUVerifyToken, self).save(**kwargs)\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/models/base.py\", line 734, in save\r\n    force_update=force_update, update_fields=update_fields)\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/models/base.py\", line 759, in save_base\r\n    with transaction.atomic(using=using, savepoint=False):\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/transaction.py\", line 150, in __enter__\r\n    if not connection.get_autocommit():\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py\", line 286, in get_autocommit\r\n    self.ensure_connection()\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py\", line 130, in ensure_connection\r\n    self.connect()\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py\", line 121, in connect\r\n    self.init_connection_state()\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py\", line 282, in init_connection_state\r\n    with self.cursor() as cursor:\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/ddtrace/contrib/django/db.py\", line 35, in cursor\r\n    return TracedCursor(tracer, conn, conn._datadog_original_cursor())\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py\", line 160, in cursor\r\n    self.validate_thread_sharing()\r\n  File \"/opt/prezi/signup/versions/318-db1a27e562e267603c55ea13e8db46b29d715834/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py\", line 421, in validate_thread_sharing\r\n    % (self.alias, self._thread_ident, thread.get_ident()))\r\nDatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 40345840 and this is thread id 76693744.\r\n```\r\n\r\nddtrace created a `DatabaseWrapper` in a different thread. And an exception is raised when the save called on the model.\r\n\r\nCurrent dependencies\r\n```\r\ngunicorn==19.3\r\nMySQL-python==1.2.5\r\nddtrace==0.11.0\r\ndatadog==0.19.0\r\n```\n", "before_files": [{"content": "\"\"\"\nSettings for Datadog tracer are all namespaced in the DATADOG_TRACE setting.\nFor example your project's `settings.py` file might look like this:\n\nDATADOG_TRACE = {\n    'TRACER': 'myapp.tracer',\n}\n\nThis module provides the `setting` object, that is used to access\nDatadog settings, checking for user settings first, then falling\nback to the defaults.\n\"\"\"\nfrom __future__ import unicode_literals\n\nimport os\nimport importlib\nimport logging\n\nfrom django.conf import settings as django_settings\n\nfrom django.test.signals import setting_changed\n\n\nlog = logging.getLogger(__name__)\n\n# List of available settings with their defaults\nDEFAULTS = {\n    'AGENT_HOSTNAME': 'localhost',\n    'AGENT_PORT': 8126,\n    'AUTO_INSTRUMENT': True,\n    'INSTRUMENT_CACHE': True,\n    'INSTRUMENT_DATABASE': True,\n    'INSTRUMENT_TEMPLATE': True,\n    'DEFAULT_DATABASE_PREFIX': '',\n    'DEFAULT_SERVICE': 'django',\n    'ENABLED': True,\n    'DISTRIBUTED_TRACING': False,\n    'TAGS': {},\n    'TRACER': 'ddtrace.tracer',\n}\n\n# List of settings that may be in string import notation.\nIMPORT_STRINGS = (\n    'TRACER',\n)\n\n# List of settings that have been removed\nREMOVED_SETTINGS = ()\n\n\ndef import_from_string(val, setting_name):\n    \"\"\"\n    Attempt to import a class from a string representation.\n    \"\"\"\n    try:\n        # Nod to tastypie's use of importlib.\n        parts = val.split('.')\n        module_path, class_name = '.'.join(parts[:-1]), parts[-1]\n        module = importlib.import_module(module_path)\n        return getattr(module, class_name)\n    except (ImportError, AttributeError) as e:\n        msg = 'Could not import \"{}\" for setting \"{}\". {}: {}.'.format(\n                val, setting_name,\n                e.__class__.__name__, e\n        )\n\n        raise ImportError(msg)\n\n\nclass DatadogSettings(object):\n    \"\"\"\n    A settings object, that allows Datadog settings to be accessed as properties.\n    For example:\n\n        from ddtrace.contrib.django.conf import settings\n\n        tracer = settings.TRACER\n\n    Any setting with string import paths will be automatically resolved\n    and return the class, rather than the string literal.\n    \"\"\"\n    def __init__(self, user_settings=None, defaults=None, import_strings=None):\n        if user_settings:\n            self._user_settings = self.__check_user_settings(user_settings)\n\n        self.defaults = defaults or DEFAULTS\n        if os.environ.get('DATADOG_ENV'):\n            self.defaults['TAGS'].update({'env': os.environ.get('DATADOG_ENV')})\n        if os.environ.get('DATADOG_SERVICE_NAME'):\n            self.defaults['DEFAULT_SERVICE'] = os.environ.get('DATADOG_SERVICE_NAME')\n        if os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME'):\n            self.defaults['AGENT_HOSTNAME'] = os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME')\n        if os.environ.get('DATADOG_TRACE_AGENT_PORT'):\n            # if the agent port is a string, the underlying library that creates the socket\n            # stops working\n            try:\n                port = int(os.environ.get('DATADOG_TRACE_AGENT_PORT'))\n            except ValueError:\n                log.warning('DATADOG_TRACE_AGENT_PORT is not an integer value; default to 8126')\n            else:\n                self.defaults['AGENT_PORT'] = port\n\n        self.import_strings = import_strings or IMPORT_STRINGS\n\n    @property\n    def user_settings(self):\n        if not hasattr(self, '_user_settings'):\n            self._user_settings = getattr(django_settings, 'DATADOG_TRACE', {})\n\n        # TODO[manu]: prevents docs import errors; provide a better implementation\n        if 'ENABLED' not in self._user_settings:\n            self._user_settings['ENABLED'] = not django_settings.DEBUG\n        return self._user_settings\n\n    def __getattr__(self, attr):\n        if attr not in self.defaults:\n            raise AttributeError('Invalid setting: \"{}\"'.format(attr))\n\n        try:\n            # Check if present in user settings\n            val = self.user_settings[attr]\n        except KeyError:\n            # Otherwise, fall back to defaults\n            val = self.defaults[attr]\n\n        # Coerce import strings into classes\n        if attr in self.import_strings:\n            val = import_from_string(val, attr)\n\n        # Cache the result\n        setattr(self, attr, val)\n        return val\n\n    def __check_user_settings(self, user_settings):\n        SETTINGS_DOC = 'http://pypi.datadoghq.com/trace/docs/#module-ddtrace.contrib.django'\n        for setting in REMOVED_SETTINGS:\n            if setting in user_settings:\n                raise RuntimeError(\n                    'The \"{}\" setting has been removed, check \"{}\".'.format(setting, SETTINGS_DOC)\n                )\n        return user_settings\n\n\nsettings = DatadogSettings(None, DEFAULTS, IMPORT_STRINGS)\n\n\ndef reload_settings(*args, **kwargs):\n    \"\"\"\n    Triggers a reload when Django emits the reloading signal\n    \"\"\"\n    global settings\n    setting, value = kwargs['setting'], kwargs['value']\n    if setting == 'DATADOG_TRACE':\n        settings = DatadogSettings(value, DEFAULTS, IMPORT_STRINGS)\n\n\nsetting_changed.connect(reload_settings)\n", "path": "ddtrace/contrib/django/conf.py"}], "after_files": [{"content": "\"\"\"\nSettings for Datadog tracer are all namespaced in the DATADOG_TRACE setting.\nFor example your project's `settings.py` file might look like this:\n\nDATADOG_TRACE = {\n    'TRACER': 'myapp.tracer',\n}\n\nThis module provides the `setting` object, that is used to access\nDatadog settings, checking for user settings first, then falling\nback to the defaults.\n\"\"\"\nfrom __future__ import unicode_literals\n\nimport os\nimport importlib\nimport logging\n\nfrom django.conf import settings as django_settings\n\n\nlog = logging.getLogger(__name__)\n\n# List of available settings with their defaults\nDEFAULTS = {\n    'AGENT_HOSTNAME': 'localhost',\n    'AGENT_PORT': 8126,\n    'AUTO_INSTRUMENT': True,\n    'INSTRUMENT_CACHE': True,\n    'INSTRUMENT_DATABASE': True,\n    'INSTRUMENT_TEMPLATE': True,\n    'DEFAULT_DATABASE_PREFIX': '',\n    'DEFAULT_SERVICE': 'django',\n    'ENABLED': True,\n    'DISTRIBUTED_TRACING': False,\n    'TAGS': {},\n    'TRACER': 'ddtrace.tracer',\n}\n\n# List of settings that may be in string import notation.\nIMPORT_STRINGS = (\n    'TRACER',\n)\n\n# List of settings that have been removed\nREMOVED_SETTINGS = ()\n\n\ndef import_from_string(val, setting_name):\n    \"\"\"\n    Attempt to import a class from a string representation.\n    \"\"\"\n    try:\n        # Nod to tastypie's use of importlib.\n        parts = val.split('.')\n        module_path, class_name = '.'.join(parts[:-1]), parts[-1]\n        module = importlib.import_module(module_path)\n        return getattr(module, class_name)\n    except (ImportError, AttributeError) as e:\n        msg = 'Could not import \"{}\" for setting \"{}\". {}: {}.'.format(\n                val, setting_name,\n                e.__class__.__name__, e\n        )\n\n        raise ImportError(msg)\n\n\nclass DatadogSettings(object):\n    \"\"\"\n    A settings object, that allows Datadog settings to be accessed as properties.\n    For example:\n\n        from ddtrace.contrib.django.conf import settings\n\n        tracer = settings.TRACER\n\n    Any setting with string import paths will be automatically resolved\n    and return the class, rather than the string literal.\n    \"\"\"\n    def __init__(self, user_settings=None, defaults=None, import_strings=None):\n        if user_settings:\n            self._user_settings = self.__check_user_settings(user_settings)\n\n        self.defaults = defaults or DEFAULTS\n        if os.environ.get('DATADOG_ENV'):\n            self.defaults['TAGS'].update({'env': os.environ.get('DATADOG_ENV')})\n        if os.environ.get('DATADOG_SERVICE_NAME'):\n            self.defaults['DEFAULT_SERVICE'] = os.environ.get('DATADOG_SERVICE_NAME')\n        if os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME'):\n            self.defaults['AGENT_HOSTNAME'] = os.environ.get('DATADOG_TRACE_AGENT_HOSTNAME')\n        if os.environ.get('DATADOG_TRACE_AGENT_PORT'):\n            # if the agent port is a string, the underlying library that creates the socket\n            # stops working\n            try:\n                port = int(os.environ.get('DATADOG_TRACE_AGENT_PORT'))\n            except ValueError:\n                log.warning('DATADOG_TRACE_AGENT_PORT is not an integer value; default to 8126')\n            else:\n                self.defaults['AGENT_PORT'] = port\n\n        self.import_strings = import_strings or IMPORT_STRINGS\n\n    @property\n    def user_settings(self):\n        if not hasattr(self, '_user_settings'):\n            self._user_settings = getattr(django_settings, 'DATADOG_TRACE', {})\n\n        # TODO[manu]: prevents docs import errors; provide a better implementation\n        if 'ENABLED' not in self._user_settings:\n            self._user_settings['ENABLED'] = not django_settings.DEBUG\n        return self._user_settings\n\n    def __getattr__(self, attr):\n        if attr not in self.defaults:\n            raise AttributeError('Invalid setting: \"{}\"'.format(attr))\n\n        try:\n            # Check if present in user settings\n            val = self.user_settings[attr]\n        except KeyError:\n            # Otherwise, fall back to defaults\n            val = self.defaults[attr]\n\n        # Coerce import strings into classes\n        if attr in self.import_strings:\n            val = import_from_string(val, attr)\n\n        # Cache the result\n        setattr(self, attr, val)\n        return val\n\n    def __check_user_settings(self, user_settings):\n        SETTINGS_DOC = 'http://pypi.datadoghq.com/trace/docs/#module-ddtrace.contrib.django'\n        for setting in REMOVED_SETTINGS:\n            if setting in user_settings:\n                raise RuntimeError(\n                    'The \"{}\" setting has been removed, check \"{}\".'.format(setting, SETTINGS_DOC)\n                )\n        return user_settings\n\n\nsettings = DatadogSettings(None, DEFAULTS, IMPORT_STRINGS)\n\n\ndef reload_settings(*args, **kwargs):\n    \"\"\"\n    Triggers a reload when Django emits the reloading signal\n    \"\"\"\n    global settings\n    setting, value = kwargs['setting'], kwargs['value']\n    if setting == 'DATADOG_TRACE':\n        settings = DatadogSettings(value, DEFAULTS, IMPORT_STRINGS)\n", "path": "ddtrace/contrib/django/conf.py"}]}