We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error log still occurs when tracer is disabled (Django)
The tracer is logging the following error when disabled:

> 2017-07-05 12:54:36,552:[none]:[ddtrace.writer:134]:ERROR cannot send services: [Errno 111] Connection refused

This is occurring when integrated with Django with the following configuration:

```python
DATADOG_TRACE = {
    'ENABLED': False
}
```
From reading the [documentation](http://pypi.datadoghq.com/trace/docs/#module-ddtrace.contrib.django) which states:
> ENABLED (default: not django_settings.DEBUG): defines if the tracer is enabled or not. If set to false, the code is still instrumented but no spans are sent to the trace agent. This setting cannot be changed at runtime and a restart is required. By default the tracer is disabled when in DEBUG mode, enabled otherwise.

It seems this log should not occur. If no spans are sent to the trace agent then presumably a connection should not be established?

Package Info
------------------

> datadog==0.15.0
> ddtrace==0.8.5  


--- 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/apps.py`
Content:
```
1 import logging
2 
3 # 3rd party
4 from django.apps import AppConfig
5 
6 # project
7 from .db import patch_db
8 from .conf import settings
9 from .cache import patch_cache
10 from .templates import patch_template
11 from .middleware import insert_exception_middleware
12 
13 from ...ext import AppTypes
14 
15 
16 log = logging.getLogger(__name__)
17 
18 
19 class TracerConfig(AppConfig):
20     name = 'ddtrace.contrib.django'
21     label = 'datadog_django'
22 
23     def ready(self):
24         """
25         Ready is called as soon as the registry is fully populated.
26         Tracing capabilities must be enabled in this function so that
27         all Django internals are properly configured.
28         """
29         tracer = settings.TRACER
30 
31         if settings.TAGS:
32             tracer.set_tags(settings.TAGS)
33 
34         # define the service details
35         tracer.set_service_info(
36             app='django',
37             app_type=AppTypes.web,
38             service=settings.DEFAULT_SERVICE,
39         )
40 
41         # configure the tracer instance
42         # TODO[manu]: we may use configure() but because it creates a new
43         # AgentWriter, it breaks all tests. The configure() behavior must
44         # be changed to use it in this integration
45         tracer.enabled = settings.ENABLED
46         tracer.writer.api.hostname = settings.AGENT_HOSTNAME
47         tracer.writer.api.port = settings.AGENT_PORT
48 
49         if settings.AUTO_INSTRUMENT:
50             # trace Django internals
51             insert_exception_middleware()
52             try:
53                 patch_db(tracer)
54             except Exception:
55                 log.exception('error patching Django database connections')
56 
57             try:
58                 patch_template(tracer)
59             except Exception:
60                 log.exception('error patching Django template rendering')
61 
62             try:
63                 patch_cache(tracer)
64             except Exception:
65                 log.exception('error patching Django cache')
66
```
--- 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/apps.py b/ddtrace/contrib/django/apps.py
--- a/ddtrace/contrib/django/apps.py
+++ b/ddtrace/contrib/django/apps.py
@@ -31,13 +31,6 @@
         if settings.TAGS:
             tracer.set_tags(settings.TAGS)
 
-        # define the service details
-        tracer.set_service_info(
-            app='django',
-            app_type=AppTypes.web,
-            service=settings.DEFAULT_SERVICE,
-        )
-
         # configure the tracer instance
         # TODO[manu]: we may use configure() but because it creates a new
         # AgentWriter, it breaks all tests. The configure() behavior must
@@ -46,6 +39,13 @@
         tracer.writer.api.hostname = settings.AGENT_HOSTNAME
         tracer.writer.api.port = settings.AGENT_PORT
 
+        # define the service details
+        tracer.set_service_info(
+            app='django',
+            app_type=AppTypes.web,
+            service=settings.DEFAULT_SERVICE,
+        )
+
         if settings.AUTO_INSTRUMENT:
             # trace Django internals
             insert_exception_middleware()

{"golden_diff": "diff --git a/ddtrace/contrib/django/apps.py b/ddtrace/contrib/django/apps.py\n--- a/ddtrace/contrib/django/apps.py\n+++ b/ddtrace/contrib/django/apps.py\n@@ -31,13 +31,6 @@\n         if settings.TAGS:\n             tracer.set_tags(settings.TAGS)\n \n-        # define the service details\n-        tracer.set_service_info(\n-            app='django',\n-            app_type=AppTypes.web,\n-            service=settings.DEFAULT_SERVICE,\n-        )\n-\n         # configure the tracer instance\n         # TODO[manu]: we may use configure() but because it creates a new\n         # AgentWriter, it breaks all tests. The configure() behavior must\n@@ -46,6 +39,13 @@\n         tracer.writer.api.hostname = settings.AGENT_HOSTNAME\n         tracer.writer.api.port = settings.AGENT_PORT\n \n+        # define the service details\n+        tracer.set_service_info(\n+            app='django',\n+            app_type=AppTypes.web,\n+            service=settings.DEFAULT_SERVICE,\n+        )\n+\n         if settings.AUTO_INSTRUMENT:\n             # trace Django internals\n             insert_exception_middleware()\n", "issue": "Error log still occurs when tracer is disabled (Django)\nThe tracer is logging the following error when disabled:\r\n\r\n> 2017-07-05 12:54:36,552:[none]:[ddtrace.writer:134]:ERROR cannot send services: [Errno 111] Connection refused\r\n\r\nThis is occurring when integrated with Django with the following configuration:\r\n\r\n```python\r\nDATADOG_TRACE = {\r\n    'ENABLED': False\r\n}\r\n```\r\nFrom reading the [documentation](http://pypi.datadoghq.com/trace/docs/#module-ddtrace.contrib.django) which states:\r\n> ENABLED (default: not django_settings.DEBUG): defines if the tracer is enabled or not. If set to false, the code is still instrumented but no spans are sent to the trace agent. This setting cannot be changed at runtime and a restart is required. By default the tracer is disabled when in DEBUG mode, enabled otherwise.\r\n\r\nIt seems this log should not occur. If no spans are sent to the trace agent then presumably a connection should not be established?\r\n\r\nPackage Info\r\n------------------\r\n\r\n> datadog==0.15.0\r\n> ddtrace==0.8.5  \r\n\n", "before_files": [{"content": "import logging\n\n# 3rd party\nfrom django.apps import AppConfig\n\n# project\nfrom .db import patch_db\nfrom .conf import settings\nfrom .cache import patch_cache\nfrom .templates import patch_template\nfrom .middleware import insert_exception_middleware\n\nfrom ...ext import AppTypes\n\n\nlog = logging.getLogger(__name__)\n\n\nclass TracerConfig(AppConfig):\n    name = 'ddtrace.contrib.django'\n    label = 'datadog_django'\n\n    def ready(self):\n        \"\"\"\n        Ready is called as soon as the registry is fully populated.\n        Tracing capabilities must be enabled in this function so that\n        all Django internals are properly configured.\n        \"\"\"\n        tracer = settings.TRACER\n\n        if settings.TAGS:\n            tracer.set_tags(settings.TAGS)\n\n        # define the service details\n        tracer.set_service_info(\n            app='django',\n            app_type=AppTypes.web,\n            service=settings.DEFAULT_SERVICE,\n        )\n\n        # configure the tracer instance\n        # TODO[manu]: we may use configure() but because it creates a new\n        # AgentWriter, it breaks all tests. The configure() behavior must\n        # be changed to use it in this integration\n        tracer.enabled = settings.ENABLED\n        tracer.writer.api.hostname = settings.AGENT_HOSTNAME\n        tracer.writer.api.port = settings.AGENT_PORT\n\n        if settings.AUTO_INSTRUMENT:\n            # trace Django internals\n            insert_exception_middleware()\n            try:\n                patch_db(tracer)\n            except Exception:\n                log.exception('error patching Django database connections')\n\n            try:\n                patch_template(tracer)\n            except Exception:\n                log.exception('error patching Django template rendering')\n\n            try:\n                patch_cache(tracer)\n            except Exception:\n                log.exception('error patching Django cache')\n", "path": "ddtrace/contrib/django/apps.py"}], "after_files": [{"content": "import logging\n\n# 3rd party\nfrom django.apps import AppConfig\n\n# project\nfrom .db import patch_db\nfrom .conf import settings\nfrom .cache import patch_cache\nfrom .templates import patch_template\nfrom .middleware import insert_exception_middleware\n\nfrom ...ext import AppTypes\n\n\nlog = logging.getLogger(__name__)\n\n\nclass TracerConfig(AppConfig):\n    name = 'ddtrace.contrib.django'\n    label = 'datadog_django'\n\n    def ready(self):\n        \"\"\"\n        Ready is called as soon as the registry is fully populated.\n        Tracing capabilities must be enabled in this function so that\n        all Django internals are properly configured.\n        \"\"\"\n        tracer = settings.TRACER\n\n        if settings.TAGS:\n            tracer.set_tags(settings.TAGS)\n\n        # configure the tracer instance\n        # TODO[manu]: we may use configure() but because it creates a new\n        # AgentWriter, it breaks all tests. The configure() behavior must\n        # be changed to use it in this integration\n        tracer.enabled = settings.ENABLED\n        tracer.writer.api.hostname = settings.AGENT_HOSTNAME\n        tracer.writer.api.port = settings.AGENT_PORT\n\n        # define the service details\n        tracer.set_service_info(\n            app='django',\n            app_type=AppTypes.web,\n            service=settings.DEFAULT_SERVICE,\n        )\n\n        if settings.AUTO_INSTRUMENT:\n            # trace Django internals\n            insert_exception_middleware()\n            try:\n                patch_db(tracer)\n            except Exception:\n                log.exception('error patching Django database connections')\n\n            try:\n                patch_template(tracer)\n            except Exception:\n                log.exception('error patching Django template rendering')\n\n            try:\n                patch_cache(tracer)\n            except Exception:\n                log.exception('error patching Django cache')\n", "path": "ddtrace/contrib/django/apps.py"}]}