Repository: DataDog/dd-trace-py

Issue:
Tornado Tracer configuration doesn't have access to settings object for Trace Filtering



Discussion:

Resolving patch:
diff --git a/ddtrace/contrib/tornado/__init__.py b/ddtrace/contrib/tornado/__init__.py
--- a/ddtrace/contrib/tornado/__init__.py
+++ b/ddtrace/contrib/tornado/__init__.py
@@ -55,6 +55,11 @@ def notify(self):
             'default_service': 'my-tornado-app',
             'tags': {'env': 'production'},
             'distributed_tracing': True,
+            'settings': {
+                'FILTERS':  [
+                    FilterRequestsOnUrl(r'http://test\.example\.com'),
+                ],
+            },
         },
     }
 
@@ -74,6 +79,7 @@ def notify(self):
   We suggest to enable it only for internal services where headers are under your control.
 * ``agent_hostname`` (default: `localhost`): define the hostname of the APM agent.
 * ``agent_port`` (default: `8126`): define the port of the APM agent.
+* ``settings`` (default: ``{}``): Tracer extra settings used to change, for instance, the filtering behavior.
 """
 from ...utils.importlib import require_modules
 
diff --git a/ddtrace/contrib/tornado/application.py b/ddtrace/contrib/tornado/application.py
--- a/ddtrace/contrib/tornado/application.py
+++ b/ddtrace/contrib/tornado/application.py
@@ -32,6 +32,9 @@ def tracer_config(__init__, app, args, kwargs):
     tracer = settings['tracer']
     service = settings['default_service']
 
+    # extract extra settings
+    extra_settings = settings.get('settings', {})
+
     # the tracer must use the right Context propagation and wrap executor;
     # this action is done twice because the patch() method uses the
     # global tracer while here we can have a different instance (even if
@@ -42,6 +45,7 @@ def tracer_config(__init__, app, args, kwargs):
         enabled=settings.get('enabled', None),
         hostname=settings.get('agent_hostname', None),
         port=settings.get('agent_port', None),
+        settings=extra_settings,
     )
 
     # set global tags if any


Test patch:
diff --git a/tests/contrib/tornado/test_config.py b/tests/contrib/tornado/test_config.py
--- a/tests/contrib/tornado/test_config.py
+++ b/tests/contrib/tornado/test_config.py
@@ -1,4 +1,6 @@
-from nose.tools import eq_
+from nose.tools import eq_, ok_
+
+from ddtrace.filters import FilterRequestsOnUrl
 
 from .utils import TornadoTestCase
 
@@ -17,6 +19,11 @@ def get_settings(self):
                 'enabled': False,
                 'agent_hostname': 'dd-agent.service.consul',
                 'agent_port': 8126,
+                'settings': {
+                    'FILTERS':  [
+                        FilterRequestsOnUrl(r'http://test\.example\.com'),
+                    ],
+                },
             },
         }
 
@@ -27,3 +34,7 @@ def test_tracer_is_properly_configured(self):
         eq_(self.tracer.enabled, False)
         eq_(self.tracer.writer.api.hostname, 'dd-agent.service.consul')
         eq_(self.tracer.writer.api.port, 8126)
+        # settings are properly passed
+        ok_(self.tracer.writer._filters is not None)
+        eq_(len(self.tracer.writer._filters), 1)
+        ok_(isinstance(self.tracer.writer._filters[0], FilterRequestsOnUrl))